Coder Social home page Coder Social logo

Comments (1)

JoviDeCroock avatar JoviDeCroock commented on September 1, 2024

Hey,

I am personally a bit on the ropes whether that would work out for several reasons, the resolveType is dependent on the users implementation, this means that that function could be relying on context or properties on the object that are later stripped out as they aren't queried by the request-document.

A more reliable way of finding out what types is returned between the client and server is by adding the __typename selection which in your example will amount to { title: "Is it user or post", __typename: "Post" }. A lot of GraphQL clients also add this selection and then remove it from the response object before returning it to the user.

Another alternative if you really don't want to touch the GraphQL client document would be to do something like heuristic fragment matching, on a union type as you suggest the request document will look like

... on User { name }
... on Post { title }

You can go over the selections of these fragments and see which ones match, this is a heuristic approximation but should generally work well if you have access to the server-side schema to know the difference between the interface and object definitions.

from graphql-js.

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.