Skip to content

Commit d97f472

Browse files
authored
shareable mutation (#144)
Similar to the `shared-root` test. It ensures mutation is ran through a single mutation field of a single subgraph, even though it's shareable and it's "cheaper" to collect two fields from two subgraphs using the shareable root field.
1 parent 3bb84ad commit d97f472

File tree

15 files changed

+186
-69
lines changed

15 files changed

+186
-69
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ This repository contains a set of tests to evaluate and compare the compatibilit
1010

1111
| Gateway | Compatibility | Test Cases | Test Suites |
1212
| :-------------------------------------------------------------: | :-----------: | :----------: | :---------: |
13-
| [Hive Gateway](https://the-guild.dev/graphql/hive/docs/gateway) | 100.00% | 🟢 187 | 🟢 41 |
14-
| [Apollo Router](https://www.apollographql.com/) | 97.86% | 🟢 183 ❌ 4 | 🟢 39 ❌ 2 |
15-
| [Apollo Gateway](https://www.apollographql.com/) | 97.33% | 🟢 182 ❌ 5 | 🟢 38 ❌ 3 |
16-
| [Cosmo Router](https://wundergraph.com) | 95.19% | 🟢 178 ❌ 9 | 🟢 36 ❌ 5 |
17-
| [Grafbase Gateway](https://grafbase.com) | 90.91% | 🟢 170 ❌ 17 | 🟢 356 |
18-
| [Inigo Gateway](https://inigo.io) | 48.66% | 🟢 91 ❌ 96 | 🟢 12 ❌ 29 |
13+
| [Hive Gateway](https://the-guild.dev/graphql/hive/docs/gateway) | 100.00% | 🟢 188 | 🟢 41 |
14+
| [Apollo Router](https://www.apollographql.com/) | 97.87% | 🟢 184 ❌ 4 | 🟢 39 ❌ 2 |
15+
| [Apollo Gateway](https://www.apollographql.com/) | 97.34% | 🟢 183 ❌ 5 | 🟢 38 ❌ 3 |
16+
| [Cosmo Router](https://wundergraph.com) | 95.21% | 🟢 179 ❌ 9 | 🟢 36 ❌ 5 |
17+
| [Grafbase Gateway](https://grafbase.com) | 90.43% | 🟢 170 ❌ 18 | 🟢 347 |
18+
| [Inigo Gateway](https://inigo.io) | 48.94% | 🟢 92 ❌ 96 | 🟢 12 ❌ 29 |
1919

2020
<!-- gateways:end -->
2121

REPORT.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44

55
| Gateway | Compatibility | Test Cases | Test Suites |
66
| :-------------------------------------------------------------: | :-----------: | :----------: | :---------: |
7-
| [Hive Gateway](https://the-guild.dev/graphql/hive/docs/gateway) | 100.00% | 🟢 187 | 🟢 41 |
8-
| [Apollo Router](https://www.apollographql.com/) | 97.86% | 🟢 183 ❌ 4 | 🟢 39 ❌ 2 |
9-
| [Apollo Gateway](https://www.apollographql.com/) | 97.33% | 🟢 182 ❌ 5 | 🟢 38 ❌ 3 |
10-
| [Cosmo Router](https://wundergraph.com) | 95.19% | 🟢 178 ❌ 9 | 🟢 36 ❌ 5 |
11-
| [Grafbase Gateway](https://grafbase.com) | 90.91% | 🟢 170 ❌ 17 | 🟢 356 |
12-
| [Inigo Gateway](https://inigo.io) | 48.66% | 🟢 91 ❌ 96 | 🟢 12 ❌ 29 |
7+
| [Hive Gateway](https://the-guild.dev/graphql/hive/docs/gateway) | 100.00% | 🟢 188 | 🟢 41 |
8+
| [Apollo Router](https://www.apollographql.com/) | 97.87% | 🟢 184 ❌ 4 | 🟢 39 ❌ 2 |
9+
| [Apollo Gateway](https://www.apollographql.com/) | 97.34% | 🟢 183 ❌ 5 | 🟢 38 ❌ 3 |
10+
| [Cosmo Router](https://wundergraph.com) | 95.21% | 🟢 179 ❌ 9 | 🟢 36 ❌ 5 |
11+
| [Grafbase Gateway](https://grafbase.com) | 90.43% | 🟢 170 ❌ 18 | 🟢 347 |
12+
| [Inigo Gateway](https://inigo.io) | 48.94% | 🟢 92 ❌ 96 | 🟢 12 ❌ 29 |
1313

1414
## Detailed Results
1515

@@ -57,7 +57,7 @@ You can look at the full list of tests [here](./src/test-suites/). Every test id
5757
<a href="./src/test-suites/keys-mashup">keys-mashup</a>
5858
<pre>🟢</pre>
5959
<a href="./src/test-suites/mutations">mutations</a>
60-
<pre>🟢🟢🟢</pre>
60+
<pre>🟢🟢🟢🟢</pre>
6161
<a href="./src/test-suites/mysterious-external">mysterious-external</a>
6262
<pre>🟢🟢</pre>
6363
<a href="./src/test-suites/nested-provides">nested-provides</a>
@@ -150,7 +150,7 @@ You can look at the full list of tests [here](./src/test-suites/). Every test id
150150
<a href="./src/test-suites/keys-mashup">keys-mashup</a>
151151
<pre>❌</pre>
152152
<a href="./src/test-suites/mutations">mutations</a>
153-
<pre>🟢🟢🟢</pre>
153+
<pre>🟢🟢🟢🟢</pre>
154154
<a href="./src/test-suites/mysterious-external">mysterious-external</a>
155155
<pre>🟢🟢</pre>
156156
<a href="./src/test-suites/nested-provides">nested-provides</a>
@@ -243,7 +243,7 @@ You can look at the full list of tests [here](./src/test-suites/). Every test id
243243
<a href="./src/test-suites/keys-mashup">keys-mashup</a>
244244
<pre>❌</pre>
245245
<a href="./src/test-suites/mutations">mutations</a>
246-
<pre>🟢🟢🟢</pre>
246+
<pre>🟢🟢🟢🟢</pre>
247247
<a href="./src/test-suites/mysterious-external">mysterious-external</a>
248248
<pre>🟢🟢</pre>
249249
<a href="./src/test-suites/nested-provides">nested-provides</a>
@@ -336,7 +336,7 @@ You can look at the full list of tests [here](./src/test-suites/). Every test id
336336
<a href="./src/test-suites/keys-mashup">keys-mashup</a>
337337
<pre>🟢</pre>
338338
<a href="./src/test-suites/mutations">mutations</a>
339-
<pre>🟢🟢🟢</pre>
339+
<pre>🟢🟢🟢🟢</pre>
340340
<a href="./src/test-suites/mysterious-external">mysterious-external</a>
341341
<pre>🟢🟢</pre>
342342
<a href="./src/test-suites/nested-provides">nested-provides</a>
@@ -429,7 +429,7 @@ You can look at the full list of tests [here](./src/test-suites/). Every test id
429429
<a href="./src/test-suites/keys-mashup">keys-mashup</a>
430430
<pre>🟢</pre>
431431
<a href="./src/test-suites/mutations">mutations</a>
432-
<pre>🟢🟢🟢</pre>
432+
<pre>🟢🟢🟢</pre>
433433
<a href="./src/test-suites/mysterious-external">mysterious-external</a>
434434
<pre>🟢🟢</pre>
435435
<a href="./src/test-suites/nested-provides">nested-provides</a>
@@ -522,7 +522,7 @@ You can look at the full list of tests [here](./src/test-suites/). Every test id
522522
<a href="./src/test-suites/keys-mashup">keys-mashup</a>
523523
<pre>❌</pre>
524524
<a href="./src/test-suites/mutations">mutations</a>
525-
<pre>🟢🟢❌</pre>
525+
<pre>🟢🟢❌🟢</pre>
526526
<a href="./src/test-suites/mysterious-external">mysterious-external</a>
527527
<pre>🟢🟢</pre>
528528
<a href="./src/test-suites/nested-provides">nested-provides</a>

gateways/apollo-gateway/results.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ interface-object-with-requires
2929
keys-mashup
3030
X
3131
mutations
32-
...
32+
....
3333
mysterious-external
3434
..
3535
nested-provides
@@ -82,6 +82,6 @@ union-intersection
8282
............
8383

8484
---
85-
Total: 187
86-
Passed: 182
85+
Total: 188
86+
Passed: 183
8787
Failed: 5

gateways/apollo-router/results.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ interface-object-with-requires
2929
keys-mashup
3030
X
3131
mutations
32-
...
32+
....
3333
mysterious-external
3434
..
3535
nested-provides
@@ -82,6 +82,6 @@ union-intersection
8282
............
8383

8484
---
85-
Total: 187
86-
Passed: 183
85+
Total: 188
86+
Passed: 184
8787
Failed: 4

gateways/cosmo-router/install.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ set -u
88
BINARY_DOWNLOAD_PREFIX="https://github.com/wundergraph/cosmo/releases/download"
99

1010
# https://github.com/wundergraph/cosmo/releases
11-
DOWNLOAD_VERSION="0.220.0"
11+
DOWNLOAD_VERSION="0.222.1"
1212

1313
download_binary() {
1414
downloader --check

gateways/cosmo-router/results.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ interface-object-with-requires
2929
keys-mashup
3030
.
3131
mutations
32-
...
32+
....
3333
mysterious-external
3434
..
3535
nested-provides
@@ -82,6 +82,6 @@ union-intersection
8282
............
8383

8484
---
85-
Total: 187
86-
Passed: 178
85+
Total: 188
86+
Passed: 179
8787
Failed: 9

gateways/grafbase-gateway/results.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ interface-object-with-requires
2929
keys-mashup
3030
.
3131
mutations
32-
...
32+
...X
3333
mysterious-external
3434
..
3535
nested-provides
@@ -82,6 +82,6 @@ union-intersection
8282
........X..X
8383

8484
---
85-
Total: 187
85+
Total: 188
8686
Passed: 170
87-
Failed: 17
87+
Failed: 18

gateways/hive-gateway/results.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ interface-object-with-requires
2929
keys-mashup
3030
.
3131
mutations
32-
...
32+
....
3333
mysterious-external
3434
..
3535
nested-provides
@@ -82,6 +82,6 @@ union-intersection
8282
............
8383

8484
---
85-
Total: 187
86-
Passed: 187
85+
Total: 188
86+
Passed: 188
8787
Failed: 0

gateways/inigo-gateway/results.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ XXXXXXX
2929
keys-mashup
3030
X
3131
mutations
32-
..X
32+
..X.
3333
mysterious-external
3434
..
3535
nested-provides
@@ -82,6 +82,6 @@ union-intersection
8282
XXXXXXXXX.XX
8383

8484
---
85-
Total: 187
86-
Passed: 91
85+
Total: 188
86+
Passed: 92
8787
Failed: 96

src/test-suites/mutations/a.subgraph.ts

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import { createSubgraph } from "../../subgraph.js";
22
import {
3+
addCategory,
34
addProduct,
45
deleteProduct,
6+
getCategories,
57
getProducts,
68
initProducts,
79
multiplyNumber,
@@ -10,10 +12,14 @@ import {
1012
export default createSubgraph("a", {
1113
typeDefs: /* GraphQL */ `
1214
extend schema
13-
@link(url: "https://specs.apollo.dev/federation/v2.3", import: ["@key"])
15+
@link(
16+
url: "https://specs.apollo.dev/federation/v2.3"
17+
import: ["@key", "@shareable"]
18+
)
1419
1520
type Mutation {
1621
addProduct(input: AddProductInput!): Product!
22+
addCategory(name: String!, requestId: String!): Category! @shareable
1723
multiply(by: Int!, requestId: String!): Int!
1824
}
1925
@@ -32,11 +38,15 @@ export default createSubgraph("a", {
3238
name: String!
3339
price: Float!
3440
}
41+
42+
type Category @key(fields: "id") {
43+
id: ID!
44+
}
3545
`,
3646
resolvers: {
3747
Query: {
3848
async product(_: {}, { id }: { id: string }) {
39-
await initProducts();
49+
initProducts();
4050
const product = (await getProducts()).find((p) => p.id === id);
4151

4252
if (!product) {
@@ -50,7 +60,7 @@ export default createSubgraph("a", {
5060
};
5161
},
5262
async products() {
53-
await initProducts();
63+
initProducts();
5464
return getProducts();
5565
},
5666
},
@@ -77,6 +87,18 @@ export default createSubgraph("a", {
7787
) {
7888
return addProduct(input.name, input.price);
7989
},
90+
async addCategory(
91+
_: {},
92+
{
93+
name,
94+
requestId,
95+
}: {
96+
name: string;
97+
requestId: string;
98+
},
99+
) {
100+
return addCategory(name, requestId);
101+
},
80102
},
81103
Product: {
82104
async __resolveReference(key: { id: string }) {
@@ -96,5 +118,19 @@ export default createSubgraph("a", {
96118
};
97119
},
98120
},
121+
Category: {
122+
__resolveReference(key: { id: string }) {
123+
const categories = getCategories();
124+
const category = categories.find((p) => p.id === key.id);
125+
126+
if (!category) {
127+
return null;
128+
}
129+
130+
return {
131+
id: category.id,
132+
};
133+
},
134+
},
99135
},
100136
});

0 commit comments

Comments
 (0)