craftcms / gatsby-source-craft

Gatsby source plugin for Craft CMS.
MIT License
54 stars 13 forks source link

Gatsby 5 compatibility #95

Closed ThijmenDeValk closed 2 years ago

ThijmenDeValk commented 2 years ago

Description

When using this plugin with Gatsby 5, you instantly get an error stating visitFn.call is not a function. The stack trace seems to suggest this is a pretty low level issue with gatsby-graphql-source-toolkit. My guess is it's fixed by https://github.com/gatsbyjs/gatsby-graphql-toolkit/pull/48, but that's not yet merged by Gatsby.

Stack trace

 ERROR #11321  PLUGIN

"gatsby-source-craft" threw an error while running the createSchemaCustomization lifecycle:

visitFn.call is not a function

  570 |     const schema = await getSchema();
  571 |     const gatsbyNodeTypes = await getGatsbyNodeTypes(gatsbyApi.reporter);
> 572 |     const documents = await compileNodeQueries({
      |                             ^
  573 |         schema,
  574 |         gatsbyNodeTypes,
  575 |         customFragments: await collectFragments(),

File: node_modules/gatsby-source-craft/gatsby-node.js:572:29
  TypeError: visitFn.call is not a function

  - compile-node-queries.ts:149 compileDocument
    [my-gatsby-site]/[gatsby-graphql-source-toolkit]/src/compile-node-queries/compile-node-queries.ts:149:10

  - compile-node-queries.ts:73 
    [my-gatsby-site]/[gatsby-graphql-source-toolkit]/src/compile-node-queries/compile-node-queries.ts:73:17

  - Array.forEach

  - compile-node-queries.ts:72 compileNodeQueries
    [my-gatsby-site]/[gatsby-graphql-source-toolkit]/src/compile-node-queries/compile-node-queries.ts:72:24

  - gatsby-node.js:572 getSourcingConfig
    [my-gatsby-site]/[gatsby-source-craft]/gatsby-node.js:572:29

  - gatsby-node.js:368 Object.exports.createSchemaCustomization
    [my-gatsby-site]/[gatsby-source-craft]/gatsby-node.js:368:20

  - api-runner-node.js:487 runAPI
    [my-gatsby-site]/[gatsby]/src/utils/api-runner-node.js:487:16

Steps to reproduce

  1. Create new Gatsby 5 project
  2. Install and configure gatsby-source-craft
  3. Run npm run develop

Example repo

https://github.com/ThijmenDeValk/gatsby-source-craft-error-proof

Additional info

ThijmenDeValk commented 2 years ago

Well, that was quick. Gatsby-graphql-toolkit v2.0.3 fixes this issue. So now all that's needed to use this with Gatsby 5 is the --legacy-peer-deps flag until official support is added to this repo (I'll make a pull request for that soon).