Support IN filter

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

If we support this, then it would automatically be available on any String field having exact/hash directive along with fields having @id directive. So this is what we should aim to support.

2 Likes

What is this about a between function on fields of String type?

Ah, I think that should have been an IN function. @minhaj can you correct that, please?

1 Like

My bad! Corrected now. Thanks @amaster507 and @pawan.

:+1: yes please.

In the longer term we should be able to support this on other scalar types as well, right?

1 Like