imgix / gatsby

A simple yet powerful integration between Gatsby and imgix
BSD 2-Clause "Simplified" License
30 stars 6 forks source link

fix(pe1168): looks like node but missing interface #154

Closed luqven closed 2 years ago

luqven commented 2 years ago

This PR implements #138 on main.

This PR addresses issue #136.

When extending a type, the plugin can at times fail to determine the original type extended the Node interface. This is likely a race condition, where the node we're extending is being created by buildObjectType before it's declared to be implementing the Node interface.

This means that our plugin could cause errors to be thrown at build time, as the newly created type was expected to be of type Node.

For more information see the Gatsby documentation here: https://www.gatsbyjs.com/docs/reference/graphql-data-layer/schema-customization/#gatsby-type-builders

"When defining top-level types, don't forget to pass interfaces: ['Node'], which does the same for Type Builders as adding implements Node to SDL-defined types."

Steps to Test

Related issue: #136

Code:

warn Type ImagesJson declared in createTypes looks like a node, but doesn't implement a Node interface. It's likely that you should add the Node interface to your type def:
type ImagesJson implements Node { ... }
If you know that you don't want it to be a node (which would mean no root queries to retrieve it), you can explicitly disable inference for it:
type ImagesJson @dontInfer { ... }
ERROR
Building schema failed
not finished building schema - 0.106s

Steps:

  1. Go to https://github.com/arsinclair/gatsby-image-schema-bug-reproduction
  2. Clone the repo
  3. run npm run develop
  4. See that the error occurs
  5. Go to node_modules/@imgix/gatsby/src/modules/gatsby-plugin/gatsby-node.ts
  6. On line 161 add interfaces: ["Node"],
  7. See that the build succeeds.
luqven commented 2 years ago

Note, ignoring the commit-lint check failure since the link it's unhappy about is needed to understand the context of the commit.

imgix-git-robot commented 2 years ago

:tada: This PR is included in version 1.7.3 :tada:

The release is available on:

Your semantic-release bot :package::rocket: