Code Monkey home page Code Monkey logo

Comments (13)

maticzav avatar maticzav commented on August 27, 2024 3

Is there any example tackling basic union types?

from graphql-yoga.

schickling avatar schickling commented on August 27, 2024 3

@eliperelman would you be open to adding an example via PR demonstrating how to use interfaces + unions?

from graphql-yoga.

simonjoom avatar simonjoom commented on August 27, 2024 3

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

from graphql-yoga.

eliperelman avatar eliperelman commented on August 27, 2024 1

@maticzav is this helpful?:

https://github.com/eliperelman/taskcluster-graphql-server/blob/679237debc15bd055e8448d71fac78c5b2df8a88/src/graphql/Tasks.graphql#L325-L331

https://github.com/eliperelman/taskcluster-graphql-server/blob/679237debc15bd055e8448d71fac78c5b2df8a88/src/resolvers/Tasks.js#L17-L36

from graphql-yoga.

tibotiber avatar tibotiber commented on August 27, 2024 1

@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

from graphql-yoga.

schickling avatar schickling commented on August 27, 2024 1

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. 🙏

from graphql-yoga.

tibotiber avatar tibotiber commented on August 27, 2024 1

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 :). 👋

from graphql-yoga.

idibidiart avatar idibidiart commented on August 27, 2024

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

from graphql-yoga.

tibotiber avatar tibotiber commented on August 27, 2024

@idibidiart do you mind expending on your solution?

from graphql-yoga.

kbrandwijk avatar kbrandwijk commented on August 27, 2024

When you implement your resolvers, all 'standard' keys for it are available, so fragment, resolve, __resolveType and __isTypeOf:

From https://github.com/apollographql/graphql-tools/blob/608414b0dfd2ff7ba8a27389e0bb8c400fb631c6/src/Interfaces.ts#L23-L28:

export interface IResolverOptions {
  resolve?: IFieldResolver<any, any>;
  subscribe?: IFieldResolver<any, any>;
  __resolveType?: GraphQLTypeResolver<any, any>;
  __isTypeOf?: GraphQLIsTypeOfFn<any, any>;
}

from graphql-yoga.

idibidiart avatar idibidiart commented on August 27, 2024

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.

from graphql-yoga.

maticzav avatar maticzav commented on August 27, 2024

@eliperelman this is super useful! Thanks!

from graphql-yoga.

stale avatar stale commented on August 27, 2024

Due to inactivity of this issue we have marked it stale. It will be closed if no further activity occurs.

from graphql-yoga.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.