GraphQL search OR operator

Viewed 950

I'd like to do some search on GraphQL base on different columns, for example, if a string is equal to the first name or the last name.

I would like to be able to do something like that:

{
  clients(where: {or: [{firstName_contains: "example"}, {lastName_contains: "example"}]}){
    id
    firstName
    lastName
    phone
  }
}

Or if there is a way to do an aggregation on multiple where.

The api is built on Strapi JS, but the queries should be standard.

System:

  1. Node.js version: 10.13.0
  2. NPM version: 6.12.0
  3. Strapi version: 3.0.0-beta.17.1
  4. Database: SQLite
  5. Operating system: Ubuntu

Thanks for your help.

1 Answers

You can use _or. Refer the documentation here .Though the reference documentation is for Hausra but the syntax works for Strapi( tested for v 3.4.1) as well.

{
  clients(where: {_or: [{firstName_contains: "example"}, {lastName_contains: "example"}]}){
    id
    firstName
    lastName
    phone
  }
}
Related