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

feat: AND/OR query filters

Open saihaj opened this issue 3 years ago • 6 comments

Enables users to execute queries with logical operators.

Query Example:

{
  musicians(where: {OR: {name: "John", id: "m2"}}) {
    name
    id
  }
}

Question: should we limit this to only one level deep?

Closes #579

saihaj avatar Sep 14 '22 16:09 saihaj

Seeing AND when everything else is lower case feels a little strange.

In the ticket and to make it more differentiable made these logical filters uppercase. Don’t have a preference so happy to do whatever you think is the best.

saihaj avatar Sep 15 '22 03:09 saihaj

Agree with David, I think lowercase would be more in keeping. And nice work!

Can you clarify what you mean by The current implementation would resolve OR only one level deep but AND is recursively constructed. - so you could have X OR (Y AND Z), and you could have X AND (Y OR Z) but not X OR (Y OR Z)?

azf20 avatar Sep 15 '22 13:09 azf20

actually need to make it recursive for picking up OR cause if we want to even mix and match AND/OR like wouldn't work. Unless we think cause of performance reasons we don't want to allow this

{
  proposals(
    where: {OR: {name_contains_nocase: "Creating", AND: {status: WITHDRAWN}}}
  ) {
    id
    name
    contributor
    contentCID
  }
}

above query for sure can be simplified since it should really just be a simple AND which is what we implicitly do. But someone can send that and would expect results back

similarly this query would fail in current implementation but in theory user should just so all in one line

{
  proposals(
    where: {OR: {name_contains_nocase: "Creating", OR: {contentCID_in: ["0x29eeb7b4ac75dbcdcbe098e18fe6707dcc5281af"]}}}
  ) {
    id
    name
    contributor
    contentCID
  }
}

saihaj avatar Sep 15 '22 14:09 saihaj

so you could have X OR (Y AND Z), and you could have X AND (Y OR Z) but not X OR (Y OR Z)?

@azf20 updated it so it no longer is limiting. User can make as much recursively deep AND/OR filter they if they chose to do so.

there's some test failures.

@lutter fixed the schema tests

saihaj avatar Sep 15 '22 16:09 saihaj

@saihaj i think we need a rebase here, and then we are good to go in terms of code review?

dotansimha avatar Sep 19 '22 06:09 dotansimha

Quick note on rebasing: please always rebase with git rebase master <mybranch> not by merging master into the branch since that leads to funky looking merge commits.

lutter avatar Sep 22 '22 23:09 lutter

If we proceed with https://github.com/graphprotocol/graph-node/pull/4080 should we close this @saihaj ?

azf20 avatar Oct 24 '22 15:10 azf20