A Relay mutation is defined as an "operations that consist of writes to the data store followed by a fetch of any changed fields.". What about something such as logging? I have not found a formal definition of mutations vs query as one would find in the REST POST vs GET vs PUT protocols. Am I correct that one would use a mutation when there is a desire to have data be modified and returned but if I just need to update something then a standard query is fine? There are also cases where I may fetch data but update something which does not need returning.
1 Answers
A Relay mutation is defined as an "operations that consist of writes to the data store followed by a fetch of any changed fields.". What about something such as logging?
If I understand your confusion about logging correctly, you want to log something in your server, but you don't have anything to update on your client-side. You should model this logging operation as a mutation, if you want to use GraphQL and Relay for logging. Query is actually a read-only operation.
If logging was a typo and you actually meant login, there are quite a few previous answers regarding authentication in Relay and GraphQL land. Check the following SO and blog posts:
- Relayjs Graphql user authentication
- javascript - Authentication and privileges on Relay/GraphQL
- api - How do I structure authenticated queries with GraphQL?
- node.js - What is a good pattern for implementing access control in a GraphQL server?
- graphql - Authentication and Access Control with Relay
- node.js - How to check permissions and other conditions in GraphQL query?
- relayjs - How to tell the user to log in with relay?
- A guide to authentication in GraphQL — Building Apollo — Medium
- Auth in GraphQL — Part 2 — Building Apollo — Medium
I have not found a formal definition of mutations vs query as one would find in the REST POST vs GET vs PUT protocols.
From GraphQL draft specification:
There are two types of operations that GraphQL models:
* query – a read‐only fetch.
* mutation – a write followed by a fetch.
Am I correct that one would use a mutation when there is a desire to have data be modified and returned but if I just need to update something then a standard query is fine?
No, that is incorrect. Mutation is the operation that you should use for any kind of modification to your data. If you don't need to fetch any data after the update, you just don't include anything in the fat query. As of now, GraphQL does not have any specific operation type for update without fetching data afterwards.

- 1
- 1

- 3,351
- 16
- 33
-
I see. yes it is logging as in a log. – cyberwombat Jul 31 '16 at 05:00