Giter VIP home page Giter VIP logo

Comments (2)

jmurrayrs avatar jmurrayrs commented on July 28, 2024

Hello crirus! For example, the client has this Query:

Products (id:20) {
Price,
Name,
BrandName
}

The Query will return JSON with this Fields: Price, Name and Brand Name. But if client wants only name, the Query must be:

Products (id:20) {
Name
}

The Customer/Client will choose what to return by the Query. The Application, in the resolver, must populate with data from Database/File, etc

from graphqlite.

moufmouf avatar moufmouf commented on July 28, 2024

Hey @crirus!

@jmurrayrs answer is correct. The whole purpose of GraphQL is to let you fetch exactly the fields you need. If this is not obvious to you, maybe you can take a look at the main GraphQL tutorial.

Now, I feel that you already know that and that your question is rather: "is there a way to get in advance the list of fields that I will have to resolve"?
And I also guess you are asking because your backend is a database and you would like to fetch only the columns that will be needed instead of fetching all the columns? Am I correct?

If this is what you are trying to do, we added in GraphQLite 4 a new way to access the GraphQL request.
GraphQLite is built on top of the webonyx/graphql-php. This library comes with a "ResolveInfo" object that contains information related to the requested fields.

You can now type-hint on ResolveInfo in any resolver.

See documentation here:

https://graphqlite.thecodingmachine.io/docs/next/query-plan

Please note this is only available in GraphQLite 4. It is not yet tagged stable but will be in less than a month, and I don't expect any more breaking changes, so you can start using GraphQLite 4 right now.

from graphqlite.

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.