Is it possible to use union types for ArgsType() ?
@InputType()
class TestA {
@Field() testa: string;
}
@InputType()
class TestB {
@Field() testb: string;
}
@InputType()
class TestC {
@Field() testc: string;
}
const UnionType = createUnionType({
name: "UnionType",
types: [TestA,TestB, TestC];
})
@ArgsType()
class UpdateArgs {
@Field(() => [UnionType], {nullable: true})
tests: Array<TestA|TestB|TestC>;
}
i tried it this way but i receive an "cannot determine graphql input type for tests"
Thank you :-)
No, this is not supported by GraphQL spec. Unions are output types and can't be used in args or inputs.
Hmmm... but how would you accept args/inputs that are an array of different types? Any recommendation?
input MyInput {
one: OneInput
two: TwoInput
three: ThreeInput
}
And in runtime you check which field is filled.
No my goal is:
Array
so the array consists of different types with an unknown amount.
one possible way would be:
input Input {
string: StringInput[],
date: DateInput[],
time: TimeInpiut[]
}
But this would break my structure because i don't have the origin sorting anymore...
So you have to make an RFC to the GraphQL spec with a proposed change or switch to REST. Sorry 馃槙
Ok i change my structure to this:
inputs: {
string: [{_id: 123, }, ...],
date: [....],
}
sorting: [
"123",
....
]
Thank you for your help
Most helpful comment
For anyone who comes to this issue looking for Union Input Types, there is an RFC in the GraphQL spec at the moment, and the issue has been discussed several times there.