Int type parameter of custom dql is wrong

I defined the following custom dql query:

type Query {
    getTest(first: Int!): [User] @custom(dql: """ 
        query q($first: int!) {
            getTest(func: type(User),first: $first) {
                id: User.id
                name: User.name
            }
        }
    """)
}

When I execute the following query, it works:

query{
  getTest(first:  12){
    id
    name
  }
}

When I changed to variable execution, it threw an error:

query($first: Int!){
   getTest(first:  $first){
    id
    name
  }
}

The error:

"errors": [
    {
      "message": "couldn't convert argument first to string because provided value is not a scalar, can't convert it to string"
    }
]

The above is the result of my test in altair client.

If I change the type of first to first: String, the above error will no longer appear, but it does not meet my expectations. first should be of type int.

PS, ignore this - This answer is wrong. Not a duplicated issue.

This is not supported, and it is duplicated of

@MichelDiz Will it be implemented later?
I use http to call the GraphQL API. According to the GraphQL specification, I must write it like this.

To make it work, I temporarily changed the type of first to String.

Hope to correct it later.

It is in the back-log and it is popular. So, 99,9999% yes.

But this works in DQL?

Yeah, It works.

type Query {
    getTest(first: String!): [User] @custom(dql: """ 
        query q($first: string!) {
            getTest(func: type(User),first: $first) {
                id: User.id
                name: User.name
            }
        }
    """)
}

It will work after changing to String type.
Looking forward to improving this feature soon.

it works in GQL as is illustrated above and as categorized. Your referenced issue was DQL.

@michaelcompton is there a reason why the input of first works with String and not Int?

This error seems like it stems from after the query gets rewritten to DQL. This does not seem like a normal type error from the graphQL logic.

My confusion was about the type of variables. Just now I noticed that I confused DQL Vars with Value Vars. My reference above is about Value Vars, not DQL.

That feels like a GraphQL parsing error

See

Run

query q($first: int) {
  getTest(func: type(Film),first: $first) {
    uid
    expand(_all_)
  }
}

In https://play.dgraph.io/?latest

So, @asuka, sorry for my mistake. DQL Vars and Value Vars are totally different things. Not sure why this parsing error happens. As INT is supported by DQL Vars.

@abhimanyusinghgaur do you have any idea about it?

It is a bug with respect to variable handling in GraphQL. Numbers from variables are parsed as json.Number and not int or float scalar types. There is a missing case for json.Number during the conversion to DQL variables.
Will have a PR for it soon.

Here is the PR: https://github.com/dgraph-io/dgraph/pull/6433
Hope to get it merged today.

1 Like

Nice! thanks The Flash! :zap:

BTW @asuka, you don’t need to add ! in DQL the exclamation has no effect. As fas as I remember.

1 Like

@MichelDiz

Ok. But how to distinguish between required and optional?

@MichelDiz meant that ! won’t have any effect in DQL. It is a feature only in GraphQL.

So, in the above line, it will make the first argument as NON_NULL. But, you don’t need to apply it inside DQL as you have done it in the next line after the above line:

So, to clarify your question, with GraphQL you can distinguish between required and optional but DQL has no such concept. So, just having the following query will make it a required argument:

type Query {
    getTest(first: Int!): [User] @custom(dql: """ 
        query q($first: int) {
            getTest(func: type(User),first: $first) {
                id: User.id
                name: User.name
            }
        }
    """)
}

@abhimanyusinghgaur Thanks, I see.