Skip to content

Commit b691508

Browse files
JoviDeCroockbenjie
andcommitted
Apply suggestions from code review
Co-authored-by: Benjie <[email protected]>
1 parent 6503fd6 commit b691508

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

website/pages/_meta.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const meta = {
1717
title: 'Advanced Guides',
1818
},
1919
'constructing-types': '',
20-
'input-unions': '',
20+
'oneof-input-objects': 'OneOf input objects',
2121
'defer-stream': '',
2222
'-- 3': {
2323
type: 'separator',

website/pages/input-unions.mdx renamed to website/pages/oneof-input-objects.mdx

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
---
2-
title: Input Unions
2+
title: OneOf input objects
33
---
44

55
import { Tabs } from 'nextra/components';
66

77
Some inputs will behave differently depending on what input we choose. Let's look at the case for
88
a field named `product`, we can fetch a `Product` by either its `id` or its `name`. Currently we'd
99
make a tradeoff for this by introducing two arguments that are both nullable, now if both are passed
10-
as null we'd have to handle that in code. To fix this the `@oneOf` directive was introduced so we
11-
can create these input-unions without sacrificing the strictly typed nature of our GraphQL Schema.
10+
as null (or both non-null) we'd have to handle that in code - the type system wouldn't indicate that exactly one was required. To fix this, the `@oneOf` directive was introduced so we
11+
can create this "exactly one option" constraint without sacrificing the strictly typed nature of our GraphQL Schema.
1212

1313
<Tabs items={['SDL', 'Code']}>
1414
<Tabs.Tab>
@@ -19,13 +19,20 @@ const schema = buildSchema(`
1919
name: String!
2020
}
2121
22-
input ProductInput @oneOf {
22+
input ProductLocation {
23+
aisleNumber: Int!
24+
shelfNumber: Int!
25+
positionOnShelf: Int!
26+
}
27+
28+
input ProductSpecifier @oneOf {
2329
id: ID
2430
name: String
31+
location: ProductLocation
2532
}
2633
2734
type Query {
28-
product(input: ProductInput!): Product
35+
product(by: ProductSpecifier!): Product
2936
}
3037
`);
3138
```
@@ -69,4 +76,5 @@ const schema = new GraphQLSchema({
6976
</Tabs>
7077

7178
It doesn't matter whether you have 2 or more inputs here, all that matters is
72-
that your user will have to specify one, and only one, for this input to be valid.
79+
that your user will have to specify one, and only one, for this input to be valid.
80+
The values are not limited to scalars, lists and other input object types are also allowed.

0 commit comments

Comments
 (0)