Skip to content
This repository has been archived by the owner on Dec 19, 2023. It is now read-only.

Error if union type has same property with different nullability in two types #347

Closed
yonigibbs opened this issue Feb 21, 2020 · 2 comments

Comments

@yonigibbs
Copy link

Hi! I seem to be hitting an issue where I have a union type, and two of the types in that union share a common field, with different nullability. For example:

type Size {
    height: Int!
    weight: Int!
}

type Cat {
    name: String!
    size: Size!         # `size` is REQUIRED on `Cat`
}

type Mouse {
    name: String!
    size: Size         # `size` is OPTIONAL on `Mouse`
}

When I query for this, the error I get is:

java.lang.IllegalStateException: Validation error of type FieldsConflict: size: fields have different nullability shapes @ 'animals'

Is there something I should be configuring to get around this? Or is this a bug?

There is a repo where this can be reproduced here: https://github.com/yonigibbs/graphql-union-type

Thanks!

@oliemansm
Copy link
Member

This isn't a problem of this library. Instead it appears to be an intended check by graphql-java: https://github.com/graphql-java/graphql-java/blob/2e1e9897030f61a6e9a2c2eba358fd87da1d20d0/src/main/java/graphql/validation/rules/OverlappingFieldsCanBeMerged.java#L178.

Haven't checked the GraphQL specification, but if according the specification this should be allowed you could raise an issue in the graphql-java project.

@yonigibbs
Copy link
Author

Thanks @oliemansm. Did a bit more digging to see if this is allowed in the schema and found this very similar issue: graphql/graphql-js#1361. There's some discussion there, and a workaround in the first response.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants