UNPKG

@graphql-tools/stitch

Version:

A set of utils for faster development of GraphQL tools

26 lines (25 loc) 1.21 kB
import { collectSubFields } from '@graphql-tools/utils'; export function getFieldsNotInSubschema(schema, stitchingInfo, gatewayType, subschemaType, fieldNodes, fragments, variableValues) { const { fields: subFieldNodesByResponseKey } = collectSubFields(schema, fragments, variableValues, gatewayType, fieldNodes); // TODO: Verify whether it is safe that extensions always exists. const fieldNodesByField = stitchingInfo?.fieldNodesByField; const fields = subschemaType.getFields(); const fieldsNotInSchema = new Set(); for (const [, subFieldNodes] of subFieldNodesByResponseKey) { const fieldName = subFieldNodes[0].name.value; if (!fields[fieldName]) { for (const subFieldNode of subFieldNodes) { fieldsNotInSchema.add(subFieldNode); } } const fieldNodesForField = fieldNodesByField?.[gatewayType.name]?.[fieldName]; if (fieldNodesForField) { for (const fieldNode of fieldNodesForField) { if (!fields[fieldNode.name.value]) { fieldsNotInSchema.add(fieldNode); } } } } return Array.from(fieldsNotInSchema); }