Skip to content
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

QueryWithVars doesn't receive int variable in @recurse() #3301

Closed
stevenayers opened this issue Apr 18, 2019 · 5 comments · Fixed by #4385
Closed

QueryWithVars doesn't receive int variable in @recurse() #3301

stevenayers opened this issue Apr 18, 2019 · 5 comments · Fixed by #4385
Labels
area/querylang/recurse Related to the recurse directive. area/querylang/vars Issues related to queries with GraphQL variables kind/enhancement Something could be better. popular status/accepted We accept to investigate/work on it.

Comments

@stevenayers
Copy link

stevenayers commented Apr 18, 2019

I would have raised this in dgo, but it looks like it could be more to do with the parser. I saw that even though you have to pass a map[string]string into QueryWithVars, if you specify it as an int in withvar(), it should be able to take it.

Code ref: https://github.com/dgraph-io/dgraph/blob/master/gql/parser.go#L303

  • What version of Dgraph are you using?
    1.0.14

  • Have you tried reproducing the issue with latest release?
    yes

  • What is the hardware spec (RAM, OS)?
    rd5.large

  • Steps to reproduce the issue (command/config used to run Dgraph).
    You can only pass a string map as the variables map.

         queryDepth := strconv.Itoa(1)
	variables := map[string]string{"$id": Id, "$depth": queryDepth}
	q := `query withvar($id: string, $depth: int){
			result(func: eq(id, $id)) @recurse(depth: $depth, loop: false){
 				id
                                 links
			}
		}`
	resp, err := txn.QueryWithVars(*ctx, q, variables)
  • Expected behaviour and actual result.

Error: Expected value inside @recurse() for key: depth

@martinmr martinmr added kind/enhancement Something could be better. kind/feature Something completely new we should consider. labels Apr 19, 2019
@martinmr
Copy link
Contributor

I checked the code and variables inside recurse have never been supported. Most likely an oversight but since this is not breaking existing features I have tagged it as a feature.

@hamada969
Copy link

hamada969 commented May 5, 2019

hey guys, appreciate the hard work.

Any updates on this issue.

This breaks with the same error using the python version as well

query = """query relation($node_id: string, $depth: int) {{
                relation(func: eq(id, $node_id)) 
                @recurse(depth: $depth, loop: true)
                {{
                    {expand}
                }}
            }}""".format(expand=EXPAND_PROPERTIES)

    variables = {'$node_id': node_id, '$depth': "3"}

@stevenayers
Copy link
Author

It's messy, but you can use string interpolation as a workaround for now.

@campoy campoy added the area/querylang/recurse Related to the recurse directive. label Sep 13, 2019
@campoy campoy added popular area/querylang/vars Issues related to queries with GraphQL variables status/accepted We accept to investigate/work on it. and removed kind/feature Something completely new we should consider. labels Sep 13, 2019
@amandalmia14
Copy link

@campoy Any updates on this issue?

@stevenayers It will be helpful if you share an example. Thanks.

@stevenayers
Copy link
Author

stevenayers commented Dec 6, 2019

@amandalmia14

depth := strconv.Itoa(5)
variables := map[string]string{"$id": Id}
q := `query withvar($url: string, $depth: int){
		result(func: eq(id, $id)) @recurse(depth: ` + depth + `, loop: false){
 			uid
    			links
		}
	}`
resp, err := txn.QueryWithVars(*ctx, q, variables)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/querylang/recurse Related to the recurse directive. area/querylang/vars Issues related to queries with GraphQL variables kind/enhancement Something could be better. popular status/accepted We accept to investigate/work on it.
Development

Successfully merging a pull request may close this issue.

5 participants