Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GraphQL multiple values eq filter

Tags:

graphql

gatsby

How do I filter multiple values in GraphQL? For example, I want both databaseID 59 and 170 to be filtered.

I've tried with 170, 59 but it returns error "Syntax Error: Expected Name, found Int \"59\"."

My GraphQL Query:

query MyQuery {
  allWpPage(filter: {databaseId: {eq: 170, 59}}) {
    nodes {
      title
      databaseId
    }
  }
}
like image 412
TurboTobias Avatar asked Sep 07 '26 17:09

TurboTobias


1 Answers

Found the answer with the help of @xadms comment.

I could use either in if I only want those ids, or nin if I want them excluded. In order to have multiple, I should pass the ids as an array

query MyQuery {
  allWpPage(filter: {databaseId: {in: [170, 59]}}) {
    nodes {
      title
      databaseId
    }
  }
}
like image 199
TurboTobias Avatar answered Sep 10 '26 15:09

TurboTobias



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!