-
Notifications
You must be signed in to change notification settings - Fork 571
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
How to use union types with graphql-yoga? #121
Comments
I just ran into this too... EDIT: never mind... doh. you need to provide a _resolveType function for union types less magical than I thought but at least now it's not a mystery how it determines the type lol |
@idibidiart do you mind expending on your solution? |
When you implement your resolvers, all 'standard' keys for it are available, so export interface IResolverOptions {
resolve?: IFieldResolver<any, any>;
subscribe?: IFieldResolver<any, any>;
__resolveType?: GraphQLTypeResolver<any, any>;
__isTypeOf?: GraphQLIsTypeOfFn<any, any>;
} |
Sorry didn’t see this before. I used __resolveType for efficient resolution. I assume isTypeOf is a hint field that has to be in the entity or API being queried but I’m not sure. I think you have to specify how to differentiate types. I’m not sure if GraphQL actually has pattern matching to resolve the different types in a Union all on its own. I don’t think that scales for long lists. |
Is there any example tackling basic |
@maticzav is this helpful?: |
@eliperelman this is super useful! Thanks! |
@eliperelman would you be open to adding an example via PR demonstrating how to use interfaces + unions? |
@schickling I've written a medium post covering Interfaces / Unions with Prisma & Yoga. Let me know which is the best way, if any, for me to help take parts of that and add to the docs. Also if there are any additions, clarifications, errors in my post, happy to correct things. https://medium.com/@tibotiber/graphql-interfaces-and-union-types-with-prisma-and-yoga-7224f9e1d9ad |
Thanks a lot for this great blog post @tibotiber! Would be great if you could create a PR adding an example demonstrating how to use interfaces + unions. 🙏 |
hello |
Due to inactivity of this issue we have marked it |
Hey stale bot, you happen to be right. I think we're done here as docs has been added to cover the question. Since I opened, I'll close :). 👋 |
Hi, is there any support for
union
types yet in graphql-yoga? It seems to need aresolveType
function to determine the actual type of an object at runtime. I couldn't find any place refering to supporting this so far.Taking this opportunity to express my deep admiration for the work you guys at graphcool have been doing. Amazing developer experience across the board since the release of the graphcool framework, and really excited at what the stack is becoming with native gql db + yoga as api gateway 👍.
The text was updated successfully, but these errors were encountered: