-
Notifications
You must be signed in to change notification settings - Fork 41
Description
I'm getting some errors in a case where my schema has a mutation that returns a union (either the created type or validation errors).
Basically I think it would be a nice pattern to make input validation errors a part of my schema for additional type safety :)
Here's some pseudocode example (unfortunately no time to make exact reprod / can't share code from my own project)
EDIT: I added ...some fields here... below as it was causing confusion, I'm indeed not using empty GraphQL types!
schema
type Foo { ...some fields here... }
type FooValidationErrors { ...some fields here... }
union FooResult = Foo | FooValidationErrors
input FooInput {...some fields here...}
type Mutation {
createFoo(input: FooInput): FooResult
}query
mutation createFoo {
createFoo($input: FooInput) {
...on Foo {...some fields here...}
...on FooValidationErrors {...some fields here...}
}
}error:
Schema.Invalid_type("Type FooResult doesn't have any fields")
Note: I'm not having any problems using this schema with Apollo server and Apollo client. Just with graphql ppx.
Edit: I decided to alter my schema a bit and went with https://github.com/mhallin/graphql_ppx#non-union-variant-conversion