Gatsby: GraphQL Error Unknown field ... on type ...

Created on 11 Sep 2018  ยท  8Comments  ยท  Source: gatsbyjs/gatsby

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.

  • envinfo.js:1 Function.e.exports.sync
    [npm]/[gatsby-cli]/[envinfo]/dist/envinfo.js:1:7778

  • envinfo.js:1 Object.copySync
    [npm]/[gatsby-cli]/[envinfo]/dist/envinfo.js:1:104976

  • envinfo.js:1 Object.t.writeSync.e [as writeSync]
    [npm]/[gatsby-cli]/[envinfo]/dist/envinfo.js:1:123499

  • envinfo.js:1
    [npm]/[gatsby-cli]/[envinfo]/dist/envinfo.js:1:124274

  • envinfo.js:1 Promise.all.then.e
    [npm]/[gatsby-cli]/[envinfo]/dist/envinfo.js:1:124289

  • From previous event:

  • envinfo.js:1 p
    [npm]/[gatsby-cli]/[envinfo]/dist/envinfo.js:1:123986

  • envinfo.js:1 Object.run
    [npm]/[gatsby-cli]/[envinfo]/dist/envinfo.js:1:125487

  • create-cli.js:181 Object.handler
    [npm]/[gatsby-cli]/lib/create-cli.js:181:17

  • command.js:235 Object.runCommand
    [npm]/[gatsby-cli]/[yargs]/lib/command.js:235:44

  • yargs.js:1046 Object.parseArgs [as _parseArgs]
    [npm]/[gatsby-cli]/[yargs]/yargs.js:1046:30

  • yargs.js:551 Object.parse
    [npm]/[gatsby-cli]/[yargs]/yargs.js:551:25

  • create-cli.js:242 module.exports
    [npm]/[gatsby-cli]/lib/create-cli.js:242:157

  • index.js:126 Object.
    [npm]/[gatsby-cli]/lib/index.js:126:1

  • bootstrap_node.js:187 startup
    bootstrap_node.js:187:16

  • bootstrap_node.js:608
    bootstrap_node.js:608:3

error UNHANDLED REJECTION

Error: The system cannot find the path specified.

  • envinfo.js:1 Function.e.exports.sync
    [npm]/[gatsby-cli]/[envinfo]/dist/envinfo.js:1:7778

  • envinfo.js:1 Object.copySync
    [npm]/[gatsby-cli]/[envinfo]/dist/envinfo.js:1:104976

  • envinfo.js:1 Object.t.writeSync.e [as writeSync]
    [npm]/[gatsby-cli]/[envinfo]/dist/envinfo.js:1:123499

  • envinfo.js:1
    [npm]/[gatsby-cli]/[envinfo]/dist/envinfo.js:1:124274

  • envinfo.js:1 Promise.all.then.e
    [npm]/[gatsby-cli]/[envinfo]/dist/envinfo.js:1:124289

  • From previous event:

  • envinfo.js:1 p
    [npm]/[gatsby-cli]/[envinfo]/dist/envinfo.js:1:123986

  • envinfo.js:1 Object.run
    [npm]/[gatsby-cli]/[envinfo]/dist/envinfo.js:1:125487

  • create-cli.js:181 Object.handler
    [npm]/[gatsby-cli]/lib/create-cli.js:181:17

  • command.js:235 Object.runCommand
    [npm]/[gatsby-cli]/[yargs]/lib/command.js:235:44

  • yargs.js:1046 Object.parseArgs [as _parseArgs]
    [npm]/[gatsby-cli]/[yargs]/yargs.js:1046:30

  • yargs.js:551 Object.parse
    [npm]/[gatsby-cli]/[yargs]/yargs.js:551:25

  • create-cli.js:242 module.exports
    [npm]/[gatsby-cli]/lib/create-cli.js:242:157

  • index.js:126 Object.
    [npm]/[gatsby-cli]/lib/index.js:126:1

  • bootstrap_node.js:187 startup
    bootstrap_node.js:187:16

  • bootstrap_node.js:608
    bootstrap_node.js:608:3

confirmed bug

Most helpful comment

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

All 8 comments

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

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

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

same here

Found a behavior in my case that might hint at the underlying issue (I'm on v2 btw gatsby@next -> [email protected])

I'm pulling in multiple AirTable sources ([email protected]) 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

@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.

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

@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)

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rossPatton picture rossPatton  ยท  3Comments

ferMartz picture ferMartz  ยท  3Comments

Oppenheimer1 picture Oppenheimer1  ยท  3Comments

mikestopcontinues picture mikestopcontinues  ยท  3Comments

andykais picture andykais  ยท  3Comments