UNPKG

@pothos/plugin-add-graphql

Version:

A Pothos plugin for adding existing GraphQL types to a Pothos schema

25 lines (24 loc) 1.25 kB
import './global-types.js'; import './schema-builder.js'; import SchemaBuilder, { BasePlugin } from '@pothos/core'; import { GraphQLSchema } from 'graphql'; import { addTypeToSchema } from './utils.js'; const pluginName = "addGraphQL"; export default pluginName; const builtInTypes = Object.keys(new GraphQLSchema({}).getTypeMap()); export class PothosAddGraphQLPlugin extends BasePlugin { beforeBuild() { var _this_builder_options_add; const { schema, types } = (_this_builder_options_add = this.builder.options.add) !== null && _this_builder_options_add !== void 0 ? _this_builder_options_add : {}; var _schema_getTypeMap; const allTypes = [ ...Array.isArray(types) ? types : Object.values(types !== null && types !== void 0 ? types : {}), ...Object.values((_schema_getTypeMap = schema === null || schema === void 0 ? void 0 : schema.getTypeMap()) !== null && _schema_getTypeMap !== void 0 ? _schema_getTypeMap : {}).filter((type) => !builtInTypes.includes(type.name)) ]; for (const type of allTypes) { addTypeToSchema(this.builder, type); } } } SchemaBuilder.registerPlugin(pluginName, PothosAddGraphQLPlugin); //# sourceMappingURL=index.js.map