diff --git a/packages/gatsby/src/schema/graphql-engine/print-plugins.ts b/packages/gatsby/src/schema/graphql-engine/print-plugins.ts index 154e70fc7fbe7..dae57fc47c49d 100644 --- a/packages/gatsby/src/schema/graphql-engine/print-plugins.ts +++ b/packages/gatsby/src/schema/graphql-engine/print-plugins.ts @@ -7,7 +7,7 @@ import { store } from "../../redux" import { IGatsbyState } from "../../redux/types" import { requireGatsbyPlugin } from "../../utils/require-gatsby-plugin" -const schemaCustomizationAPIs = new Set([ +export const schemaCustomizationAPIs = new Set([ `setFieldsOnGraphQLNodeType`, `createSchemaCustomization`, `createResolvers`, @@ -73,7 +73,7 @@ function render( const imports: Array = [ ...uniqGatsbyNode.map( (plugin, i) => - `import * as pluginGatsbyNode${i} from "${relativePluginPath( + `import * as pluginGatsbyNode${i} from "gatsby/dist/schema/graphql-engine/webpack-remove-apis-loader!${relativePluginPath( plugin.resolve )}/gatsby-node"` ), diff --git a/packages/gatsby/src/schema/graphql-engine/webpack-remove-apis-loader.ts b/packages/gatsby/src/schema/graphql-engine/webpack-remove-apis-loader.ts new file mode 100644 index 0000000000000..638ece7fe78c3 --- /dev/null +++ b/packages/gatsby/src/schema/graphql-engine/webpack-remove-apis-loader.ts @@ -0,0 +1,23 @@ +import { transformSync } from "@babel/core" +import { GatsbyNodeAPI } from "../../redux/types" +import * as nodeApis from "../../utils/api-node-docs" +import { schemaCustomizationAPIs } from "./print-plugins" + +module.exports = function loader(source: string): string | null | undefined { + const result = transformSync(source, { + babelrc: false, + configFile: false, + plugins: [ + [ + require.resolve(`../../utils/babel/babel-plugin-remove-api`), + { + apis: (Object.keys(nodeApis) as Array).filter( + api => !schemaCustomizationAPIs.has(api) + ), + }, + ], + ], + }) + + return result?.code +}