menu

FakeQL

Get support for FakeQL, the GraphQL API mocking service.

Channels
Team

Query using OR behaves like AND

October 28, 2019 at 3:11pm

Query using OR behaves like AND

October 28, 2019 at 3:11pm (Edited 11 months ago)
Firstly, thank you for providing this service, it is both super useful and intuitive, you can go from nothing to having something that actually works in next to no time. I really appreciate it.
However I am running into a problem when using OR in my queries. I am not sure if this is my inexperience with GraphQL or an actual bug.
I have uploaded the following JSON:
{
"guests": [
{ "id": 1, "firstname": "Mike", "lastname": "John"},
{ "id": 2, "firstname": "Marvin", "lastname": "Gay"},
{ "id": 3, "firstname": "Lucy", "lastname": "Liu"},
{ "id": 4, "firstname": "James", "lastname": "Mario"},
{ "id": 5, "firstname": "Minty", "lastname": "Measles"}
]
}
When I run the following Query:
{
guests(where: {firstname_contains: "M", or: {lastname_contains: "M"}}) {
firstname
lastname
id
}
}
it returns one line only:
{
"data": {
"guests": [
{
"firstname": "Minty",
"lastname": "Measles",
"id": "5"
}
]
}
}
Although I would expect this to be the valid response if the query contained an 'AND' it does not seem right for an 'OR.' I would expect an 'OR' query to return the data for IDs 1, 2, 4 and 5 as they all have "M" in either their firstname OR their lastname.
Am I doing something wrong (entirely possible) or is this a bug? Your help is very much appreciated.

November 17, 2019 at 4:35pm
Sorry for the late reply. Just came back from the Himalayas. Root level is always AND. Move both "contains" statements into the OR clause as an array and it will work. Hasura guys explained this technic nicely, FakeQL is just leaving away the underscore: https://docs.hasura.io/1.0/graphql/manual/queries/query-filters.html#using-multiple-filters-in-the-same-query-and-or
  • reply
  • like
Fantastic, thank you for the help, appreciate it.
  • reply
  • like