From 9c2508215ccbdf50163e9427a14b5ae503cc9c55 Mon Sep 17 00:00:00 2001 From: Luis Ball Date: Wed, 4 Aug 2021 14:51:42 -0400 Subject: [PATCH] fix(pe1168): looks like node but missing interface 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." --- src/modules/gatsby-plugin/gatsby-node.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/modules/gatsby-plugin/gatsby-node.ts b/src/modules/gatsby-plugin/gatsby-node.ts index 8f642115..f936e4f5 100644 --- a/src/modules/gatsby-plugin/gatsby-node.ts +++ b/src/modules/gatsby-plugin/gatsby-node.ts @@ -141,6 +141,11 @@ export const createSchemaCustomization: ICreateSchemaCustomizationHook 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: