Skip to content

Commit

Permalink
New scenario: null keys (#75)
Browse files Browse the repository at this point in the history
Co-authored-by: Kamil Kisiela <[email protected]>
  • Loading branch information
ardatan and kamilkisiela authored Oct 22, 2024
1 parent c1a0fe0 commit fc65104
Show file tree
Hide file tree
Showing 16 changed files with 282 additions and 39 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ This repository contains a set of tests to evaluate and compare the compatibilit

| Gateway | Compatibility | Test Cases | Test Suites |
| :------------------------------------------------: | :-----------: | :----------: | :---------: |
| [Hive Gateway](https://the-guild.dev/graphql/hive) | 100.00% | 🟢 170 | 🟢 40 |
| [Apollo Router](https://www.apollographql.com/) | 97.65% | 🟢 166 ❌ 4 | 🟢 38 ❌ 2 |
| [Apollo Gateway](https://www.apollographql.com/) | 97.06% | 🟢 165 ❌ 5 | 🟢 37 ❌ 3 |
| [Cosmo Router](https://wundergraph.com) | 70.00% | 🟢 119 ❌ 51 | 🟢 19 ❌ 21 |
| [Grafbase Gateway](https://grafbase.com) | 60.00% | 🟢 10268 | 🟢 19 ❌ 21 |
| [Hive Gateway](https://the-guild.dev/graphql/hive) | 100.00% | 🟢 171 | 🟢 41 |
| [Apollo Router](https://www.apollographql.com/) | 97.66% | 🟢 167 ❌ 4 | 🟢 39 ❌ 2 |
| [Apollo Gateway](https://www.apollographql.com/) | 97.08% | 🟢 166 ❌ 5 | 🟢 38 ❌ 3 |
| [Cosmo Router](https://wundergraph.com) | 69.59% | 🟢 119 ❌ 52 | 🟢 19 ❌ 22 |
| [Grafbase Gateway](https://grafbase.com) | 59.06% | 🟢 10170 | 🟢 19 ❌ 22 |

<!-- gateways:end -->

Expand Down
22 changes: 16 additions & 6 deletions REPORT.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

| Gateway | Compatibility | Test Cases | Test Suites |
| :------------------------------------------------: | :-----------: | :----------: | :---------: |
| [Hive Gateway](https://the-guild.dev/graphql/hive) | 100.00% | 🟢 170 | 🟢 40 |
| [Apollo Router](https://www.apollographql.com/) | 97.65% | 🟢 166 ❌ 4 | 🟢 38 ❌ 2 |
| [Apollo Gateway](https://www.apollographql.com/) | 97.06% | 🟢 165 ❌ 5 | 🟢 37 ❌ 3 |
| [Cosmo Router](https://wundergraph.com) | 70.00% | 🟢 119 ❌ 51 | 🟢 19 ❌ 21 |
| [Grafbase Gateway](https://grafbase.com) | 60.00% | 🟢 10268 | 🟢 19 ❌ 21 |
| [Hive Gateway](https://the-guild.dev/graphql/hive) | 100.00% | 🟢 171 | 🟢 41 |
| [Apollo Router](https://www.apollographql.com/) | 97.66% | 🟢 167 ❌ 4 | 🟢 39 ❌ 2 |
| [Apollo Gateway](https://www.apollographql.com/) | 97.08% | 🟢 166 ❌ 5 | 🟢 38 ❌ 3 |
| [Cosmo Router](https://wundergraph.com) | 69.59% | 🟢 119 ❌ 52 | 🟢 19 ❌ 22 |
| [Grafbase Gateway](https://grafbase.com) | 59.06% | 🟢 10170 | 🟢 19 ❌ 22 |

## Detailed Results

Expand Down Expand Up @@ -65,6 +65,8 @@ You can look at the full list of tests [here](./src/test-suites/). Every test id
<pre>🟢</pre>
<a href="./src/test-suites/non-resolvable-interface-object">non-resolvable-interface-object</a>
<pre>🟢🟢🟢🟢🟢🟢🟢</pre>
<a href="./src/test-suites/null-keys">null-keys</a>
<pre>🟢</pre>
<a href="./src/test-suites/override-type-interface">override-type-interface</a>
<pre>🟢🟢🟢🟢</pre>
<a href="./src/test-suites/override-with-requires">override-with-requires</a>
Expand Down Expand Up @@ -156,6 +158,8 @@ You can look at the full list of tests [here](./src/test-suites/). Every test id
<pre>🟢</pre>
<a href="./src/test-suites/non-resolvable-interface-object">non-resolvable-interface-object</a>
<pre>🟢🟢🟢🟢🟢🟢🟢</pre>
<a href="./src/test-suites/null-keys">null-keys</a>
<pre>🟢</pre>
<a href="./src/test-suites/override-type-interface">override-type-interface</a>
<pre>🟢🟢🟢🟢</pre>
<a href="./src/test-suites/override-with-requires">override-with-requires</a>
Expand Down Expand Up @@ -247,6 +251,8 @@ You can look at the full list of tests [here](./src/test-suites/). Every test id
<pre>🟢</pre>
<a href="./src/test-suites/non-resolvable-interface-object">non-resolvable-interface-object</a>
<pre>🟢❌🟢🟢🟢🟢🟢</pre>
<a href="./src/test-suites/null-keys">null-keys</a>
<pre>🟢</pre>
<a href="./src/test-suites/override-type-interface">override-type-interface</a>
<pre>🟢🟢🟢🟢</pre>
<a href="./src/test-suites/override-with-requires">override-with-requires</a>
Expand Down Expand Up @@ -338,6 +344,8 @@ You can look at the full list of tests [here](./src/test-suites/). Every test id
<pre>🟢</pre>
<a href="./src/test-suites/non-resolvable-interface-object">non-resolvable-interface-object</a>
<pre>🟢🟢🟢🟢❌🟢❌</pre>
<a href="./src/test-suites/null-keys">null-keys</a>
<pre>❌</pre>
<a href="./src/test-suites/override-type-interface">override-type-interface</a>
<pre>🟢❌🟢🟢</pre>
<a href="./src/test-suites/override-with-requires">override-with-requires</a>
Expand Down Expand Up @@ -429,6 +437,8 @@ You can look at the full list of tests [here](./src/test-suites/). Every test id
<pre>🟢</pre>
<a href="./src/test-suites/non-resolvable-interface-object">non-resolvable-interface-object</a>
<pre>❌🟢❌🟢🟢🟢❌</pre>
<a href="./src/test-suites/null-keys">null-keys</a>
<pre>❌</pre>
<a href="./src/test-suites/override-type-interface">override-type-interface</a>
<pre>❌❌🟢🟢</pre>
<a href="./src/test-suites/override-with-requires">override-with-requires</a>
Expand Down Expand Up @@ -468,5 +478,5 @@ You can look at the full list of tests [here](./src/test-suites/). Every test id
<a href="./src/test-suites/union-interface-distributed">union-interface-distributed</a>
<pre>🟢🟢🟢🟢🟢🟢🟢</pre>
<a href="./src/test-suites/union-intersection">union-intersection</a>
<pre>🟢🟢❌❌🟢🟢🟢❌</pre>
<pre>🟢🟢🟢❌❌🟢❌</pre>
</details>
6 changes: 4 additions & 2 deletions gateways/apollo-gateway/results.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ node
.
non-resolvable-interface-object
.X.....
null-keys
.
override-type-interface
....
override-with-requires
Expand Down Expand Up @@ -80,6 +82,6 @@ union-intersection
........

---
Total: 170
Passed: 165
Total: 171
Passed: 166
Failed: 5
6 changes: 4 additions & 2 deletions gateways/apollo-router/results.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ node
.
non-resolvable-interface-object
.......
null-keys
.
override-type-interface
....
override-with-requires
Expand Down Expand Up @@ -80,6 +82,6 @@ union-intersection
........

---
Total: 170
Passed: 166
Total: 171
Passed: 167
Failed: 4
6 changes: 4 additions & 2 deletions gateways/cosmo-router/results.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ node
.
non-resolvable-interface-object
....X.X
null-keys
X
override-type-interface
.X..
override-with-requires
Expand Down Expand Up @@ -80,6 +82,6 @@ union-intersection
XXXXXXXX

---
Total: 170
Total: 171
Passed: 119
Failed: 51
Failed: 52
10 changes: 6 additions & 4 deletions gateways/grafbase-gateway/results.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ node
.
non-resolvable-interface-object
X.X...X
null-keys
X
override-type-interface
XX..
override-with-requires
Expand Down Expand Up @@ -77,9 +79,9 @@ unavailable-override
union-interface-distributed
.......
union-intersection
..XX...X
...XX.XX

---
Total: 170
Passed: 102
Failed: 68
Total: 171
Passed: 101
Failed: 70
2 changes: 1 addition & 1 deletion gateways/hive-gateway/install.sh
Original file line number Diff line number Diff line change
@@ -1 +1 @@
curl -sSL https://graphql-hive.com/install-gateway.sh | sh -s "1.0.9"
curl -sSL https://graphql-hive.com/install-gateway.sh | sh -s "1.3.1"
6 changes: 4 additions & 2 deletions gateways/hive-gateway/results.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ node
.
non-resolvable-interface-object
.......
null-keys
.
override-type-interface
....
override-with-requires
Expand Down Expand Up @@ -80,6 +82,6 @@ union-intersection
........

---
Total: 170
Passed: 170
Total: 171
Passed: 171
Failed: 0
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const testCases = await Promise.all(
import("./test-suites/fed1-external-extends-resolvable/index.js"),
import("./test-suites/requires-with-argument/index.js"),
import("./test-suites/keys-mashup/index.js"),
import("./test-suites/null-keys/index.js"),
].map((i) => i.then((e) => e.default)),
);

Expand Down
43 changes: 43 additions & 0 deletions src/test-suites/null-keys/a.subgraph.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { createSubgraph } from "../../subgraph.js";
import { books } from "./data.js";

export default createSubgraph("a", {
typeDefs: /* GraphQL */ `
extend schema
@link(
url: "https://specs.apollo.dev/federation/v2.3"
import: ["@key"]
)
type Query {
bookContainers: [BookContainer]
}
type BookContainer {
book: Book
}
type Book @key(fields: "upc") {
upc: ID!
}
`,
resolvers: {
Query: {
bookContainers() {
return books.map((book) => ({ book: { upc: book.upc } }));
}
},
Book: {
__resolveReference(reference: { upc: String; }) {
if (reference != null) {
let book = books.find((book) => book.upc === reference.upc);
if (book != null && book.upc !== null) {
return {
__typename: "Book",
upc: book.upc
};
}
}
throw new Error("Invalid reference");
},
}
},
});
45 changes: 45 additions & 0 deletions src/test-suites/null-keys/b.subgraph.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { createSubgraph } from "../../subgraph.js";
import { books } from "./data.js";

export default createSubgraph("b", {
typeDefs: /* GraphQL */ `
extend schema
@link(
url: "https://specs.apollo.dev/federation/v2.3"
import: ["@key"]
)
type Book @key(fields: "id") @key(fields: "upc") {
id: ID!
upc: ID!
}
`,
resolvers: {
Book: {
__resolveReference(reference: { id: String; } | { upc: String; }) {
if (reference != null) {
let book: { id: string; upc: string; } | undefined;
if ('id' in reference) {
book = books.find((book) => book.id === reference.id);
}
if ('upc' in reference) {
book = books.find((book) => book.upc === reference.upc);
}
if (book != null) {
// `a` has `Book` entities with upc: `b1, b2, b3`, but `b` has `Book` entities with only `b1` and `b2`.
// `b3` is not available and this subgraph is the only possible step to get to the other subgraph (need of `id` field) to resolve the author.
if (book.id === '3') {
return null;
}
return {
__typename: "Book",
id: book.id,
upc: book.upc
};
}
}
throw new Error("Invalid reference");
}
}
},
});
49 changes: 49 additions & 0 deletions src/test-suites/null-keys/c.subgraph.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { createSubgraph } from "../../subgraph.js";
import { books } from "./data.js";

export default createSubgraph("c", {
typeDefs: /* GraphQL */ `
extend schema
@link(
url: "https://specs.apollo.dev/federation/v2.3"
import: ["@key"]
)
type Book @key(fields: "id") {
id: ID!
author: Author
}
type Author {
id: ID!
name: String
}
`,
resolvers: {
Book: {
__resolveReference(reference: { id: String; } | { upc: String; }) {
if (reference != null) {
let book: { id: string; author: { id: string; name: string; } } | undefined;
if ('id' in reference && reference.id !== null) {
book = books.find((book) => book.id === reference.id);
}
if ('upc' in reference && reference.upc !== null) {
book = books.find((book) => book.upc === reference.upc);
}
if (book != null) {
return {
__typename: "Book",
id: book.id,
author: {
__typename: "Author",
id: book.author.id,
name: book.author.name
}
};
}
}
throw new Error("Invalid reference");
}
}
},
});
32 changes: 32 additions & 0 deletions src/test-suites/null-keys/data.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
export const books = [
{
__typename: "Book",
id: "1",
upc: "b1",
author: {
__typename: "Author",
id: "a1",
name: "Alice"
}
},
{
__typename: "Book",
id: "2",
upc: "b2",
author: {
__typename: "Author",
id: "a2",
name: "Bob"
}
},
{
__typename: "Book",
id: "3",
upc: "b3",
author: {
__typename: "Author",
id: "a3",
name: "Jack"
}
}
]
7 changes: 7 additions & 0 deletions src/test-suites/null-keys/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { serve } from "../../supergraph.js";
import a from "./a.subgraph.js";
import b from "./b.subgraph.js";
import c from "./c.subgraph.js";
import test from "./test.js";

export default serve("null-keys", [a, b, c], test);
Loading

0 comments on commit fc65104

Please sign in to comment.