UNPKG

@pothos/plugin-sub-graph

Version:

A Pothos plugin for creating multiple variants or sub-selections of the same graph

17 lines (16 loc) 711 B
import { PothosSchemaError } from '@pothos/core'; import { GraphQLList, GraphQLNonNull } from 'graphql'; export function replaceType(type, newTypes, referencedBy, subGraphs) { if (type instanceof GraphQLNonNull) { return new GraphQLNonNull(replaceType(type.ofType, newTypes, referencedBy, subGraphs)); } if (type instanceof GraphQLList) { return new GraphQLList(replaceType(type.ofType, newTypes, referencedBy, subGraphs)); } const newType = newTypes.get(type.name); if (!newType) { throw new PothosSchemaError(`${type.name} (referenced by ${referencedBy}) does not exist in subGraph (${subGraphs})`); } return newType; } //# sourceMappingURL=util.js.map