Skip to content

Commit

Permalink
fix(pe1168): looks like node but missing interface
Browse files Browse the repository at this point in the history
This commit addresses issue #136. When extending nodes that were defined
with Node inference, the plugin can at times fail to detect the Node
interface. For example, if the original node being extented was defined
using SDL, extending it without adding `interfaces: Node` will mean that
GraphQl doesn't know that the node being created extends the Node type.
This mean that our plugin could cause errors to be thrown at build time,
as the newly created type was expected to be a Node type but was not.
For more information see the Gatsby documentation here:
https://www.gatsbyjs.com/docs/reference/graphql-data-layer/schema-customization/#gatsby-type-builders

It says, "When defnining 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."
  • Loading branch information
luqven committed Dec 8, 2021
1 parent 9dd289d commit 9c25082
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/modules/gatsby-plugin/gatsby-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@ export const createSchemaCustomization: ICreateSchemaCustomizationHook<IImgixGat
fields.map((fieldOptions) =>
gatsbyContext.schema.buildObjectType({
name: `${fieldOptions.nodeType}`,
// We have to declare that we're extending the Node interface here
// This does the same as 'implements Node' does for SDL-defined types.
// See here for more info:
// https://www.gatsbyjs.com/docs/reference/graphql-data-layer/schema-customization/#:~:text=when%20defining%20top-level%20types%2C%20don%E2%80%99t%20forget%20to%20pass%20interfaces%3A%20%5B'node'%5D%2C%20which%20does%20the%20same%20for%20type%20builders%20as%20adding%20implements%20node%20does%20for%20sdl-defined%20types.%20
interfaces: ['Node'],
fields: {
[fieldOptions.fieldName]: {
type:
Expand Down

0 comments on commit 9c25082

Please sign in to comment.