I'm learning about GraphQL and I'm very interested in the operation name
the part of the query that comes after the query
or mutation
(depending on the root query type). I found a couple of code examples using the operation name, and I'm confused as to where they come from? There seems to be no references in the code about them, and they seem completely arbitrary.
query Welcome { echo (email: "[email protected]") }
and
query HeroNameQuery { hero { name } }
I don't understand why a given schema can't just contain the queries and types that follow (eg. user
, article
, order
, etc.), and I don't understand the namespacing system and the operation name provides any sort of advantage.
https://github.com/mugli/learning-graphql/blame/master/7.%20Deep%20Dive%20into%20GraphQL%20Type%20System.md#L436
http://graphql.org/docs/queries/
The operation name is pretty much up to you on what you want to call it. However, you do need it when you pass in query / mutation parameters like so: // GraphQL Query query Welcome ($data: String!) { echo (email: $data) { name } } // GraphQL Variables { "data": "[email protected]" }
Mutations allow you to modify server-side data, and it also returns an object based on the operation performed. It can be used to insert, update, or delete data. Dgraph automatically generates GraphQL mutations for each type that you define in your schema.
In GraphiQL you can choose from a list of queries specified by the operation name. Here's some screenshots to help make this make sense.
When you have two mutations / queries side-by-side and they don't have an operation name you can't run them.
When they have operation names they can be listed when you click the play / run button.
This is the biggest case for having an operation name that I've seen so far.
But it's not necessary because when you just have run query / mutation that's what's gonna run.
The Query/Mutation name is optional. You can use it on the backend for stored queries if your backend supports it. However, it is generally used for logging. You can use a unique name for each query/mutation. Then, when you are having problems, you can grep through your logs for the query name to see what was happening with that specific query.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With