What is the point of naming queries and mutations in GraphQL?

The query name doesn’t have any meaning on the server whatsoever. It’s only used for clients to identify the responses (since you can send multiple queries/mutations in a single request).

In fact, you can send just an anonymous query object if that’s the only thing in the GraphQL request (and doesn’t have any parameters):

{
  user(id: 4) {
    id
    name
    profilePic(size: 200)
  }
}

This only works for a query, not mutation.

EDIT:
As @orta notes below, the name could also be used by the server to identify a persistent query. However, this is not part of the GraphQL spec, it’s just a custom implementation on top.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)