Thuta Learning
GraphQL
BasicWeb Developmentbeginner

The Schema and Type System

What you'll walk away with

  • Explain the core ideas behind The Schema and Type System
  • 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

A GraphQL schema is a contract that declares every shape of data the API can return, using types. Built-in scalar types are `String`, `Int`, `Float`, `Boolean`, and `ID`; `!` marks a field non-null, and syntax like `[Type!]!` means a non-null list of non-null items. `Query` is a special root type that declares every readable entry point. This type language is called Schema Definition Language (SDL).

Connect it to a real scenario

We declare the Tutorial Platform's core `Tutorial` type with `id`, `title`, `summary`, `lessonCount`, and `isFeatured` fields. Marking `id` as `ID!` (non-null) enforces at the schema level that every tutorial must have an id. Notice the difference inside `Query` between `tutorial(id: ID!): Tutorial` (a single, nullable item) and `tutorials: [Tutorial!]!` (a non-null list).

Try the working example

graphql
type Tutorial {
  id: ID!
  title: String!
  summary: String
  lessonCount: Int!
  isFeatured: Boolean!
}

type Query {
  tutorial(id: ID!): Tutorial
  tutorials: [Tutorial!]!
}
You should see
You can read and write a simple schema using types, scalars, and non-null/list syntax.

5-minute try-it

Write an `Author` type with `id`, `name`, and a nullable `bio`, plus a `tutorials` list field, and a `Query` extension with `author(id: ID!): Author`.

One important caution

Marking a field non-null (`!`) and then having the resolver return `null` causes a GraphQL execution error. If a field can legitimately be missing, leave it nullable.

GraphQL — Schemas and TypesGraphQL

Easy traps

  • Marking a field non-null (`!`) and then having the resolver return `null` causes a GraphQL execution error. If a field can legitimately be missing, leave it nullable.
  • Validate sample queries and mutations on a local or test server with recoverable data before applying them to production.

Exercise

Write an `Author` type with `id`, `name`, and a nullable `bio`, plus a `tutorials` list field, and a `Query` extension with `author(id: ID!): Author`.

You'll know it worked when: You can read and write a simple schema using types, scalars, and non-null/list syntax.

The Schema and Type System | Thuta Learning