diff --git a/packages/gatsby/src/schema/schema-composer.js b/packages/gatsby/src/schema/schema-composer.js deleted file mode 100644 index 8ba18cbabf796..0000000000000 --- a/packages/gatsby/src/schema/schema-composer.js +++ /dev/null @@ -1,22 +0,0 @@ -const { SchemaComposer, GraphQLJSON } = require(`graphql-compose`) -const { getNodeInterface } = require(`./types/node-interface`) -import { GraphQLDate } from "./types/date" -const { addDirectives } = require(`./extensions`) - -const createSchemaComposer = ({ fieldExtensions } = {}) => { - const schemaComposer = new SchemaComposer() - - // Workaround, mainly relevant in testing - // See https://github.com/graphql-compose/graphql-compose/commit/70995f7f4a07996cfbe92ebf19cae5ee4fa74ea2 - // This is fixed in v7, so can be removed once we upgrade - const { BUILT_IN_DIRECTIVES } = require(`graphql-compose/lib/SchemaComposer`) - schemaComposer._directives = [...BUILT_IN_DIRECTIVES] - - getNodeInterface({ schemaComposer }) - schemaComposer.add(GraphQLDate) - schemaComposer.add(GraphQLJSON) - addDirectives({ schemaComposer, fieldExtensions }) - return schemaComposer -} - -module.exports = { createSchemaComposer } diff --git a/packages/gatsby/src/schema/schema-composer.ts b/packages/gatsby/src/schema/schema-composer.ts new file mode 100644 index 0000000000000..e01092e3d02d3 --- /dev/null +++ b/packages/gatsby/src/schema/schema-composer.ts @@ -0,0 +1,22 @@ +import { SchemaComposer, GraphQLJSON } from "graphql-compose" +import { addDirectives, GraphQLFieldExtensionDefinition } from "./extensions" +import { GraphQLDate } from "./types/date" +import { IGatsbyResolverContext } from "./type-definitions" +import { getNodeInterface } from "./types/node-interface" + +export const createSchemaComposer = ({ + fieldExtensions, +}: GraphQLFieldExtensionDefinition = {}): SchemaComposer< + IGatsbyResolverContext +> => { + const schemaComposer: SchemaComposer> = new SchemaComposer() + + getNodeInterface({ schemaComposer }) + schemaComposer.add(GraphQLDate) + schemaComposer.add(GraphQLJSON) + addDirectives({ schemaComposer, fieldExtensions }) + return schemaComposer +}