[Question] Why can queryWithVars variables only be strings, not ints?

Moved from GitHub dgraph-js/33

Posted by good-idea:

I have a query function that looks like this:

const getUsers = async ({ first = 50, after = '0x0' }: PaginationArgs): Promise<PageType | null | Error> => {
	const query = `query getUsers($first: number, $after: string) {
		getUsers(func: eq(type, "user"), first: $first, after: $after)  {
	const vars = {
		$first: first,
		$after: after
	const result = await db.newTxn().queryWithVars(query, vars))
	return result

One issue is that this variable is simply discarded, then I get the error:
Error: 2 UNKNOWN: : strconv.ParseInt: parsing "": invalid syntax - this would be much more helpful if it said something like “Only strings are allowed as variables”

I can then get this working if I do this:

	const query = `query getUsers($first: string, $after: string) {
	// change 'number' to 'string'    ----^

	const vars = {
		$first: first.toString(),
		$after: after

But then, it’s just going to be parsed back to an Int internally. Why not allow for ints in the first place?

gpahal commented :

It’s how Dgraph works. To pass an integer 5, you either have to define a schema or use the NQuad <uid> <age> "5"^^<xs:int> .. See Language and RDF Types

good-idea commented :

Got it, Thanks!