-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unions are not supported for mutation return query type? #74
Comments
I think the problem is your schema which is not valid. As far as I know, you cannot have empty objects or scalar unions. You have no fields in The following example which is almost the same as yours would be valid. Schema: type Foo {
id: String!
name: String!
}
enum UserValidationError {
SomeError
}
type UserValidationErrors {
errors: [SomeError!]!
}
union FooResult = Foo | FooValidationErrors
input FooInput {
name: String
}
type Mutation {
createFoo(input: FooInput): FooResult
} Query: mutation createFoo($input: FooInput) {
createFoo(input: $input) {
...on Foo {
id # at least one field required
}
...on FooValidationErrors {
errors
}
}
} |
@elnygren As you mentioned, the best approach would be to use Can this issue be closed? |
@baransu ah my example was a bit short...
This is incorrect, I was just lazy and left them out... (I've fixed this now in the original post). So in other words: the error happens with a valid schema as I described. |
Could you provide example? Error message says: FooResult doesn’t have any fields so I’m curious 🤔 |
I'm getting some errors in a case where my schema has a
mutation
that returns aunion
(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
query
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
The text was updated successfully, but these errors were encountered: