logo

Understanding the Schema

Every GraphQL API has a schema that defines what you can query. It's the source of truth for what data exists and how to access it.

type User {
  id: ID!
  name: String!
  email: String
  posts: [Post!]!
}

type Query {
  user(id: ID!): User
  users: [User!]!
}

This tells you:

  • User has id, name, email, and posts fields
  • Query.user takes an ID and returns one user (or null)
  • Query.users returns a list of users

The ! means non-nullable. [Post!]! means a non-null list of non-null posts.

GraphQL APIs are self-documenting. You can query the schema itself:

{
  __schema {
    types {
      name
    }
  }
}

This introspection is how tools like GraphiQL show you available fields.

I explain schema design in my GraphQL with Python course.