Hi, is there any support for union types yet in graphql-yoga? It seems to need a resolveType 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 馃憤.
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 fragment, resolve, __resolveType and __isTypeOf:
export interface IResolverOptions {
resolve?: IFieldResolver<any, any>;
subscribe?: IFieldResolver<any, any>;
__resolveType?: GraphQLTypeResolver<any, any>;
__isTypeOf?: GraphQLIsTypeOfFn<any, any>;
}
Sorry didn鈥檛 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鈥檓 not sure. I think you have to specify how to differentiate types. I鈥檓 not sure if GraphQL actually has pattern matching to resolve the different types in a Union all on its own. I don鈥檛 think that scales for long lists.
Is there any example tackling basic union types?
@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
Who want to learn Prisma or contribute in our Project?:
We have got a ready react-native project who use prisma already setup with all techno apollo2 webpack4 react-scripts inside:
It's here
https://github.com/simonjoom/react-native-project
Read README, We are ready to hire competent and efficient developper who use prisma API CRUD in efficient way for our project
Due to inactivity of this issue we have marked it stale. It will be closed if no further activity occurs.
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 :). 馃憢
Most helpful comment
@eliperelman would you be open to adding an example via PR demonstrating how to use interfaces + unions?