Motivation
Extend support for IN
filter in GraphQL
which will take a List
of arguments as Input.
User Impact
Users will now be able to apply the eq
filter smoothly on a list of values instead of clubbing every scalar value with or
filter which is not a very intuitive way to do that.
Introduction
Current Scenario
For the given type State
having @id
directive at the field code
:
type State {
code: String! @id
name: String!
capital: String
}
Suppose we want to query States having either code
= abc
or def
, then the corresponding GraphQL
query is:
query {
queryState(filter: {code: {eq: "abc"}, or: {code: {eq: "def"}}}){
code
name
}
}
which is equivalent to the following DQL
query:
query {
queryState(func: type(State)) @filter((eq(State.code, "abc") OR eq(State.code, "def"))) {
code : State.code
name : State.name
dgraph.uid : uid
}
}
GraphQL Query with IN filter
We wish to support an alternative way to do this which would be an easy approach to apply a filter for the list of values. The GraphQL
query for doing this with IN
filter would be:
query {
queryState(filter: {code: {in : ["abc", "def"]}}){
code
name
}
}
which would be equivalent to the following Dgraph Query
:
query {
queryState(func: type(State)) @filter(eq(State.code, ["abc","def"])) {
code : State.code
name : State.name
dgraph.uid : uid
}
}
Additional Support
All the fields of String type which have Hash
or Exact
filter also get a in
function. So the GraphQL schema for the hash
and exact
filter will be:
input StringHashFilter {
eq: String
in: [String]
}
input StringExactFilter {
eq: String
in: [String]
}
References:
Support IN function for fields with @id directive
Proposal: more filter functions