GraphQL APIs with Spring Boot · Lektion

Ihr erstes GraphQL-Schema entwerfen

Lernen Sie, grundlegende Schem typen und Felder zu definieren und die Schema Definition Language (SDL) zu verstehen.

Lektion 3 von 411 Schritte

Ihr erstes GraphQL-Schema entwerfen ist eine kostenlose GraphQL APIs with Spring Boot-Lektion auf CoddyKit. Dies ist Lektion 3 von 4. Du kannst die komplette Lektion unten kostenlos lesen – dann übst du sie direkt im Browser mit einem integrierten Code-Editor und einem KI-Tutor rund um die Uhr. Sie ist Teil des GraphQL APIs with Spring Boot-Lernpfads, und dein Fortschritt wird über Web und CoddyKit-App synchronisiert. Der GraphQL APIs with Spring Boot-Kurs umfasst insgesamt 4 Lektionen.

Teile dieser Lektion wurden noch nicht übersetzt und werden auf Englisch angezeigt.

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.

Kostenlos starten

Lerne GraphQL APIs with Spring Boot mit einem KI-Tutor — kostenlos

Schreibe und führe echten Code in deinem Browser aus, bekomme sofortige Hilfe von einem 24/7 KI-Tutor und setze dein Lernen im Web oder in der App fort.

Kurse
12
Lektionen
48

Häufig gestellte Fragen

Ist die Lektion „Ihr erstes GraphQL-Schema entwerfen“ kostenlos?

Ja — der vollständige Text von „Ihr erstes GraphQL-Schema entwerfen“ ist hier im Web kostenlos zu lesen. Um sie interaktiv zu üben (integrierter Code-Editor und 24/7 KI-Tutor) und den Rest des GraphQL APIs with Spring Boot-Kurses freizuschalten, upgrade auf CoddyKit PRO. Der GraphQL APIs with Spring Boot-Kurs umfasst insgesamt 4 Lektionen.

Was lerne ich in „Ihr erstes GraphQL-Schema entwerfen“?

Lernen Sie, grundlegende Schem typen und Felder zu definieren und die Schema Definition Language (SDL) zu verstehen. Du übst GraphQL APIs with Spring Boot mit praktischem Code, den du direkt im Browser ausführst, und ein 24/7 KI-Tutor beantwortet deine Fragen während du die Lektion bearbeitest.

Brauche ich Erfahrung, um GraphQL APIs with Spring Boot zu starten?

Keine Vorkenntnisse erforderlich. GraphQL APIs with Spring Boot auf CoddyKit ist für Anfänger bis fortgeschrittene Lernende strukturiert, sodass du hier starten oder von Anfang an beginnen und in deinem eigenen Tempo voranschreiten kannst. Dies ist Lektion 3 von 4.

Wie lange dauert die Lektion „Ihr erstes GraphQL-Schema entwerfen“?

Die meisten CoddyKit-Lektionen dauern etwa 5–10 Minuten. Jede ist kompakt und interaktiv, sodass du stetig Fortschritte machst und genau dort weitermachst, wo du aufgehört hast – im Web und in der App.

Kann ich in dieser GraphQL APIs with Spring Boot-Lektion Code schreiben und ausführen?

Ja. Jede GraphQL APIs with Spring Boot-Lektion enthält einen integrierten Code-Editor, sodass du echten Code direkt in deinem Browser schreibst und ausführst und sofort KI-Feedback erhältst — ohne lokale Einrichtung erforderlich.

Alle Lektionen in diesem Kurs

  1. Was ist GraphQL?
  2. Spring Boot für GraphQL einrichten
  3. Ihr erstes GraphQL-Schema entwerfen
  4. GraphQL vs. REST: Den richtigen Ansatz wählen
← Zurück zu GraphQL APIs with Spring Boot