MattH
(Matt H)
November 19, 2021, 4:06am
1
I’m trying to get the syntax down for running an Upsert via curl. I’m using the Upsert guidance on this page: https://dgraph.io/docs/graphql/mutations/upsert/ /
My Upsert attempt looks like:
curl -H "Content-Type: application/json" localhost:8080/mutate/?commitNow=true -XPOST -d '{
"query": "mutation($traveler: [AddTravelerInput!]!) {addTraveler(input: $traveler, upsert: true) {traveler {user_id countries_visited {country_code}}}}",
"variables": { "traveler": {"user_id": "1c395a9f", "countries_visited": { "country_code": "US"}}
}
}' | jq
Resulting error:
{
"errors": [
{
"message": "while lexing mutation($traveler: [AddTravelerInput!]!) {addTraveler(input: $traveler, upsert: true) {traveler {user_id traveler_countries_visited {country_code}}}} at line 1 column 8: Unrecognized character inside mutation: U+0028 '('",
"extensions": {
"code": "ErrorInvalidRequest"
}
}
],
"data": null
}
`
What am I doing wrong?
Thanks in advance!
amaster507
(Anthony Master)
November 19, 2021, 4:42am
2
You are trying to send a GraphQL mutation to the DQL mutate endpoint.
This may help:
I would like to better understand the relationship between the DQL schemas and the GraphQL schemas
This statement and a multitude of related questions (see References) have prompted me to write this to help new users. I remember when I started on the Dgraph road. Why were there so many endpoints? Which one should I use when? What is graphql±? (Meaning to me “GraphQL more or less.” Now it is commonly called DQL to avoid confusion and easier to say/write ) Should I write my schema in GraphQL or …
1 Like
MattH
(Matt H)
November 19, 2021, 6:54pm
3
Thank you! Pointing it to the correct endpoint helped resolve the lexing issue and from there just had to tweak a couple things to get it working. And thanks for the link!
1 Like
loic
(Loïc V)
November 22, 2021, 4:58pm
4
Hello there! Could you share the last version as an example? Thanks
MattH
(Matt H)
November 22, 2021, 6:01pm
5
curl -X POST "http://localhost:8080/graphql" -H "Content-Type: application/json" -d '{
"query": "mutation($vtraveler: [AddTravelerInput!]!) {addTraveler(input: $vtraveler, upsert: true) {traveler {user_id countries_visited {country_code} }}}",
"variables": {"vtraveler": {"user_id": "1c395a9f", "countries_visited": {"country_code": "GB"} }}}'
2 Likes