twiz
twiz

Reputation: 10558

Apollo/GraphQL actions that are neither mutations nor queries

Sometimes you need your API to perform an action that doesn't involve retrieving or manipulating data. For example, sending a "Forgot password" email or interacting with a third-party API.

Does Apollo (or GraphQL itself) have a recommended way to accomplish this?

If not, what solutions exists to accomplish this while still taking advantage of Apollo's benefits (such as schema/type-checking)?

Upvotes: 3

Views: 446

Answers (1)

Daniel Rearden
Daniel Rearden

Reputation: 84687

The distinction between queries and mutations is mostly academic. While the spec defines a mutation as a "a write followed by a fetch", you can think of queries as being idempotent and side-effect free while mutations are anything that's, well, not. In this sense, a password reset request may not change anything in your database but it is certainly not free of side-effects and should therefore be a mutation.

As a rule of thumb, anything that can be described as an action ("create", "update", "reset", "send", etc.) should probably be a mutation. This plays into client usage as well, since many clients (i.e Apollo) expect mutations to be used differently than queries client-side.

Upvotes: 7

Related Questions