Gatsby: [gatsby-source-graphql] [v2] The new GraphQL source plugin doesn't update cached schema

Created on 15 Aug 2018  路  4Comments  路  Source: gatsbyjs/gatsby

Description

The new gatsby-source-graphql that stitches schema together and allows using other GraphQL servers, apparently has an issue that if the schema on remote server has changed, it won't be reflected in Gatsby.

A harsh workaround is rm -rf .cache before running Gatsby.

Steps to reproduce

  • Configure a new source for Gatsby using gatsby-source-graphql.
  • gatsby develop
  • A change happens in remote schema, you also change query in your source to reflect that change.
  • Gatsby will error, because there is no such data.
  • Restart gatsby: gatsby develop
  • Error is still thrown.
GraphQL Error Unknown field `copyrightDate` on type `Nethart_Footer`

  file: /Users/tomo/projects/nh3.0/gatsby-craftql/src/blocks/Footer.js

   2 |       {
   3 |         nethart {
   4 |           globals {
   5 |             footer {
   6 |               followTitle: socialMediaCta
   7 |               social: socialMediaLinks {
   8 |                 name: socialMediaName
   9 |                 url: socialMediaLink
  10 |               }
  11 |               slogan: companyName
> 12 |               copyrightDate
     |               ^
  13 |               addressEntries: contactInfo {
  14 |                 text: contactText
  15 |                 type: contactTextType
  16 |               }
  17 |             }
  18 |           }
  19 |         }
  20 |       }
  21 |

 ERROR  Failed to compile with 1 errors                                                                                                                                                                                                                               2:05:50 PM

 error  in ./src/blocks/Footer.js

Our backend is CraftCMS with CraftQL, we are currently setting up our CMS alongside frontend development. Here, I changed field name from companyDate to copyrightDate.

Expected result

If the remote schema has changed, update accordingly.
I'd be okay that Gatsby asks for restart or something. (Though I don't see it as the right way to do things)

Actual result

The schema is getting cached, supposedly on first run, and stays there indefinitely.

Environment

  System:
    OS: macOS High Sierra 10.13.6
    CPU: x64 Intel(R) Core(TM) i5-7360U CPU @ 2.30GHz
    Shell: 3.2.57 - /bin/bash
  Binaries:
    Node: 10.7.0 - /usr/local/bin/node
    Yarn: 1.9.2 - /usr/local/bin/yarn
    npm: 6.2.0 - /usr/local/bin/npm
  Browsers:
    Chrome: 68.0.3440.106
    Safari: 11.1.2
  npmPackages:
    gatsby: next => 2.0.0-beta.92 
    gatsby-plugin-emotion: ^2.0.0-beta.3 => 2.0.0-beta.3 
    gatsby-plugin-manifest: next => 2.0.2-beta.4 
    gatsby-plugin-offline: next => 2.0.0-beta.9 
    gatsby-plugin-react-helmet: next => 3.0.0-beta.4 
    gatsby-source-filesystem: ^2.0.1-beta.10 => 2.0.1-beta.10 
    gatsby-source-graphql: ^2.0.0-beta.1 => 2.0.0-beta.1 
    gatsby-transformer-json: ^2.1.1-beta.5 => 2.1.1-beta.5

File contents (if changed)

gatsby-config.js: N/A
package.json: N/A
gatsby-node.js: N/A
gatsby-browser.js: N/A
gatsby-ssr.js: N/A

needs more info

All 4 comments

@joltmode can you share a minimal reproduction with sample data?

@joltmode have you tried setting the refreshInterval or using createSchema?

@dbrookes, thanks for the links, the answer appears to be in the readme:

By default schema is introspected from the remote schema. Schema is cached in .cache in this case and refreshing the schema requires deleting the cache.

Missed the part before. So, it appears to be the expected behaviour.

createSchema feels like the solution to use, if I don't like the default.
refreshInterval wouldn't cut it, as it would only requery the data based on current schema, not also update the schema, if I understood correctly.

An option to opt-out of default schema caching behaviour would be great, though.
Currently I would go about retrieving the schema the same way it is done now, just to set up my custom createSchema callback to prevent caching.
Boolean flag seems easier. Though, I might be the only one who has both - the backend and the frontend in prototypal/startup phase.

Hi @joltmode, since this is the expected behavior with gatsby-source-graphql we are closing this issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kalinchernev picture kalinchernev  路  3Comments

hobochild picture hobochild  路  3Comments

KyleAMathews picture KyleAMathews  路  3Comments

dustinhorton picture dustinhorton  路  3Comments

benstr picture benstr  路  3Comments