diff --git a/gateway-js/src/FieldSet.ts b/gateway-js/src/FieldSet.ts index 1757872dd2..02cf29a2ff 100644 --- a/gateway-js/src/FieldSet.ts +++ b/gateway-js/src/FieldSet.ts @@ -64,25 +64,8 @@ function groupBy(keyFunction: (element: T) => U) { }; } -// The response name isn't sufficient for determining uniqueness. In the case of -// unions, for example, we can see a response name collision where the parent type -// is different. In this case, these should not be merged (media)! -// query { -// content { -// ... on Audio { -// media { -// url -// } -// } -// ... on Video { -// media { -// aspectRatio -// } -// } -// } -// } -export const groupByParentTypeAndResponseName = groupBy(field => - `${field.scope.parentType}:${getResponseName(field.fieldNode)}`, +export const groupByResponseName = groupBy(field => + getResponseName(field.fieldNode) ); export const groupByParentType = groupBy( @@ -98,7 +81,7 @@ export function selectionSetFromFieldSet( selections: Array.from(groupByParentType(fields)).flatMap( ([typeCondition, fieldsByParentType]: [GraphQLCompositeType, FieldSet]) => wrapInInlineFragmentIfNeeded( - Array.from(groupByParentTypeAndResponseName(fieldsByParentType).values()).map( + Array.from(groupByResponseName(fieldsByParentType).values()).map( fieldsByResponseName => { return combineFields(fieldsByResponseName) .fieldNode; diff --git a/gateway-js/src/buildQueryPlan.ts b/gateway-js/src/buildQueryPlan.ts index fe6ae3396f..1b255cbd95 100644 --- a/gateway-js/src/buildQueryPlan.ts +++ b/gateway-js/src/buildQueryPlan.ts @@ -31,7 +31,7 @@ import { Field, FieldSet, groupByParentType, - groupByParentTypeAndResponseName, + groupByResponseName, matchesField, selectionSetFromFieldSet, Scope, @@ -373,7 +373,7 @@ function splitFields( fields: FieldSet, groupForField: (field: Field) => FetchGroup, ) { - for (const fieldsForResponseName of groupByParentTypeAndResponseName(fields).values()) { + for (const fieldsForResponseName of groupByResponseName(fields).values()) { for (const [parentType, fieldsForParentType] of groupByParentType( fieldsForResponseName, )) { @@ -413,7 +413,7 @@ function splitFields( scope as Scope, group, path, - fieldsForResponseName, + fieldsForParentType, ), ); } else { @@ -452,7 +452,7 @@ function splitFields( field.fieldNode, ); - const fieldsWithRuntimeParentType = fieldsForResponseName.map(field => ({ + const fieldsWithRuntimeParentType = fieldsForParentType.map(field => ({ ...field, fieldDef, }));