DDave
DDave

Reputation: 1553

apollo client, query with filter

actually, all my queries have no filter, just retrieve all the records from the tables

I've read this link: https://github.com/graphql/graphql-js/issues/640

it's about building a manual filter, but the discussion doesn't end with a clear solution.

there is a way to in apollo client, to send a parameter to a query?

in mutation I use, but I have doubt about using the query

one query is by example:

query TourList {

    tours {
      id
      name
      price
      country
      seatsmax
      seatsmin
      datestart
      dateend
      organizer_id
   }
}

how to filter by organizer_id ? I'm using sequelize ...

Upvotes: 1

Views: 2882

Answers (1)

Ionut Achim
Ionut Achim

Reputation: 977

You provide the organizer_id to your resolver, through the arguments, and do the filtering there. Something like this:

query TourList {
    tours(oid: 1) {
      id
      name
      price
      ...
   }
}

// type definitions:
Query {
   tours(oid: Int): [Tour!]!
}


// tours resolver:
tours: (obj, args, ctx, info) => {
  // logic to get and return the filtered tours 
}

You can use variables the same way you are doing with your mutations

Upvotes: 1

Related Questions