-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Kamil Kisiela <[email protected]>
- Loading branch information
1 parent
c1a0fe0
commit fc65104
Showing
16 changed files
with
282 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
}, | ||
} | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
} | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
} | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
Oops, something went wrong.