Support IN function for fields with @id directive

I have this type. Im using GraphQL Dgraph (not the GraphQL± or DQL)

type Respondent {
  name: String
  refcode: String! @id
}

Now I basically want to create a query such that I input [“refcode1”, “refcode2”] and get [{name: “johndoe”, refcode: “refcode1”}, {name: “janedoe”, refcode: “refcode2”}].

One way is to use the generated types. For example,

query {
  queryRespondent(filter: {    
    refcode: {eq:"refcode1"}
    or: {
      refcode: {eq: "refcode2"}
      or: {
        refcode: {eq: "refcode3"}
      }
    },
  }) {
    name
    refcode
  }
}

I also wanted to try to use the DQL custom types – I guess something like this

queryRespondentsByRefcodes(refcodes: [String!]): Respondent @custom(dql: """
	query q($refcodes: [string]) {
		queryRespondentsByRefcodes(func: @filter(eq($refcodes,Respondent.refcode)) ){
			name: Respondent.name
			refcode: Respondent.refcode
		}
	}
	""")

But, I get this error. Which seems to mean I cant pass in a list argument to a graphql query

{"errors":[{"message":"resolving updateGQLSchema failed because input:28: Type Query; Field queryRespondentsByRefcodes: Argument refcodes: must be of a scalar type. @custom DQL queries accept only scalar arguments.\n (Locations: [{Line: 3, Column: 4}])","extensions":{"code":"Error"}}]}VaseAdmins-MacBook-Pro-3:dql-test justin$ 
  1. Is there a more elegant way to write this query using the generated types?
  2. Is there a way to bypass the restriction of not having list as an argument for a custom type?

@pawan - some tips?

1 Like

This query could be simplified if we accept a list of inputs for @id fields like we do for fields of type ID!. So if we supported that, the query would look simpler.

query {
  queryRespondent(filter: {    
    refcode: ["refcode1", "refcode2", "refcode3"]
  }) {
    name
    refcode
  }
}

We can look into this as an enhancement.

Yeah, this is a restriction right now. @abhimanyusinghgaur how hard would it be to support a list of scalars?

2 Likes

DQL doesn’t support list variables at present. We would need to add that capability to DQL itself, if want to pass list args to DQL. See here for DQL vars.

1 Like

I feel like this is a very natural feature. In fact, I discussed with my team and we were still kinda of onboard to just use the auto-gen graphql, otherwise, we’d need to create two layers of graphql on top of each other. Bringing up that we cannot filter by non-native id in the form of a simple array just made it a clear dealbreaker.

Has an issue be made for this (shall I make one)? What kind of precedence will it take in the issue backlog?

I have a feature req floating around somewhere about an in function that would do just this.

The related feature requests and posts:

  1. Proposal: more filter functions
  2. How to find missing data in GraphQL - #3 by amaster507

We are going to support an IN function which allows filtering against multiple values for fields with @id directive. We’ll also look into extending this for other fields which are searchable later. Marking this as accepted.

2 Likes

Fixed by: feat(GraphQL): add support for IN filter by minhaj-shakeel · Pull Request #6662 · dgraph-io/dgraph · GitHub

1 Like

For the given type State having @id

Did this get expanded to all the fields that use the search hash and not just the ones with @id directive?

Oh, I guess that is later. :expressionless: