UNPKG

graphile-build

Version:

Build a GraphQL schema from plugins

51 lines (50 loc) 1.57 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var QueryPlugin = async function QueryPlugin(builder) { builder.hook("build", build => build.extend(build, { $$isQuery: Symbol("isQuery") }, `Extending Build`), ["Query"]); builder.hook("GraphQLSchema", (schema, build) => { const { $$isQuery, newWithHooks, extend, graphql: { GraphQLObjectType, GraphQLNonNull }, inflection } = build; const queryType = newWithHooks(GraphQLObjectType, { description: build.wrapDescription("The root query type which gives access points into the data universe.", "type"), name: inflection.builtin("Query"), isTypeOf: (value, _context, info) => info.parentType == null || value === $$isQuery, fields: ({ Self }) => ({ query: { description: build.wrapDescription("Exposes the root query type nested one level down. This is helpful for Relay 1 which can only query top level fields if they are in a particular form.", "field"), type: new GraphQLNonNull(Self), resolve() { return $$isQuery; } } }) }, { __origin: `graphile-build built-in (root query type)`, isRootQuery: true }, true); if (queryType) { return extend(schema, { query: queryType }, `Adding 'query' type to Schema`); } else { return schema; } }, ["Query"]); }; exports.default = QueryPlugin; //# sourceMappingURL=QueryPlugin.js.map