Skip to content

Commit 83c0af0

Browse files
No unnecessary inline fragment spreads for union types in federation and link dependencies (#5913)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent b1294d4 commit 83c0af0

File tree

69 files changed

+322
-58
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+322
-58
lines changed

.changeset/swift-cows-tan.md

+5

packages/batch-delegate/package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,15 @@
5050
"graphql": "^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0"
5151
},
5252
"dependencies": {
53-
"@graphql-tools/delegate": "^10.0.1",
54-
"@graphql-tools/utils": "^10.0.0",
53+
"@graphql-tools/delegate": "^10.0.3",
54+
"@graphql-tools/utils": "^10.0.13",
5555
"dataloader": "2.2.2",
5656
"tslib": "^2.4.0",
5757
"value-or-promise": "^1.0.12"
5858
},
5959
"devDependencies": {
60-
"@graphql-tools/schema": "^10.0.0",
61-
"@graphql-tools/stitch": "9.0.4"
60+
"@graphql-tools/schema": "^10.0.2",
61+
"@graphql-tools/stitch": "^9.0.4"
6262
},
6363
"publishConfig": {
6464
"directory": "dist",

packages/batch-execute/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
"graphql": "^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0"
5151
},
5252
"dependencies": {
53-
"@graphql-tools/utils": "^10.0.5",
53+
"@graphql-tools/utils": "^10.0.13",
5454
"dataloader": "^2.2.2",
5555
"tslib": "^2.4.0",
5656
"value-or-promise": "^1.0.12"

packages/delegate/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@
5252
"dependencies": {
5353
"@graphql-tools/batch-execute": "^9.0.1",
5454
"@graphql-tools/executor": "^1.0.0",
55-
"@graphql-tools/schema": "^10.0.0",
56-
"@graphql-tools/utils": "^10.0.5",
55+
"@graphql-tools/schema": "^10.0.2",
56+
"@graphql-tools/utils": "^10.0.13",
5757
"dataloader": "^2.2.2",
5858
"tslib": "^2.5.0"
5959
},

packages/delegate/src/prepareGatewayDocument.ts

+9-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import {
1010
isAbstractType,
1111
isCompositeType,
1212
isInterfaceType,
13+
isNonNullType,
14+
isUnionType,
1315
Kind,
1416
SelectionNode,
1517
SelectionSetNode,
@@ -442,8 +444,13 @@ function wrapConcreteTypes(
442444
}
443445
},
444446
[Kind.FIELD]: (node: FieldNode) => {
445-
const type = typeInfo.getType();
446-
if (type != null && isAbstractType(getNamedType(type))) {
447+
let type = typeInfo.getType();
448+
type = isNonNullType(type) ? type.ofType : type;
449+
if (
450+
type != null &&
451+
isAbstractType(getNamedType(type)) &&
452+
(!isUnionType(type) || type.name === '_Entity') // unnecessary spread on union types, except for federation's "_Entity" (https://www.apollographql.com/docs/federation/subgraph-spec/#union-_entity)
453+
) {
447454
return {
448455
...node,
449456
selectionSet: {

packages/executor/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
"graphql": "^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0"
5656
},
5757
"dependencies": {
58-
"@graphql-tools/utils": "^10.0.8",
58+
"@graphql-tools/utils": "^10.0.13",
5959
"@graphql-typed-document-node/core": "3.2.0",
6060
"@repeaterjs/repeater": "^3.0.4",
6161
"tslib": "^2.4.0",

packages/executors/apollo-link/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
"graphql": "^15.2.0 || ^16.0.0"
5353
},
5454
"dependencies": {
55-
"@graphql-tools/utils": "^10.0.0",
55+
"@graphql-tools/utils": "^10.0.13",
5656
"tslib": "^2.3.1"
5757
},
5858
"devDependencies": {

packages/executors/envelop/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@
5151
"@envelop/core": "^3.0.4 || ^4.0.0 || ^5.0.0"
5252
},
5353
"dependencies": {
54-
"@graphql-tools/utils": "^10.0.0",
55-
"@graphql-tools/wrap": "^10.0.0",
54+
"@graphql-tools/utils": "^10.0.13",
55+
"@graphql-tools/wrap": "^10.0.1",
5656
"tslib": "^2.3.1"
5757
},
5858
"devDependencies": {

packages/executors/graphql-ws/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
"graphql": "^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0"
5252
},
5353
"dependencies": {
54-
"@graphql-tools/utils": "^10.0.2",
54+
"@graphql-tools/utils": "^10.0.13",
5555
"@types/ws": "^8.0.0",
5656
"graphql-ws": "^5.14.0",
5757
"isomorphic-ws": "^5.0.0",

packages/executors/http/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
"graphql": "^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0"
5252
},
5353
"dependencies": {
54-
"@graphql-tools/utils": "^10.0.2",
54+
"@graphql-tools/utils": "^10.0.13",
5555
"@repeaterjs/repeater": "^3.0.4",
5656
"@whatwg-node/fetch": "^0.9.0",
5757
"extract-files": "^11.0.0",

packages/executors/legacy-ws/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
"graphql": "^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0"
5252
},
5353
"dependencies": {
54-
"@graphql-tools/utils": "^10.0.0",
54+
"@graphql-tools/utils": "^10.0.13",
5555
"@types/ws": "^8.0.0",
5656
"isomorphic-ws": "^5.0.0",
5757
"tslib": "^2.4.0",

packages/executors/urql-exchange/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
"wonka": "^6.0.0"
4949
},
5050
"dependencies": {
51-
"@graphql-tools/utils": "^10.0.0",
51+
"@graphql-tools/utils": "^10.0.13",
5252
"tslib": "^2.4.0"
5353
},
5454
"devDependencies": {

packages/executors/yoga/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
},
5454
"dependencies": {
5555
"@graphql-tools/executor-envelop": "^2.0.3",
56-
"@graphql-tools/utils": "^10.0.1",
56+
"@graphql-tools/utils": "^10.0.13",
5757
"tslib": "^2.3.1"
5858
},
5959
"devDependencies": {

packages/federation/package.json

+7-7
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,13 @@
5050
"graphql": "^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0"
5151
},
5252
"dependencies": {
53-
"@graphql-tools/delegate": "^10.0.1",
54-
"@graphql-tools/executor-http": "^1.0.6",
55-
"@graphql-tools/merge": "^9.0.0",
56-
"@graphql-tools/schema": "^10.0.0",
57-
"@graphql-tools/stitch": "^9.0.2",
58-
"@graphql-tools/utils": "^10.0.0",
59-
"@graphql-tools/wrap": "^10.0.0",
53+
"@graphql-tools/delegate": "^10.0.3",
54+
"@graphql-tools/executor-http": "^1.0.8",
55+
"@graphql-tools/merge": "^9.0.1",
56+
"@graphql-tools/schema": "^10.0.2",
57+
"@graphql-tools/stitch": "^9.0.4",
58+
"@graphql-tools/utils": "^10.0.13",
59+
"@graphql-tools/wrap": "^10.0.1",
6060
"tslib": "^2.4.0",
6161
"value-or-promise": "^1.0.12"
6262
},

packages/federation/test/__snapshots__/supergraphs.test.ts.snap

+2
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,7 @@ type Query {
459459
me: User
460460
throw: String
461461
fooBar: FooBar
462+
mustFooBar: FooBar!
462463
}
463464
464465
type User {
@@ -488,6 +489,7 @@ type Query {
488489
me: User
489490
throw: String
490491
fooBar: FooBar
492+
mustFooBar: FooBar!
491493
_entities(representations: [_Any!]!): _Entity
492494
}
493495

0 commit comments

Comments
 (0)