Skip to content

Circular requires audit #134

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ This repository contains a set of tests to evaluate and compare the compatibilit

<!-- gateways:start -->

| Gateway | Compatibility | Test Cases | Test Suites |
| :-------------------------------------------------------------: | :-----------: | :----------: | :---------: |
| [Hive Gateway](https://the-guild.dev/graphql/hive/docs/gateway) | 100.00% | 🟢 187 | 🟢 41 |
| [Apollo Router](https://www.apollographql.com/) | 97.86% | 🟢 183 ❌ 4 | 🟢 39 ❌ 2 |
| [Apollo Gateway](https://www.apollographql.com/) | 97.33% | 🟢 182 ❌ 5 | 🟢 38 ❌ 3 |
| [Cosmo Router](https://wundergraph.com) | 95.19% | 🟢 178 ❌ 9 | 🟢 36 ❌ 5 |
| [Grafbase Gateway](https://grafbase.com) | 90.91% | 🟢 170 ❌ 17 | 🟢 35 ❌ 6 |
| [Inigo Gateway](https://inigo.io) | 48.66% | 🟢 91 ❌ 96 | 🟢 12 ❌ 29 |
| Gateway | Compatibility | Test Cases | Test Suites |
| :--------------------------------------------------------: | :-----------: | :----------: | :---------: |
| [Hive Gateway](https://the-guild.dev/graphql/hive/gateway) | 98.94% | 🟢 187 ❌ 2 | 🟢 41 ❌ 1 |
| [Apollo Router](https://www.apollographql.com/) | 97.88% | 🟢 185 ❌ 4 | 🟢 40 ❌ 2 |
| [Apollo Gateway](https://www.apollographql.com/) | 97.35% | 🟢 184 ❌ 5 | 🟢 39 ❌ 3 |
| [Cosmo Router](https://wundergraph.com) | 95.24% | 🟢 180 ❌ 9 | 🟢 37 ❌ 5 |
| [Grafbase Gateway](https://grafbase.com) | 91.01% | 🟢 172 ❌ 17 | 🟢 36 ❌ 6 |
| [Inigo Gateway](https://inigo.io) | 48.15% | 🟢 91 ❌ 98 | 🟢 12 ❌ 30 |

<!-- gateways:end -->

Expand Down
30 changes: 21 additions & 9 deletions REPORT.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

## Summary

| Gateway | Compatibility | Test Cases | Test Suites |
| :-------------------------------------------------------------: | :-----------: | :----------: | :---------: |
| [Hive Gateway](https://the-guild.dev/graphql/hive/docs/gateway) | 100.00% | 🟢 187 | 🟢 41 |
| [Apollo Router](https://www.apollographql.com/) | 97.86% | 🟢 183 ❌ 4 | 🟢 39 ❌ 2 |
| [Apollo Gateway](https://www.apollographql.com/) | 97.33% | 🟢 182 ❌ 5 | 🟢 38 ❌ 3 |
| [Cosmo Router](https://wundergraph.com) | 95.19% | 🟢 178 ❌ 9 | 🟢 36 ❌ 5 |
| [Grafbase Gateway](https://grafbase.com) | 90.91% | 🟢 170 ❌ 17 | 🟢 35 ❌ 6 |
| [Inigo Gateway](https://inigo.io) | 48.66% | 🟢 91 ❌ 96 | 🟢 12 ❌ 29 |
| Gateway | Compatibility | Test Cases | Test Suites |
| :--------------------------------------------------------: | :-----------: | :----------: | :---------: |
| [Hive Gateway](https://the-guild.dev/graphql/hive/gateway) | 98.94% | 🟢 187 ❌ 2 | 🟢 41 ❌ 1 |
| [Apollo Router](https://www.apollographql.com/) | 97.88% | 🟢 185 ❌ 4 | 🟢 40 ❌ 2 |
| [Apollo Gateway](https://www.apollographql.com/) | 97.35% | 🟢 184 ❌ 5 | 🟢 39 ❌ 3 |
| [Cosmo Router](https://wundergraph.com) | 95.24% | 🟢 180 ❌ 9 | 🟢 37 ❌ 5 |
| [Grafbase Gateway](https://grafbase.com) | 91.01% | 🟢 172 ❌ 17 | 🟢 36 ❌ 6 |
| [Inigo Gateway](https://inigo.io) | 48.15% | 🟢 91 ❌ 98 | 🟢 12 ❌ 30 |

## Detailed Results

Expand All @@ -22,7 +22,7 @@ You can look at the full list of tests [here](./src/test-suites/). Every test id
### Hive Gateway

- [Repository](https://github.com/graphql-hive/gateway)
- [Website](https://the-guild.dev/graphql/hive/docs/gateway)
- [Website](https://the-guild.dev/graphql/hive/gateway)

<details>
<summary>Results</summary>
Expand Down Expand Up @@ -80,6 +80,8 @@ You can look at the full list of tests [here](./src/test-suites/). Every test id
<pre>🟢🟢</pre>
<a href="./src/test-suites/provides-on-union">provides-on-union</a>
<pre>🟢🟢</pre>
<a href="./src/test-suites/requires-circular">requires-circular</a>
<pre>❌❌</pre>
<a href="./src/test-suites/requires-interface">requires-interface</a>
<pre>🟢🟢🟢🟢🟢</pre>
<a href="./src/test-suites/requires-requires">requires-requires</a>
Expand Down Expand Up @@ -173,6 +175,8 @@ You can look at the full list of tests [here](./src/test-suites/). Every test id
<pre>🟢🟢</pre>
<a href="./src/test-suites/provides-on-union">provides-on-union</a>
<pre>🟢🟢</pre>
<a href="./src/test-suites/requires-circular">requires-circular</a>
<pre>🟢🟢</pre>
<a href="./src/test-suites/requires-interface">requires-interface</a>
<pre>🟢🟢🟢🟢🟢</pre>
<a href="./src/test-suites/requires-requires">requires-requires</a>
Expand Down Expand Up @@ -266,6 +270,8 @@ You can look at the full list of tests [here](./src/test-suites/). Every test id
<pre>🟢🟢</pre>
<a href="./src/test-suites/provides-on-union">provides-on-union</a>
<pre>🟢🟢</pre>
<a href="./src/test-suites/requires-circular">requires-circular</a>
<pre>🟢🟢</pre>
<a href="./src/test-suites/requires-interface">requires-interface</a>
<pre>🟢🟢🟢🟢🟢</pre>
<a href="./src/test-suites/requires-requires">requires-requires</a>
Expand Down Expand Up @@ -359,6 +365,8 @@ You can look at the full list of tests [here](./src/test-suites/). Every test id
<pre>❌❌</pre>
<a href="./src/test-suites/provides-on-union">provides-on-union</a>
<pre>❌❌</pre>
<a href="./src/test-suites/requires-circular">requires-circular</a>
<pre>🟢🟢</pre>
<a href="./src/test-suites/requires-interface">requires-interface</a>
<pre>🟢🟢🟢🟢🟢</pre>
<a href="./src/test-suites/requires-requires">requires-requires</a>
Expand Down Expand Up @@ -452,6 +460,8 @@ You can look at the full list of tests [here](./src/test-suites/). Every test id
<pre>❌❌</pre>
<a href="./src/test-suites/provides-on-union">provides-on-union</a>
<pre>🟢❌</pre>
<a href="./src/test-suites/requires-circular">requires-circular</a>
<pre>🟢🟢</pre>
<a href="./src/test-suites/requires-interface">requires-interface</a>
<pre>🟢🟢🟢🟢🟢</pre>
<a href="./src/test-suites/requires-requires">requires-requires</a>
Expand Down Expand Up @@ -545,6 +555,8 @@ You can look at the full list of tests [here](./src/test-suites/). Every test id
<pre>❌❌</pre>
<a href="./src/test-suites/provides-on-union">provides-on-union</a>
<pre>❌❌</pre>
<a href="./src/test-suites/requires-circular">requires-circular</a>
<pre>❌❌</pre>
<a href="./src/test-suites/requires-interface">requires-interface</a>
<pre>❌❌❌❌❌</pre>
<a href="./src/test-suites/requires-requires">requires-requires</a>
Expand Down
6 changes: 4 additions & 2 deletions gateways/apollo-gateway/results.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ provides-on-interface
..
provides-on-union
..
requires-circular
..
requires-interface
.....
requires-requires
Expand Down Expand Up @@ -82,6 +84,6 @@ union-intersection
............

---
Total: 187
Passed: 182
Total: 189
Passed: 184
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 @@ -52,6 +52,8 @@ provides-on-interface
..
provides-on-union
..
requires-circular
..
requires-interface
.....
requires-requires
Expand Down Expand Up @@ -82,6 +84,6 @@ union-intersection
............

---
Total: 187
Passed: 183
Total: 189
Passed: 185
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 @@ -52,6 +52,8 @@ provides-on-interface
XX
provides-on-union
XX
requires-circular
..
requires-interface
.....
requires-requires
Expand Down Expand Up @@ -82,6 +84,6 @@ union-intersection
............

---
Total: 187
Passed: 178
Total: 189
Passed: 180
Failed: 9
6 changes: 4 additions & 2 deletions gateways/grafbase-gateway/results.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ provides-on-interface
XX
provides-on-union
.X
requires-circular
..
requires-interface
.....
requires-requires
Expand Down Expand Up @@ -82,6 +84,6 @@ union-intersection
........X..X

---
Total: 187
Passed: 170
Total: 189
Passed: 172
Failed: 17
2 changes: 1 addition & 1 deletion gateways/hive-gateway/gateway.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "Hive Gateway",
"repository": "https://github.com/graphql-hive/gateway",
"website": "https://the-guild.dev/graphql/hive/docs/gateway",
"website": "https://the-guild.dev/graphql/hive/gateway",
"graphql": "http://127.0.0.1:4000/graphql",
"health": "http://127.0.0.1:4000/healthcheck"
}
6 changes: 4 additions & 2 deletions gateways/hive-gateway/results.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ provides-on-interface
..
provides-on-union
..
requires-circular
XX
requires-interface
.....
requires-requires
Expand Down Expand Up @@ -82,6 +84,6 @@ union-intersection
............

---
Total: 187
Total: 189
Passed: 187
Failed: 0
Failed: 2
6 changes: 4 additions & 2 deletions gateways/inigo-gateway/results.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ provides-on-interface
XX
provides-on-union
XX
requires-circular
XX
requires-interface
XXXXX
requires-requires
Expand Down Expand Up @@ -82,6 +84,6 @@ union-intersection
XXXXXXXXX.XX

---
Total: 187
Total: 189
Passed: 91
Failed: 96
Failed: 98
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ async function getTestCases(router: ReturnType<typeof createRouter>) {
import("./test-suites/requires-with-argument/index.js"),
import("./test-suites/keys-mashup/index.js"),
import("./test-suites/null-keys/index.js"),
import("./test-suites/requires-circular/index.js"),
].map((i) => i.then((e) => e.default))
);

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

export default createSubgraph("a", {
typeDefs: /* GraphQL */ `
extend schema
@link(
url: "https://specs.apollo.dev/federation/v2.3"
import: ["@key", "@external", "@requires"]
)

type Query {
feed: [Post]
}

type Post @key(fields: "id") {
id: ID!
byNovice: Boolean! @external
byExpert: Boolean! @requires(fields: "byNovice")
}

type Author @key(fields: "id") {
id: ID!
name: String!
yearsOfExperience: Int!
}
`,
resolvers: {
Query: {
feed() {
return posts.map((post) => ({ id: post.id }));
},
},
Post: {
__resolveReference(ref: { id: string; byNovice?: boolean }) {
const post = posts.find((post) => post.id === ref.id);
if (!post) {
return null;
}
if (ref.byNovice == null) {
return {
id: post.id,
};
}
return {
id: post.id,
byNovice: ref.byNovice,
};
},
byExpert(post: { byNovice: boolean }) {
if (post.byNovice == null) {
// ensuring requires is not skipped
return null;
}
return !post.byNovice;
},
},
Author: {
__resolveReference(ref: { id: string }) {
const author = authors.find((author) => author.id === ref.id);
if (!author) {
return null;
}
return {
id: author.id,
name: author.name,
yearsOfExperience: author.yearsOfExperience,
};
},
},
},
});
46 changes: 46 additions & 0 deletions src/test-suites/requires-circular/b.subgraph.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { createSubgraph } from "../../subgraph.js";
import { posts } from "./data.js";

export default createSubgraph("b", {
typeDefs: /* GraphQL */ `
extend schema
@link(
url: "https://specs.apollo.dev/federation/v2.3"
import: ["@key", "@external", "@requires"]
)

type Post @key(fields: "id") {
id: ID!
author: Author!
byNovice: Boolean! @requires(fields: "author { yearsOfExperience }")
}

type Author @key(fields: "id") {
id: ID!
yearsOfExperience: Int! @external
}
`,
resolvers: {
Post: {
__resolveReference(ref: {
id: string;
author?: { yearsOfExperience: number };
}) {
const post = posts.find((post) => post.id === ref.id);
if (!post) {
return null;
}
return {
id: post.id,
author: {
id: post.author.id,
...ref.author,
},
};
},
byNovice(post: { author: { yearsOfExperience: number } }) {
return post.author.yearsOfExperience < 10;
},
},
},
});
25 changes: 25 additions & 0 deletions src/test-suites/requires-circular/data.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
export const authors = [
{
id: "a1",
name: "John",
yearsOfExperience: 5,
},
{
id: "a2",
name: "Jane",
yearsOfExperience: 20,
},
];

export const posts = [
{
id: "p1",
body: "p1-body",
author: authors[0],
},
{
id: "p2",
body: "p2-body",
author: authors[1],
},
];
6 changes: 6 additions & 0 deletions src/test-suites/requires-circular/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { serve } from "../../supergraph.js";
import a from "./a.subgraph.js";
import b from "./b.subgraph.js";
import test from "./test.js";

export default serve("requires-circular", [a, b], test);
Loading
Loading