Thuta Learning
GraphQL
IntermediateWeb Developmentbeginner

Input Types and Nested Mutations

What you'll walk away with

  • Explain the core ideas behind Input Types and Nested Mutations
  • Run the sample GraphQL query or code and verify its output
  • Apply the technique correctly to the Tutorial Platform and production scenarios

Build the mental model

When a mutation needs many scalar arguments, an `input` object type groups them into one — input types look like output object types syntactically, but their fields may only be scalars, enums, or other input types, never regular object types. Nesting a list of input types (`lessons: [LessonInput!]!`) inside an input lets you create a tutorial and its lessons in a single request.

Connect it to a real scenario

The author dashboard's "create tutorial" form submits one `CreateTutorialInput` containing `title`, `difficulty`, and `lessons` (each with `title`/`durationMinutes`). The resolver validates lesson-list length and duration ranges at the application level, then inserts the tutorial and its lessons inside one database transaction.

Try the working example

graphql
input LessonInput {
  title: String!
  durationMinutes: Int!
}

input CreateTutorialInput {
  title: String!
  difficulty: Difficulty!
  lessons: [LessonInput!]!
}

mutation CreateTutorial($input: CreateTutorialInput!) {
  createTutorial(input: $input) {
    id
    title
    lessons {
      title
    }
  }
}
You should see
You can write a mutation with a nested input type that creates related records in one request.

5-minute try-it

Write an `UpdateTutorialInput` (`title`, `summary`, `difficulty` — all optional) and design an `updateTutorial` mutation that supports partial updates.

One important caution

Trying to use a regular output object type (like `Author`) as a field type inside an input type fails schema validation — input-type fields must themselves be input types.

GraphQL — Schemas and Types (Input Types)GraphQL

Easy traps

  • Trying to use a regular output object type (like `Author`) as a field type inside an input type fails schema validation — input-type fields must themselves be input types.
  • Validate sample queries and mutations on a local or test server with recoverable data before applying them to production.

Exercise

Write an `UpdateTutorialInput` (`title`, `summary`, `difficulty` — all optional) and design an `updateTutorial` mutation that supports partial updates.

You'll know it worked when: You can write a mutation with a nested input type that creates related records in one request.

Input Types and Nested Mutations | Thuta Learning