Daniel's working notes

GraphQL support named query with alias

When working on a project, I need to do two similar query with slightly different parameters. After reading GraphQL docs, turns out it support named query with alias. So in the documentation example, we could query User with two different parameters like this:

{
  first: User(id: "1") {
    name
  }
  second: User(id: "2") {
    name
  }
}

and the response:

{
  "first": {
    "name": "Alice"
  },
  "second": {
    "name": "Sarah"
  }
}

This particularly useful because we can nest the same model object under different field to differentiate them.

Linked Notes: