gatsbyjs / gatsby

The best React-based framework with performance, scalability and security built in.
https://www.gatsbyjs.com
MIT License
55.28k stars 10.31k forks source link

GraphQL Error Unknown field ... on type ... #8053

Closed JanLenoch closed 6 years ago

JanLenoch commented 6 years ago

Description

Occasionally, during the process of building a project with gatsby develop an error occurs:

"GraphQL Error Unknown field some field on type some type"

It definitely happens every time the project is first run (after initializing it with npm install). But, it also happens in other moments, in a random fashion.

Steps to reproduce

  1. Clone https://github.com/Kentico/cloud-gatsby.
  2. Run the project.
  3. Watch the progress in the terminal.

Expected result

The update schema step should be processed without errors.

Actual result

success delete html and css files from previous builds — 0.007 s
success open and validate gatsby-config — 0.008 s
success copy gatsby files — 0.049 s
success onPreBootstrap — 0.525 s
⠁ sourceNodes executes
success source and transform nodes — 0.335 s
success building schema — 0.268 s
success createLayouts — 0.055 s
success createPages — 0.058 s
success createPagesStatefully — 0.035 s
success onPreExtractQueries — 0.001 s
success update schema — 0.172 s
GraphQL Error Unknown field `url` on type `KenticoCloudItemBlogpostReference`

  file: C:/Users/janl/source/repos/cloud-gatsby/src/pages/index.js

   1 |
   2 |   query AllDefaultLanguageItemsQuery {
   3 |     allKenticoCloudItemBlogpostReference(filter: { fields: { languageStep1: { eq: "default" }}}) {
   4 |       edges {
   5 |         node {
   6 |           fields {
   7 |             languageStep1
   8 |           }
   9 |           id
> 10 |           url {
     |           ^
  11 |             value
  12 |           }
  13 |           name___teaser_image__name {
  14 |             value
  15 |           }
  16 |         }
  17 |       }
  18 |     }
  19 |     allKenticoCloudItemProjectReference(filter: { fields: { languageStep1: { eq: "default" }}}) {
  20 |       edges {
success extract queries from components — 0.107 s
success run graphql queries — 0.028 s
success write out page data — 0.016 s
success write out redirect data — 0.002 s
success onPostBootstrap — 0.001 s

Environment

System: OS: Windows 10 CPU: x64 Intel(R) Core(TM) i7-7700 CPU @ 3.60GHz Binaries: npm: 5.6.0 - C:\Program Files\nodejs\npm.CMD Browsers: Edge: 40.15063.674.0 npmPackages: gatsby: ^1.9.277 => 1.9.277 gatsby-link: ^1.6.46 => 1.6.46 gatsby-plugin-react-helmet: ^2.0.11 => 2.0.11

error The system cannot find the path specified.

Error: The system cannot find the path specified.

error UNHANDLED REJECTION

Error: The system cannot find the path specified.

kakadiadarpan commented 6 years ago

I'm able to reproduce this and getting it on the first run and every time .cache the directory is cleared.

kamerondotcom commented 6 years ago

I am also seeing this error. Similar environment but am seeing the behavior regardless of the .cache directory being cleared.

Simply007 commented 6 years ago

I am also seeing this error. Similar environment but am seeing the behavior regardless of the .cache directory being cleared.

same here

youmustfight commented 6 years ago

Found a behavior in my case that might hint at the underlying issue (I'm on v2 btw gatsby@next -> gatsby@2.0.0-rc.28)

I'm pulling in multiple AirTable sources (gatsby-source-airtable@2.0.1) and the table that was throwing this error had a single record which had null values. When I filled all the rows values into the other fields, it no longer threw

pieh commented 6 years ago

@JanLenoch this happens because it this moment gatsby doesn't support class instances when constructing schema

url field that is missing is instance of TextField class ( https://github.com/Enngage/kentico-cloud-js/blob/94ce81548f167530c9376e7a852ac733a708e85b/packages/delivery/lib/fields/field-types.ts#L8-L32 ), which gatsby can't handle first time it sees it. But it works on second try because after serializing data to cache and deserializing it again we get plain object with properties which gatsby can handle

I think fastest way forward would be to normalize fields you get from kentico-cloud-delivery client to plain objects in source plugin. I will try to see if it's feasible to add support for those in gatsby.

JanLenoch commented 6 years ago

Hi @pieh, thanks for looking into it! Having support for classes would be great as this is what our JS SDK produces by default.

pieh commented 6 years ago

@JanLenoch I've hacky checked yesterday and it seems that what we need is really only way to determine when Object is something we would want to handle - just switching our check here https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby/src/schema/data-tree-utils.js#L174 should be enough to make it work, but not sure what's the best check we can use - switching it to more open _.isObject (or any stuff that only checks for typeof x === 'object') could be problematic because we have whole class of Objects that shouldn't be treated as plain objects (like Date, Number, Array, Map, Set, WeakMap, WeakSet, Promise, ArrayBuffer etc)

JanLenoch commented 6 years ago

Hi @pieh , I found a semi-hacky way of passing plain objects to Gatsby while still being able to utilize our JS SDK at the same time. We're currently doing a peer review of my PR that brings the plain objects. In the mid-term future, it would still be great if Gatsby supported class instances. That way, we could avoid this semi-hacky solution. I'll close this one for now and I'll file a new issue to support class instances. Thanks for looking into it.