-
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.
Simple input object intersection (#7)
- Loading branch information
1 parent
898cbb0
commit caa224e
Showing
7 changed files
with
171 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
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,47 @@ | ||
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: ["@key", "@shareable"] | ||
) | ||
input UsersFilter { | ||
first: Int! | ||
} | ||
type User @key(fields: "id") { | ||
id: ID! | ||
name: String! @shareable | ||
} | ||
type Query { | ||
usersInA(filter: UsersFilter!): [User!] | ||
} | ||
`, | ||
resolvers: { | ||
Query: { | ||
usersInA(_: {}, { filter }: { filter: { first: number } }) { | ||
if ("offset" in filter) { | ||
return []; | ||
} | ||
|
||
return users; | ||
}, | ||
}, | ||
User: { | ||
__resolveReference(key: { id: string }) { | ||
const user = users.find((user) => user.id === key.id); | ||
|
||
if (!user) { | ||
return null; | ||
} | ||
|
||
return user; | ||
}, | ||
}, | ||
}, | ||
}); |
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,51 @@ | ||
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: ["@key", "@shareable"] | ||
) | ||
input UsersFilter { | ||
offset: Int | ||
first: Int! | ||
} | ||
type User @key(fields: "id") { | ||
id: ID! | ||
name: String! @shareable | ||
} | ||
type Query { | ||
usersInB(filter: UsersFilter!): [User!] | ||
} | ||
`, | ||
resolvers: { | ||
Query: { | ||
usersInB( | ||
_: {}, | ||
{ filter }: { filter: { offset?: number; first: number } } | ||
) { | ||
if (typeof filter.offset !== "undefined") { | ||
return []; | ||
} | ||
|
||
return users; | ||
}, | ||
}, | ||
User: { | ||
__resolveReference(key: { id: string }) { | ||
const user = users.find((user) => user.id === key.id); | ||
|
||
if (!user) { | ||
return null; | ||
} | ||
|
||
return user; | ||
}, | ||
}, | ||
}, | ||
}); |
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,10 @@ | ||
export const users = [ | ||
{ | ||
id: "u1", | ||
name: "u1-name", | ||
}, | ||
{ | ||
id: "u2", | ||
name: "u2-name", | ||
}, | ||
]; |
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("input-object-intersection", [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,49 @@ | ||
import { createTest } from "../../test"; | ||
|
||
export default [ | ||
createTest( | ||
/* GraphQL */ ` | ||
query { | ||
usersInA(filter: { first: 1 }) { | ||
id | ||
} | ||
} | ||
`, | ||
{ | ||
data: { | ||
usersInA: [ | ||
{ | ||
id: "u1", | ||
}, | ||
{ | ||
id: "u2", | ||
}, | ||
], | ||
}, | ||
} | ||
), | ||
createTest( | ||
/* GraphQL */ ` | ||
query { | ||
usersInA(filter: { first: 1, offset: 2 }) { | ||
id | ||
} | ||
} | ||
`, | ||
{ | ||
errors: true, | ||
} | ||
), | ||
createTest( | ||
/* GraphQL */ ` | ||
query { | ||
usersInB(filter: { first: 1, offset: 2 }) { | ||
id | ||
} | ||
} | ||
`, | ||
{ | ||
errors: true, | ||
} | ||
), | ||
]; |