craftcms / gatsby-source-craft

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

Missing onError handler for invocation 'building-schema' error #19

Closed tcherokee closed 3 years ago

tcherokee commented 3 years ago

Description

Hey There,

So I just installed gatsby-source-craft and when I ran gatsby develop, I ran into the following error

Missing onError handler for invocation 'building-schema', error was 'Error: Cannot resolve types for CraftGQL_games_games_Entry'. Stacktrace was 'Error: Cannot resolve types for
CraftGQL_games_games_Entry
    at resolveInterfaceArrayAsThunk (/Users/me/Documents/Web-Stuff/Public/giochi-react/node_modules/graphql-compose/lib/utils/configAsThunk.js:102:11)
    at ObjectTypeComposer.getInterfaces (/Users/me/Documents/Web-Stuff/Public/giochi-react/node_modules/graphql-compose/lib/ObjectTypeComposer.js:734:84)
    at mergeTypes (/Users/me/Documents/Web-Stuff/Public/giochi-react/node_modules/gatsby/src/schema/schema.js:371:10)
    at forEach (/Users/me/Documents/Web-Stuff/Public/giochi-react/node_modules/gatsby/src/schema/schema.js:287:11)
    at Array.forEach (<anonymous>)
    at addTypes (/Users/me/Documents/Web-Stuff/Public/giochi-react/node_modules/gatsby/src/schema/schema.js:246:9)
    at updateSchemaComposer (/Users/me/Documents/Web-Stuff/Public/giochi-react/node_modules/gatsby/src/schema/schema.js:135:9)
    at buildSchema (/Users/me/Documents/Web-Stuff/Public/giochi-react/node_modules/gatsby/src/schema/schema.js:62:9)
    at build (/Users/me/Documents/Web-Stuff/Public/giochi-react/node_modules/gatsby/src/schema/index.js:105:24)
    at buildSchema (/Users/me/Documents/Web-Stuff/Public/giochi-react/node_modules/gatsby/src/services/build-schema.ts:19:3)'

right after this error it seems to hang on building schema.

I have run gatsby clean a number of times, deleted my .cache folder to no avail.

Additional info

I am not exactly sure what could be causing this as I can pull the data using the gatsby-source-graphql plugin.

tcherokee commented 3 years ago

So I just set up a brand new gatsby install with just the gatsby-source-craft plugin and I am still getting the error unfortunately.

tcherokee commented 3 years ago

Ok figured it out. Not a bug. I was trying to pull in Verbb/Navigation Plugin as well and that was what was causing the issue. From the documentation, I am guessing I have to configure Navigation to use the plugin.

andris-sevcenko commented 3 years ago

Okay, so I fixed this.

There were a couple of issues here at play.

1) Navigation plugin exposes the related elements in the navigation trees using the ElementInterface GraphQL interface type. This Interface is not referred to or returned by any Query, so, by looking at queries, there's no reason for Gatsby GraphQL Toolkit to even start figuring out what that interface is based on Queries.

2) There was an actual bug where some behavior was bleeding over from the experimental behavior (when setting looseInterfaces to true), which actually triggered the behavior of (1) to blow up. Namely, enabling the experimental behavior rewrites the Schema a bit and forgets the interface definitions for types, so, based on (1), Gatsby, in essence, loses all knowledge of the ElementInterface type, since it is not referred to by queries OR types at this point. So, it implodes when encountering the Navigation plugin because it does not know what to do with the ElementInterface.

I've patched so that this will still be a bug, if looseInterfaces is enabled, but really, we strongly discourage using that experimental behavior (for good reason).

If this ever comes up again and the experimental behavior is required, we'll probably try to engineer around it, but, currently, it's not worth the effort and added complexity.

I'll see if we can get a release out today for this plugin.