0Pricing
GraphQL APIs with Spring Boot · Lesson

Designing Your First GraphQL Schema

Learn to define basic schema types, fields, and understand the Schema Definition Language (SDL).

Designing Your First GraphQL Schema is a free GraphQL APIs with Spring Boot lesson on CoddyKit — lesson 3 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the GraphQL APIs with Spring Boot learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

What's a GraphQL Schema?

A GraphQL schema is the blueprint of your API: it defines what data clients can ask for and how it’s structured. It’s the core of every GraphQL service.

Meet SDL: Schema Language

You write schemas in the Schema Definition Language (SDL) — a simple, readable syntax for declaring object types, their fields, and how they relate.

Building Blocks: Object Types

The core building block is the object type, declared with the type keyword. Like a class, it represents a kind of object you can fetch.

type User {
  # Fields will go here
}

Adding Fields with Scalar Types

Fields hold data via built-in scalar types: String, Int, Float, Boolean, and ID for unique identifiers.

type User {
  id: ID
  name: String
  age: Int
  isActive: Boolean
  rating: Float
}

Essential Data: Non-Null Fields

Add ! after a type to make a field non-null — it must always have a value. Query it and the server must return one or it errors.

type Product {
  id: ID!
  name: String!
  price: Float!
  description: String
}

Collections: Lists in GraphQL

Wrap a type in [] for a list. Stack the ! too: [String!]! means a non-null list of non-null strings.

type Book {
  id: ID!
  title: String!
  pages: Int
}

type Author {
  id: ID!
  name: String!
  books: [Book] # A list of books, can be empty or null
  tags: [String!]! # A list of non-null strings, and the list itself is non-null
}

Entry Point: The Query Type

Every schema needs the root Query type — it defines all the entry points for clients to read data. Queries always start here.

type Query {
  # Query fields will go here
}

Defining Query Fields

Fields on Query are the data you can fetch, and they take arguments to filter — like book(id: ID!): Book to grab one book by id.

type Author {
  id: ID!
  name: String!
}

type Book {
  id: ID!
  title: String!
}

type Query {
  allAuthors: [Author!]!
  bookById(id: ID!): Book
}

Your First Complete Schema

Here it all comes together: Author and Book types, a Query entry point, and a Book.author field that links the two. Relationships!

type Author {
  id: ID!
  name: String!
  books: [Book!]! # An author has a list of non-null books
}

type Book {
  id: ID!
  title: String!
  pages: Int
  author: Author # A book has one author
}

type Query {
  allBooks: [Book!]!
  book(id: ID!): Book
  allAuthors: [Author!]!
  author(id: ID!): Author
}

Schema Check-up

What does ! mean, and where does Query fit? Prove it.

Schema Design Recap

You designed a real schema: object types with the type keyword, scalar fields, ! for non-null, [] for lists, and Query as the read entry point.

Frequently asked questions

Is the “Designing Your First GraphQL Schema” lesson free?

Yes — the full text of “Designing Your First GraphQL Schema” is free to read here on the web, and the GraphQL APIs with Spring Boot course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the GraphQL APIs with Spring Boot course, upgrade to CoddyKit PRO.

What will I learn in “Designing Your First GraphQL Schema”?

Learn to define basic schema types, fields, and understand the Schema Definition Language (SDL). You practise GraphQL APIs with Spring Boot with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start GraphQL APIs with Spring Boot?

No prior experience is required. GraphQL APIs with Spring Boot on CoddyKit is structured for beginners through advanced learners; this is — lesson 3 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Designing Your First GraphQL Schema” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this GraphQL APIs with Spring Boot lesson?

Yes. Every GraphQL APIs with Spring Boot lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. What is GraphQL?
  2. Setting up Spring Boot for GraphQL
  3. Designing Your First GraphQL Schema
  4. GraphQL vs REST: Choosing the Right Approach
← Back to GraphQL APIs with Spring Boot