-
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.
- Loading branch information
1 parent
16297eb
commit 5091afb
Showing
6 changed files
with
129 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { createSubgraph } from "../../subgraph"; | ||
import { users } from "./data"; | ||
|
||
export default createSubgraph("a", { | ||
typeDefs: /* GraphQL */ ` | ||
extend schema | ||
@link( | ||
url: "https://specs.apollo.dev/federation/v2.3" | ||
import: ["@shareable"] | ||
) | ||
type User { | ||
id: ID @shareable | ||
} | ||
type Query { | ||
users: [User!]! | ||
} | ||
`, | ||
resolvers: { | ||
Query: { | ||
users() { | ||
return users.map((u) => ({ __typename: "User", id: u.id })); | ||
}, | ||
}, | ||
}, | ||
}); |
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,44 @@ | ||
import { createSubgraph } from "../../subgraph"; | ||
|
||
import { users } from "./data"; | ||
|
||
export default createSubgraph("b", { | ||
typeDefs: /* GraphQL */ ` | ||
extend schema | ||
@link( | ||
url: "https://specs.apollo.dev/federation/v2.3" | ||
import: ["@shareable", "@key"] | ||
) | ||
union Account = User | Admin | ||
type User @key(fields: "id") { | ||
id: ID! | ||
name: String | ||
} | ||
type Admin { | ||
id: ID | ||
photo: String @shareable | ||
} | ||
type Query { | ||
accounts: [Account!]! | ||
} | ||
`, | ||
resolvers: { | ||
Query: { | ||
accounts() { | ||
return [ | ||
...users.map((user) => ({ __typename: "User", ...user })), | ||
{ __typename: "Admin", id: "a1", photo: "a1-photo" }, | ||
]; | ||
}, | ||
}, | ||
User: { | ||
__resolveReference(key: { id: string }) { | ||
return users.find((user) => user.id === key.id); | ||
}, | ||
}, | ||
}, | ||
}); |
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,6 @@ | ||
export const users = [ | ||
{ | ||
id: "n1", | ||
name: "n1-profile", | ||
}, | ||
]; |
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,6 @@ | ||
import { serve } from "../../supergraph"; | ||
import a from "./a.subgraph"; | ||
import b from "./b.subgraph"; | ||
import test from "./test"; | ||
|
||
export default serve("entity-and-no-entity", [a, b], test); |
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,44 @@ | ||
import { createTest } from "../../test"; | ||
|
||
export default [ | ||
createTest( | ||
/* GraphQL */ ` | ||
query { | ||
users { | ||
id | ||
name | ||
} | ||
accounts { | ||
... on User { | ||
id | ||
name | ||
} | ||
... on Admin { | ||
id | ||
photo | ||
} | ||
} | ||
} | ||
`, | ||
{ | ||
data: { | ||
users: [ | ||
{ | ||
id: "n1", | ||
name: "n1-profile", | ||
}, | ||
], | ||
accounts: [ | ||
{ | ||
id: "n1", | ||
name: "n1-profile", | ||
}, | ||
{ | ||
id: "a1", | ||
photo: "a1-photo", | ||
}, | ||
], | ||
}, | ||
} | ||
), | ||
]; |