-
Notifications
You must be signed in to change notification settings - Fork 38
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
GraphQL schema generation failed when using Union type #27
Comments
You're right! |
Hi team! Thank you for the awesome work on this package. I'm just wondering if there are any plans to support union types in the near future? |
Another one for Unions. Looks like it has a problem when you hit the |
Behavior-wise I think it should join all types within the union into one big filter type. Same with sort.
One can have a CharacterFiterType with both dob and makeDate StringFilter types and let mongo find the properties accordingly. For example..
In that case the query would be... I guess another way to go is to build a union filter type that in turn has the separate filter types within it so you can go...
But that seems trickier and a little excessive since the query would be the same. |
|
I use graphql-union-input-type as a union input type since GraphQL is lacking that right now. The way I am implementing it is by using the typeKey property and then filtering out by 'kind' property in my object.
Maybe something similar could be implemented here. You can error out if typeKey is not in Union. Also a CharacterKind enum can be recommended to make things simpler.
BTW my union type would look like this in this hypothetical case.
BTW for anyone confused by my code, I am using character.kind only because GraphQLUnionType doesn't support typeKey only UnionInputType does but I am adding it on here as a reference to a possible solution for this great module. |
For now and until a proper feature is implemented, the way I am solving it for my particular purpose is as follows
This diff plugin is great for vs code. This will not work for every case and people should wait until a proper feature is implemented. Basically this just combines all of the types of the union into one big filter type and it could replace or mess up things for people. I deal with conflicts between fields of the same name by just replacing fields with Object.assign. I am also adding opr exist|not exist to leaf types. This gets the job done for now. Since I am only using sort, and filter I haven't messed with projection or anything else so this only applies to sort and filter. I am sure the feature is forthcoming. |
update on this? |
If using a Union type field together with the
getMongoDbQueryResolver
GraphQL schema validation fails with the error:The text was updated successfully, but these errors were encountered: