0Pricing
GraphQL APIs with Spring Boot · Leçon

Concevoir votre premier schéma GraphQL

Apprenez à définir les types et champs de base d'un schéma et découvrez le langage de définition de schéma (SDL).

Concevoir votre premier schéma GraphQL est une leçon GraphQL APIs with Spring Boot gratuite sur CoddyKit. Ceci est la leçon 3 sur 4. Tu peux lire la leçon complète ci-dessous gratuitement — puis la pratiquer en direct dans le navigateur avec un éditeur de code intégré et un tuteur IA 24/7. Elle fait partie du parcours d'apprentissage GraphQL APIs with Spring Boot, et ta progression se synchronise sur le web et l'application CoddyKit. Le cours GraphQL APIs with Spring Boot comprend 4 leçons au total.

Certaines parties de cette leçon n'ont pas encore été traduites et s'affichent en anglais.

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.

Questions Fréquemment Posées

La leçon « Concevoir votre premier schéma GraphQL » est-elle gratuite ?

Oui — le texte complet de « Concevoir votre premier schéma GraphQL » est gratuit à lire ici sur le web. Pour la pratiquer de manière interactive (un éditeur de code intégré et un tuteur IA 24/7) et déverrouiller le reste du cours GraphQL APIs with Spring Boot, passe à CoddyKit PRO. Le cours GraphQL APIs with Spring Boot comprend 4 leçons au total.

Qu'est-ce que j'apprendrai dans « Concevoir votre premier schéma GraphQL » ?

Apprenez à définir les types et champs de base d'un schéma et découvrez le langage de définition de schéma (SDL). Tu pratiques GraphQL APIs with Spring Boot avec du code pratique que tu exécutes directement dans le navigateur, et un tuteur IA 24/7 répond à tes questions au fur et à mesure que tu avances dans la leçon.

Dois-je avoir de l'expérience pour commencer GraphQL APIs with Spring Boot ?

Aucune expérience préalable n'est requise. GraphQL APIs with Spring Boot sur CoddyKit est structuré pour les débutants jusqu'aux apprenants avancés, donc tu peux commencer ici ou depuis le début et avancer à ton rythme. Ceci est la leçon 3 sur 4.

Combien de temps prend la leçon « Concevoir votre premier schéma GraphQL » ?

La plupart des leçons CoddyKit prennent environ 5–10 minutes. Chacune est courte et interactive, tu progresses régulièrement et tu repiques exactement où tu t'es arrêté sur le web et l'app.

Peux-tu écrire et exécuter du code dans cette leçon GraphQL APIs with Spring Boot ?

Oui. Chaque leçon GraphQL APIs with Spring Boot inclut un éditeur de code intégré, tu écris et exécutes du vrai code directement dans ton navigateur et tu reçois des retours IA instantanés — aucune configuration locale requise.

Toutes les leçons de ce cours

  1. Qu'est-ce que GraphQL ?
  2. Configurer Spring Boot pour GraphQL
  3. Concevoir votre premier schéma GraphQL
  4. GraphQL ou REST : choisir la bonne approche
← Retour à GraphQL APIs with Spring Boot