graph-node icon indicating copy to clipboard operation
graph-node copied to clipboard

Expose AND and OR logical operators in GraphQL query filters

Open fordN opened this issue 6 years ago • 3 comments

Where filters should allow AND and OR logical operators to combine and nest conditions in the GraphQL queries.

fordN avatar Nov 16 '18 16:11 fordN

The way this was initially intended to look like was:

{
  users(where:
    # implicit AND at the top level
    {
      name_startsWith: "A",
      OR: {
        name_endsWith: "c",
        name_endsWith: "d",
        AND: {
          name_contains: "o",
          name_contains: "i",
        }
      }
    }
  ) {
    ...
  }
}

The above would return all users whose names start with "A" and either

  • ends with "c"
  • ends with "d"
  • contains an "o" and an "i"

Open questions:

  • Is this a good design? (How do others do it?)
  • Do we want to enforce a limit on the depth? (1-2-3 levels?)

Jannis avatar Nov 16 '21 12:11 Jannis

I'd also like this, especially because I cannot match null using *_in:

query  {
        erc721Tokens(
            orderBy: identifier,
            orderDirection: asc,
            where: {hat_in:["Bucket", "Cowboy"]}
        ) {
            identifier
            owner {
                id
            }
        }
}

What I really need is matching where Bucket || Cowboy || null.

I think this would be intuitive, especially since both hat_in:["Bucket", "Cowboy"] and hat:null work as expected when ran individually:

query  {
        erc721Tokens(
            orderBy: identifier,
            orderDirection: asc,
            where: {hat_in:["Bucket", "Cowboy"] OR hat:null}
        ) {
            identifier
            owner {
                id
            }
        }
}

montanaflynn avatar Mar 04 '22 17:03 montanaflynn

Is this supposed to only work on the same field or can we combine multiple fields like:

where: {hat_in: ["bucket", "Cowboy"] OR shoe: "46"}

compojoom avatar Jul 04 '22 20:07 compojoom

https://github.com/graphprotocol/graph-node/pull/4080

saihaj avatar Nov 10 '22 02:11 saihaj