Skip to content

Commit aa90b7d

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

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

website/pages/input-unions.mdx

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import { Tabs } from 'nextra/components';
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)