Definition

Selecting fields means explicitly specifying which fields of a type should be included in the response.


Core Concept

GraphQL requires the client to define the exact shape of the response by selecting fields.

Only the selected fields are returned by the server.


Basic Example

query {
  user {
    id
    name
  }
}

Response

{
  "data": {
    "user": {
      "id": "1",
      "name": "Zeeshan"
    }
  }
}

Partial Selection

query {
  user {
    name
  }
}

Response

{
  "data": {
    "user": {
      "name": "Zeeshan"
    }
  }
}

Fields not requested are not returned.


Nested Selection

If a field returns an object, its fields must also be selected.