From 7dc86887fc72651c3e3123171c944485e81cb676 Mon Sep 17 00:00:00 2001 From: jdecroock Date: Wed, 3 Apr 2024 06:36:50 +0200 Subject: [PATCH] fix type issues --- packages/delegate/src/mergeFields.ts | 8 ++++++-- packages/stitch/src/executor.ts | 6 +++--- packages/stitch/src/getFieldsNotInSubschema.ts | 8 ++++---- packages/stitch/src/stitchingInfo.ts | 2 +- packages/utils/src/visitResult.ts | 18 +++++++++--------- 5 files changed, 23 insertions(+), 19 deletions(-) diff --git a/packages/delegate/src/mergeFields.ts b/packages/delegate/src/mergeFields.ts index ef479d45d43..681ef3b3477 100644 --- a/packages/delegate/src/mergeFields.ts +++ b/packages/delegate/src/mergeFields.ts @@ -117,12 +117,16 @@ function handleResolverResult( const type = schema.getType(object.__typename) as GraphQLObjectType; const { fields } = collectFields(schema, EMPTY_OBJECT, EMPTY_OBJECT, type, selectionSet); const nullResult: Record = {}; - for (const [responseKey, fieldNodes] of fields) { + for (const [responseKey, fieldGroups] of fields) { const combinedPath = [...path, responseKey]; if (resolverResult instanceof GraphQLError) { nullResult[responseKey] = relocatedError(resolverResult, combinedPath); } else if (resolverResult instanceof Error) { - nullResult[responseKey] = locatedError(resolverResult, fieldNodes, combinedPath); + nullResult[responseKey] = locatedError( + resolverResult, + fieldGroups.map(group => group.fieldNode), + combinedPath, + ); } else { nullResult[responseKey] = null; } diff --git a/packages/stitch/src/executor.ts b/packages/stitch/src/executor.ts index ee4b19dd193..6f9b50c3b03 100644 --- a/packages/stitch/src/executor.ts +++ b/packages/stitch/src/executor.ts @@ -32,8 +32,8 @@ export function createStitchingExecutor(stitchedSchema: GraphQLSchema) { operation.selectionSet, ); const data: Record = {}; - for (const [fieldName, fieldNodes] of fields) { - const responseKey = fieldNodes[0].alias?.value ?? fieldName; + for (const [fieldName, fieldGroups] of fields) { + const responseKey = fieldGroups[0].fieldNode.alias?.value ?? fieldName; const subschemaForField = subschemas.find(subschema => { const subschemaSchema = isSubschemaConfig(subschema) ? subschema.schema @@ -48,7 +48,7 @@ export function createStitchingExecutor(stitchedSchema: GraphQLSchema) { info: { schema: stitchedSchema, fieldName, - fieldNodes, + fieldNodes: fieldGroups.map(group => group.fieldNode), operation, fragments, parentType: rootType, diff --git a/packages/stitch/src/getFieldsNotInSubschema.ts b/packages/stitch/src/getFieldsNotInSubschema.ts index f75bc80f968..0c32bb4305e 100644 --- a/packages/stitch/src/getFieldsNotInSubschema.ts +++ b/packages/stitch/src/getFieldsNotInSubschema.ts @@ -25,11 +25,11 @@ export function getFieldsNotInSubschema( const fields = subschemaType.getFields(); const fieldsNotInSchema = new Set(); - for (const [, subFieldNodes] of subFieldNodesByResponseKey) { - const fieldName = subFieldNodes[0].name.value; + for (const [, subFieldGroups] of subFieldNodesByResponseKey) { + const fieldName = subFieldGroups[0].fieldNode.name.value; if (!fields[fieldName]) { - for (const subFieldNode of subFieldNodes) { - fieldsNotInSchema.add(subFieldNode); + for (const subFieldNode of subFieldGroups) { + fieldsNotInSchema.add(subFieldNode.fieldNode); } } const fieldNodesForField = fieldNodesByField?.[gatewayType.name]?.[fieldName]; diff --git a/packages/stitch/src/stitchingInfo.ts b/packages/stitch/src/stitchingInfo.ts index 72ca8c9f3a3..cbba1ed4a9c 100644 --- a/packages/stitch/src/stitchingInfo.ts +++ b/packages/stitch/src/stitchingInfo.ts @@ -318,7 +318,7 @@ export function completeStitchingInfo>( const { fields } = collectFields(schema, fragments, variableValues, type, selectionSet); for (const [, fieldNodes] of fields) { - for (const fieldNode of fieldNodes) { + for (const { fieldNode } of fieldNodes) { const key = print(fieldNode); if (fieldNodeMap[key] == null) { fieldNodeMap[key] = fieldNode; diff --git a/packages/utils/src/visitResult.ts b/packages/utils/src/visitResult.ts index 906b701589c..974568344a5 100644 --- a/packages/utils/src/visitResult.ts +++ b/packages/utils/src/visitResult.ts @@ -1,5 +1,4 @@ import { - FieldNode, FragmentDefinitionNode, getNullableType, GraphQLError, @@ -15,7 +14,7 @@ import { TypeMetaFieldDef, TypeNameMetaFieldDef, } from 'graphql'; -import { collectFields, collectSubFields } from './collectFields.js'; +import { collectFields, collectSubFields, FieldDetails } from './collectFields.js'; import { getOperationASTFromRequest } from './getOperationASTFromRequest.js'; import { ExecutionRequest, ExecutionResult } from './Interfaces.js'; import { Maybe } from './types.js'; @@ -204,7 +203,7 @@ function visitRoot( function visitObjectValue( object: Record, type: GraphQLObjectType, - fieldNodeMap: Map, + fieldNodeMap: Map, schema: GraphQLSchema, fragments: Record, variableValues: Record, @@ -230,7 +229,7 @@ function visitObjectValue( } for (const [responseKey, subFieldNodes] of fieldNodeMap) { - const fieldName = subFieldNodes[0].name.value; + const fieldName = subFieldNodes[0].fieldNode.name.value; let fieldType = fieldMap[fieldName]?.type; if (fieldType == null) { switch (fieldName) { @@ -257,6 +256,7 @@ function visitObjectValue( addPathSegmentInfo(type, fieldName, newPathIndex, fieldErrors, errorInfo); } + // TODO: for fragment arguments we might need to update the variable-values here. const newValue = visitFieldValue( object[responseKey], fieldType, @@ -322,7 +322,7 @@ function updateObject( function visitListValue( list: Array, returnType: GraphQLOutputType, - fieldNodes: Array, + fieldNodes: Array, schema: GraphQLSchema, fragments: Record, variableValues: Record, @@ -350,7 +350,7 @@ function visitListValue( function visitFieldValue( value: any, returnType: GraphQLOutputType, - fieldNodes: Array, + fieldGroups: Array, schema: GraphQLSchema, fragments: Record, variableValues: Record, @@ -368,7 +368,7 @@ function visitFieldValue( return visitListValue( value as Array, nullableType.ofType, - fieldNodes, + fieldGroups, schema, fragments, variableValues, @@ -384,7 +384,7 @@ function visitFieldValue( fragments, variableValues, finalType, - fieldNodes, + fieldGroups.map(group => group.fieldNode), ); return visitObjectValue( value, @@ -404,7 +404,7 @@ function visitFieldValue( fragments, variableValues, nullableType, - fieldNodes, + fieldGroups.map(group => group.fieldNode), ); return visitObjectValue( value,