I have gone through below documentation regarding how to write mutations using HTTP requests
https://dgraph.io/docs/mutations/mutations-using-curl/
How can I pass variable to the mutation using curl command?
eg:I want to pass name predicate value through post request
I dont find any documentation regarding that?
How can I achieve that?
The usual DQL/RDF mutation doesn’t support query variables. Specially RDF, there’s no way to use Query Variable in RDF as the parser doesn’t support it. However, we support a variable object in DQL using the JSON format. Go to GraphQL Variables - Query language and select “cURL” in the runnable block(there are examples for various languages). In JSON format there are two objects you can pass, the Query and the Variable.
You can also use the DQL format with query variables, but there’s no way to pass it in a “usual way”. You have to use the default value instead.
e.g:
curl -H "Content-Type: application/rdf" -X POST localhost:8080/mutate?commitNow=true -d $'
upsert {
query test($a: int = "5", $b: int = "10", $name: string = "Steven Spielberg") {
me(func: allofterms(name@en, $name)) {
v as uid
name@en
director.film (first: $a, offset: $b) {
name @en
genre(first: $a) {
name@en
}
}
}
}
mutation {
set {
uid(v) <age> "28" .
}
}
}' | jq
See the line that’s defining the default values for the variables.
$a: int = “5”, $b: int = “10”, $name: string = “Steven Spielberg”
@MichelDiz I am using insomnia to write mutations .
My payload looks like this
{
"query": "query test($school: string){ q(func: eq(school, $school)) {v as uid} }",
"set": {
"uid": "uid(v)",
"strength":60
},
"variables":{ "$school": "a" }
}
each time I hit the api , a new duplicate school is getting created.
if I write my payload as given below:
{
"query": "query test($school: string=\"a\"){ q(func: eq(school, $school)) {v as uid} }",
"set": {
"uid": "uid(v)",
"strenght":62
}
}
this is working fine. The strenght value is getting updated . No duplicates are getting created.
what is the wrong with my 1st payload?
Am i defining the default values for the variables in wrong way?
Ah! sorry, I just remembered that the HTTP API doesn’t support DQL variables… Just some clients.