New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GraphQL variables don't seem to be supported in arrays #2272

Closed
ondrowan opened this Issue Mar 27, 2018 · 6 comments

Comments

Projects
None yet
8 participants
@ondrowan
Copy link

ondrowan commented Mar 27, 2018

If you suspect this could be a bug, follow the template.

  • What version of Dgraph are you using?

1.0.4

  • Steps to reproduce the issue (command/config used to run Dgraph).
query all($a: string, $b: string) {
  all(func: eq(whatever, [$a, $b])) {
    uid,
  }
}

Expected comma or language but got: a

  • Expected behaviour and actual result.

Either I'm doing something wrong or GraphQL variables that are used in arrays don't work. And since it's not possible to define variable as arrays, it also seems impossible to do something like:

query all($a: [string]) {
  all(func: eq(whatever, $a)) {
    uid,
  }
}

@pawanrawal pawanrawal self-assigned this Mar 28, 2018

@jmaeso

This comment has been minimized.

Copy link

jmaeso commented Jun 26, 2018

Same happened me, trying the function for getting near locations:

query test($long: string, $lat: string, $radius: string){
	test(func: near(loc, [$long, $lat] , $radius)){
		uid
	}
}

It returns: rpc error: code = Unknown desc = Found invalid item: $ while parsing geo arguments.

As a workaround:

// Create the string with the array inside:
lat := "1.0"
lon := "-2.0"
radius := "200000"
variables := map[string]string{
	"$coords": "[" + lon + ", " + lat + "]", // aka: "[1.0, -2.0]"
	"$radius": radius,
}

// And pass the string to the query:
query test($coords: string, $radius: string){
	test(func: near(loc, $coords , $radius)){
		uid
	}
}

Hope this help someone

@JeffersonH44

This comment has been minimized.

Copy link

JeffersonH44 commented Jul 24, 2018

I've got the same problem using ratel, my current dgraph version is 1.0.6, this is in some way my query:

{
  var(func: anyofterms(...)) {
      lat as location.lat
        lng as location.lng
  }
  
  test(func: near(loc, [val(lat), val(lng)], 10000)) {
       ...
  }
}

and I'm getting this error:

Found invalid item: ( while parsing geo arguments.

@manishrjain

This comment has been minimized.

Copy link
Member

manishrjain commented Jul 26, 2018

I don't think this is supported. You'd have to run this in 2-queries.

@F21

This comment has been minimized.

Copy link
Contributor

F21 commented Jan 24, 2019

Just a quick note that @jmaeso 's solution unfortunately does not work with eq().

Query:

query Assets ($ids: string){
	asset(func: eq(name, $ids)){
		uid
		name
	}
}

Variables:

"$ids": "[\"a1\", \"a2\"]"

This returns nothing, because dgraph is probably treating ["a1", "a2"] as the string it's trying to match.

@MichelDiz

This comment has been minimized.

Copy link
Contributor

MichelDiz commented Feb 5, 2019

Just an update on this thread.

query geoq($loca:string = "[-122.469829, 37.771935]") {
  tourist(func: near(loc, $loca, 1000) ) {
    name
  }
}

Run this query in https://play.dgraph.io/

That's the right way to use geo arguments in Dgraph, for who's trying that.

For the Inequality issue you can always use [ ] and set multiple values. Like so:

{
  me(func: eq(name@en, ["Ridley Scott", "Steven Spielberg"])) {
    name@en
    director.film @filter(lt(initial_release_date, "1980-01-01"))  {
      initial_release_date
      name@en
    }
  }
}

Run this query in https://play.dgraph.io/

However I do not understand why eq does not work with GraphQL Variables in this case.
We could mimic the process used in "near" to "eq".

@srfrog srfrog added bug and removed enhancement labels Feb 6, 2019

@srfrog

This comment has been minimized.

Copy link
Contributor

srfrog commented Feb 7, 2019

Unfortunately, the geo array is not supported. The eq var array is a bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment