Example of using variable in mutation?

Hi All,

I tried using the syntax in Query and mutate in the same statement? to retrieve a variable and use it in a mutation, but I must be doing something wrong. With the below statement, I get the error Expected Left round brackets. Got: lex.Item [6] \"{\. I’m using Dgraph v0.8.1. Sorry if this question is a duplicate from somewhere - I wasn’t able to find a working example.

{
	var(func: eq(VertexType, "Namespace")) @filter(eq(Name, "General")) {
			NamespaceUid AS _uid_
	}

	mutation {
	  set {
	    _:a <Name> "This thing" .
	    _:a <Namespace> val(NamespaceUid)  .
	  }
	}
}

Here is an example

https://docs.dgraph.io/query-language/#variables-in-mutations

Also I’d recommend upgrading to v0.8.2 as it has a lot of bugfixes.

1 Like

For anyone looking to do something similar, here’s another working example in v0.8.3:


{
	ns as var(func: eq(VertexType, "Namespace")) @filter(eq(Name, "General"))
}

mutation {
  set {
    _:a <Name> "This thing" .
    _:a <Namespace> uid(ns)  .
  }
}
1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.