GithubHelp home page GithubHelp logo

random incorrect response about graphql-tools HOT 6 CLOSED

bsr203 avatar bsr203 commented on April 30, 2024
random incorrect response

from graphql-tools.

Comments (6)

helfer avatar helfer commented on April 30, 2024

@bsr203 Looking just at the query and response it's really hard to tell. Can you show me the relevant part of your schema and how you're passing it to the server? Is node always a viewer? And is this using actual resolve functions, or are you using mocking?

from graphql-tools.

bsr203 avatar bsr203 commented on April 30, 2024

thanks for the quick response. I will try to get a reproducible case. Node is an interface with 9 implementations. I don't have any resolve/ custom mock function, but just the default mock by graphql-tools. Is there anything like sampling from 9 implementation? but anyway, I will try to make a reproducible case. thanks again.

from graphql-tools.

helfer avatar helfer commented on April 30, 2024

Okay, so this could be due to the mocking indeed, because if you don't have resolve functions and don't specify the mocks then it will randomly pick one of the implementing types for the interface. Since you only ask for a fragment on the Viewer type, the response will come back empty in 8 out of 9 cases, because Viewer is only one of the 9 types.

from graphql-tools.

bsr203 avatar bsr203 commented on April 30, 2024

so, is it feasible to identify the fragment type and mock appropriately by graphql-tools, or it should be the responsibility of the user to provide a resolve function? Do you have any rough sketch or any example/test case to point to. thanks again.

from graphql-tools.

helfer avatar helfer commented on April 30, 2024

I think looking into fragments to decide what interface gets mocked would make things a bit more complicated, but it shouldn't be too hard to do. One thing to keep in mind however is that what you're getting right now is a completely valid GraphQL response, so your program should be able to deal with it.
If you want to mock only a certain type of the interface, one way to go about it would be to specify the node mock and return an object with { typename: "Viewer"}. I'm not 100% sure, but believe that would give you what you want.

You can find a test case in the test folder, just search for interface. The actual implementation is in mock.js

from graphql-tools.

bsr203 avatar bsr203 commented on April 30, 2024

thank you. I will close this now, as you said, it is a valid response. Will try out the options you suggested and get back with you. thanks again.

from graphql-tools.

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.