# Query, Mutation and Subscription Types — GraphQL

Source: https://www.skillbyai.com/en/graphql/s-root

> Entry points into the graph.

## Root operation types

The schema defines entry points: fields on `Query` read data, fields on `Mutation` change data (executed one after another, in order), and fields on `Subscription` stream events. Root fields take arguments such as IDs, filters and pagination parameters. Keep root fields focused (`user(id:)`, `products(filter:, first:)`) and let clients navigate relationships from there rather than adding a root field for every combination.

## Root types for the shop

GraphQL SDL.

```graphql
type Query {
  me: User
  user(id: ID!): User
  product(id: ID!): Product
  products(filter: ProductFilter, first: Int = 20, after: String): ProductConnection!
}

type Mutation {
  addToCart(input: AddToCartInput!): AddToCartPayload!
  placeOrder(input: PlaceOrderInput!): PlaceOrderPayload!
}

type Subscription {
  orderStatusChanged(orderId: ID!): Order!
}
```

## Return nullable single lookups

user(id:) returning User (nullable) lets "not found" be null instead of an error.

**Quiz:** How are multiple mutation fields in one request executed?

- [ ] In parallel, in random order
- [x] Serially, in the order written
- [ ] Only the first runs
- [ ] They are rejected

*Answer:* Serially, in the order written. Query fields may run in parallel; mutations run in order.
