Closed JBrVJxsc closed 4 years ago
The and
and or
parts must be used like sqlalchemy functions with arguments. The root filter combines all arguments using AND.
Let me explain with examples:
query { Foo(filters: { key_like: "%foo%", and: [{ id: "1" }] }) { id key } }
select * from foo where key like "%foo%" AND id = "1"
query { Foo(filters: { key_like: "%foo%", or: [{ id: "2" }] }) { id key } }
select * from foo where key like "%foo%" AND id = "2"
query { Foo(filters: {or: [{key_like: "%foo%"}, {"id": "2"}]}) { id key } }
select * from foo where key like "%foo%" OR id = "2"
query { Foo(filters: {or: [{key_like: "%foo%"}, {"id": "2", key_like: "%bar%"}]}) { id key } }
select * from foo where key like "%foo%" OR (id = "2" AND key like "%bar%")
got it! thank you!
So I have 2 records in schema Foo: id: 1, key: 'foo' id: 2, key: 'foobar'
if I run the below command:
query { Foo(filters: { key_like: "%foo%", and: [{ id: "1" }] }) { id key } }
it will return:{ "data": { "Foo": [ { "id": "1", "key": "foo" } ] } }
, which is expected, as both records' key like foo, but only record 1 has the id 1, so only the record 1 was returned;but if I run the below command:
query { Foo(filters: { key_like: "%foo%", or: [{ id: "2" }] }) { id key } }
it will ONLY return:{ "data": { "Foo": [ { "id": "2", "key": "foobar" } ] } }
Shouldn't both records got returned? I'm not using relay and I'm using the example code (w/o relay) you provide the other day to build the filter set.