In Part 1, we explored what GraphQL is and how it’s changing the way developers think about APIs.
If you haven’t read it yet, you might want to check it out — it’ll make what we’re about to cover even clearer.

In this second part, we’re diving into the heart of GraphQLSchemas and Types.
They’re what make GraphQL powerful, flexible, and… honestly, pretty fun to use.

What’s a GraphQL Schema, Anyway?

Think of a schema as the map of your data world.
It describes all the types of data your API can handle — along with the relationships between them. Everything you can query, mutate, or fetch is defined right here.

Here’s a simple example:

type Book {
  id: ID!
  title: String!
  author: String!
  publishedYear: Int
}

type Query {
  books: [Book]
  book(id: ID!): Book
}

This tells us a few things:

  • There’s a Book type with fields like id, title, author, and publishedYear.
  • We can fetch all books with books or get one book by its ID using book.

Pretty neat, right? You’re basically defining what’s possible in your API.

The Building Blocks: Types

GraphQL is all about types — everything revolves around them.
They make your API predictable and self-documenting, which means fewer surprises for developers using it.

Here are some basic types you’ll encounter:

Type

What It Means

Int

Whole numbers

Float

Decimal numbers

String

Text values

Boolean

True or false

ID

Unique identifiers for objects

Of course, you can also create your own custom types, like User, Product, or Book, depending on your data.

Reading and Writing Data

Now that you’ve got a schema and some types, how do you use them?
That’s where queries and mutations come in.

Queries = Reading Data

Queries are like asking your API for information.

Example:

query {
  books {
    title
    author
  }
}

And here’s what you might get back:

{
  "data": {
    "books": [
      { "title": "1984", "author": "George Orwell" },
      { "title": "The Hobbit", "author": "J.R.R. Tolkien" }
    ]
  }
}

Just what you asked for — no more, no less.

Mutations = Changing Data

Mutations let you add, update, or delete data.

Example:

mutation {
  addBook(title: "Dune", author: "Frank Herbert", publishedYear: 1965) {
    id
    title
  }
}

This would create a new book entry and return its ID and title.
One call — one clean response.

Resolvers: The Hidden Workers

Behind every query or mutation, there’s a resolver — a function that actually fetches the data.
Think of it as the bridge between your GraphQL schema and your database or API.

Here’s a quick Python example:

def resolve_books(root, info):
    # Fetch all books from the database
    return db.get_all_books()

So when you run that books query, this resolver goes off and grabs the real data for you.

Why Schemas and Types Matter

Schemas aren’t just technical details — they’re what make GraphQL so easy to work with.
They ensure:

  • Predictability: You always know what data is available and how to get it.
  • Self-documentation: Tools like Apollo Studio or GraphiQL can automatically visualize your schema.
  • Flexibility: You can evolve your API without breaking old queries.

In other words, the schema is your API’s single source of truth.

Up Next

Now that you know how schemas and types work, you’re ready to start building real queries and mutations.
In Part 3, we’ll dig deeper into writing and executing queries, handling arguments, and connecting to real databases.

Stick around — this is where GraphQL really starts to shine!

Categorized in: