If I do:
union Question = QuestionMultipleChoice | QuestionText | QuestionNumber
union NewQuestionResult = Question | WrongToken
I get an error Union type NewQuestionResult can only include Object types, it cannot include Question.
, while:
union Question = QuestionMultipleChoice | QuestionText | QuestionNumber
union NewQuestionResult = QuestionMultipleChoice | QuestionText | QuestionNumber | WrongToken
works… But this leads to 2 questions:
- why on earth would one fordid Unions of Unions? ML languages have been doing this for years without any issue.
- how can I avoid the very dangerous code duplication it creates? Here I just have 2 lines to maintain, but I will surely run into troubles if for any single function that may return a
Question
or some errors I need to create a new line. The schema will be impossible to maintain in a few days!
MWE:
type QuestionMultipleChoice {
question: String
nbChoices: Int!
}
type QuestionText {
question: String
}
type QuestionNumber {
question: String
}
type WrongToken {
_: Boolean
}
union Question = QuestionMultipleChoice | QuestionText | QuestionNumber
union NewQuestionResult = Question | WrongToken
type Mutation {
newQuestion: NewQuestionResult
}
type Query {
hello: String
}