Skip to content

Commit

Permalink
fix(delegate): WrapConcreteTypes regression (#2174)
Browse files Browse the repository at this point in the history
WrapConcreteTypes should not process fragments that are not on a root type.

addresses #2173
  • Loading branch information
yaacovCR committed Nov 1, 2020
1 parent b25e16c commit 856e23f
Show file tree
Hide file tree
Showing 4 changed files with 315 additions and 108 deletions.
5 changes: 5 additions & 0 deletions .changeset/old-wasps-worry.md
@@ -0,0 +1,5 @@
---
'@graphql-tools/delegate': patch
---

fix(delegate): WrapConcreteTypes should not process fragments that are not on a root type (#2173)
11 changes: 11 additions & 0 deletions packages/delegate/src/transforms/WrapConcreteTypes.ts
Expand Up @@ -10,6 +10,7 @@ import {
visitWithTypeInfo,
isObjectType,
FieldNode,
FragmentDefinitionNode,
} from 'graphql';

import { Request } from '@graphql-tools/utils';
Expand Down Expand Up @@ -47,10 +48,20 @@ function wrapConcreteTypes(
return document;
}

const queryTypeName = targetSchema.getQueryType()?.name;
const mutationTypeName = targetSchema.getMutationType()?.name;
const subscriptionTypeName = targetSchema.getSubscriptionType()?.name;

const typeInfo = new TypeInfo(targetSchema);
const newDocument = visit(
document,
visitWithTypeInfo(typeInfo, {
[Kind.FRAGMENT_DEFINITION]: (node: FragmentDefinitionNode) => {
const typeName = node.typeCondition.name.value;
if (typeName !== queryTypeName && typeName !== mutationTypeName && typeName !== subscriptionTypeName) {
return false;
}
},
[Kind.FIELD]: (node: FieldNode) => {
if (isAbstractType(getNamedType(typeInfo.getType()))) {
return {
Expand Down
108 changes: 0 additions & 108 deletions packages/stitch/tests/fragments.test.ts

This file was deleted.

0 comments on commit 856e23f

Please sign in to comment.