Skip to content

Commit dca1655

Browse files
authored
Update InputUnion.md (#705)
1 parent 6671989 commit dca1655

File tree

1 file changed

+15
-44
lines changed

1 file changed

+15
-44
lines changed

rfcs/InputUnion.md

Lines changed: 15 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -455,68 +455,35 @@ The mechanism for configuring the discriminator field is open to debate, in this
455455

456456
### 🎲 Variations
457457

458-
* Value is the input's type name
459-
460-
```graphql
461-
input CatInput {
462-
kind: CatInput
463-
name: String!
464-
age: Int
465-
livesLeft: Int
466-
}
467-
input DogInput {
468-
kind: DogInput
469-
name: String!
470-
age: Int
471-
breed: DogBreed
472-
}
473-
474-
inputunion AnimalInput @discriminator(field: "kind") =
475-
| CatInput
476-
| DogInput
477-
478-
type Mutation {
479-
logAnimalDropOff(location: String, animals: [AnimalInput!]!): Int
480-
}
481-
482-
# Variables:
483-
{
484-
location: "Portland, OR",
485-
animals: [
486-
{
487-
kind: "CatInput",
488-
name: "Buster",
489-
livesLeft: 7
490-
}
491-
]
492-
}
493-
```
494-
495458
* Value is a `Enum` literal
496459

497460
This variation is derived from discussions in https://github.com/graphql/graphql-spec/issues/488
498461

499462
```graphql
500-
enum AnimalKind {
463+
enum AnimalSpecies {
501464
CAT
502465
DOG
503466
}
504467

505468
input CatInput {
506-
kind: AnimalKind::CAT
469+
species: AnimalSpecies::CAT
507470
# ...
508471
}
509472
input DogInput {
510-
kind: AnimalKind::DOG
473+
species: AnimalSpecies::DOG
511474
# ...
512475
}
513476

477+
inputunion AnimalInput @discriminator(field: "species") =
478+
| CatInput
479+
| DogInput
480+
514481
# Variables:
515482
{
516483
location: "Portland, OR",
517484
animals: [
518485
{
519-
kind: "CAT",
486+
species: "CAT",
520487
name: "Buster",
521488
livesLeft: 7
522489
}
@@ -528,20 +495,24 @@ input DogInput {
528495

529496
```graphql
530497
input CatInput {
531-
kind: "cat"
498+
species: "Cat"
532499
# ...
533500
}
534501
input DogInput {
535-
kind: "dog"
502+
species: "Dog"
536503
# ...
537504
}
538505

506+
inputunion AnimalInput @discriminator(field: "species") =
507+
| CatInput
508+
| DogInput
509+
539510
# Variables:
540511
{
541512
location: "Portland, OR",
542513
animals: [
543514
{
544-
kind: "cat",
515+
species: "Cat",
545516
name: "Buster",
546517
livesLeft: 7
547518
}

0 commit comments

Comments
 (0)