remorses / genql

Type safe TypeScript client for any GraphQL API
https://genql.dev
MIT License
881 stars 37 forks source link

query based on condition of a field value #175

Open zmzlois opened 5 months ago

zmzlois commented 5 months ago

The whole flow of setting up and using it was super convenient! Thank you so much for creating the project!

Wondering if it is possible to create conditional query based on a field's condition?

For example right now I have a query looks like:

const gql = await client1()

    return gql.query({
        templates: {
            __args: { recommended: true, first: 10 },
            __scalar: true,
            edges: {
                node: {
                    __scalar: true,
                    metadata: {
                        activeProjects: true, // type number
                }
            }

        }
    })

I want to limit the query to only query the templates that has activeProjects more than 50, is there any way I can achieve this?

some example usage like

metadata: {

                        activeProjects.gt: 50,  // query all activeProjects has number greater than 50
                }
linear[bot] commented 5 months ago

GEN-30 query based on condition of a field value

remorses commented 5 months ago

If your backend API supports this you can filter in the __args object, or you can filter on the returned results

zmzlois commented 5 months ago

Unfortunately for this particular API I have no control over the backend, right now I am opting for filtering the returned results

zmzlois commented 5 months ago

If I make a PR for this will this be merged or this is just isn't a feature you'd like to support? @remorses

remorses commented 5 months ago

No, just filter the returned data