-
Notifications
You must be signed in to change notification settings - Fork 1.1k
union does not allow sub-union or covariance #711
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
Comments
Unfortunately, there are not many discussions here but as for me, support of covariance is very crucial.
In the above example, we see that parent of a cow can be only a cow, not any animal.
It may be not really a good example, but I just want to show that field For better reading of this issue, I will use "anonymous" unions and will define them on the field definition
And here we have a huge issue, we cannot decrease the list of union types on the implementation. Therefore we cannot define in a schema that Wolf CANNOT be a parent for Cow It will be good to be able to have something like this:
I will appreciate any comments or suggestions on how to deal with this. |
Any news on this? This issue has been around for 4 years, with a PR during 2 years, and forbidding unions of unions create massive code duplication, possible errors, maintainability headaches, and poor readability. Consider for instance:
|
There are a few related feature requests related to expanding subtyping. A few years ago, I looked into championing some of these efforts, but quickly simply found that I hit more complexity than I had bargained for. So this work is looking for a new champion! Anyone interested in tackling it might want to take a look at https://github.com/graphql/graphql-wg/blob/main/rfcs/ExpandingSubtyping.md — where I summarized my progress and documented some potential pitfalls. Hope this helps! |
Thanks for your attempts. So after a quick look, I would (warning: non specialist here):
|
In RDF it's quite common to use subclasses, and somewhat common to use union types (eg
schema:rangeIncludes
states a field can take values from several different classes;owl:unionOf
does a similar thing).RDF is based on formal logic, so it considers classes (types) as sets. In this interpretation, it's clear how to determine subtypes (especially useful for field covariance). Eg
But the spec says:
This means that
U1, U3, U4
are not allowed, and neither of them can be used in an object type field.This creates severe limitations on what polymorphic constructs (in particular RDF constructs) can be mapped to GraphQL.
(I searched here for "union but not 'input union'" and came up only with #518 as a possibly related issue. cc @derek-miller @mavilein)
The text was updated successfully, but these errors were encountered: