UNPKG

@cran/gql.core

Version:

Cran/GraphQL Core Utilities

45 lines (44 loc) 1.63 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.composeExecutableSchema = void 0; const Plugin_1 = require("../plugins/Plugin"); const schema_1 = require("@graphql-tools/schema"); // eslint-disable-next-line max-lines-per-function function composeExecutableSchema(definition) { const plugins = definition.plugins || []; let schema = (0, schema_1.makeExecutableSchema)({ ...definition, typeDefs: [ definition.typeDefs, ...plugins.map(function mapTypeDefs(plugin) { return plugin.typeDefs; }).filter(Boolean), ], resolvers: ([ ...(Array.isArray(definition.resolvers) ? definition.resolvers : [definition.resolvers,]), ...plugins.map(function mapResolvers(plugin) { return plugin.resolvers; }), ].filter(Boolean)), }); for (const phase of [ Plugin_1.PluginPhase.PREPARE, Plugin_1.PluginPhase.DEFAULT, Plugin_1.PluginPhase.FINALIZE, ]) { for (const plugin of plugins) { if (!plugin.transformer) { continue; } if (plugin.transformer instanceof Function) { if (phase === Plugin_1.PluginPhase.DEFAULT) { schema = plugin.transformer(schema); } } else if (plugin.transformer[phase] instanceof Function) { schema = plugin.transformer[phase](schema); } } } return schema; } exports.composeExecutableSchema = composeExecutableSchema;