diff --git a/packages/gatsby/src/schema/node-model.js b/packages/gatsby/src/schema/node-model.js index e839d978f53f8..5e5c30abedfd5 100644 --- a/packages/gatsby/src/schema/node-model.js +++ b/packages/gatsby/src/schema/node-model.js @@ -846,7 +846,7 @@ async function resolveRecursive( return _.pickBy(resolvedFields, (value, key) => queryFields[key]) } - +let withResolverContext function resolveField( nodeModel, schemaComposer, @@ -858,7 +858,13 @@ function resolveField( if (!gqlField?.resolve) { return node[fieldName] } - const withResolverContext = require(`./context`) + + // We require this inline as there's a circular dependency from context back to this file. + // https://github.com/gatsbyjs/gatsby/blob/9d33b107d167e3e9e2aa282924a0c409f6afd5a0/packages/gatsby/src/schema/context.ts#L5 + if (!withResolverContext) { + withResolverContext = require(`./context`) + } + return gqlField.resolve( node, gqlField.args.reduce((acc, arg) => {