Progettare il primo schema GraphQL
Impari a definire i tipi e i campi di base dello schema e a comprendere lo Schema Definition Language (SDL).
Progettare il primo schema GraphQL è una lezione GraphQL APIs with Spring Boot gratuita su CoddyKit. Questa è la lezione 3 di 4. Puoi leggere la lezione completa qui gratuitamente — poi esercitati direttamente nel browser con un editor di codice integrato e un tutor IA disponibile 24/7. Fa parte del percorso di apprendimento GraphQL APIs with Spring Boot, e i tuoi progressi si sincronizzano tra il web e l'app CoddyKit. Il corso GraphQL APIs with Spring Boot include 4 lezioni in totale.
Parti di questa lezione non sono ancora state tradotte e vengono mostrate in inglese.
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.
Domande Frequenti
La lezione «Progettare il primo schema GraphQL» è gratuita?
Sì — il testo completo di «Progettare il primo schema GraphQL» è gratuito qui sul web. Per esercitarvi in modo interattivo (un editor di codice integrato e un tutor IA 24/7) e sbloccare il resto del corso GraphQL APIs with Spring Boot, passa a CoddyKit PRO. Il corso GraphQL APIs with Spring Boot include 4 lezioni in totale.
Cosa imparerò in «Progettare il primo schema GraphQL»?
Impari a definire i tipi e i campi di base dello schema e a comprendere lo Schema Definition Language (SDL). Eserciti GraphQL APIs with Spring Boot con codice pratico che esegui direttamente nel browser, e un tutor IA 24/7 risponde alle tue domande mentre lavori sulla lezione.
Ho bisogno di esperienza per iniziare GraphQL APIs with Spring Boot?
Non è richiesta alcuna esperienza precedente. GraphQL APIs with Spring Boot su CoddyKit è strutturato per principianti e studenti avanzati, quindi puoi iniziare da qui o dall'inizio e procedere al tuo ritmo. Questa è la lezione 3 di 4.
Quanto tempo richiede la lezione «Progettare il primo schema GraphQL»?
La maggior parte delle lezioni CoddyKit richiede circa 5–10 minuti. Ogni lezione è breve e interattiva, quindi fai progressi costanti e riprendi esattamente da dove hai lasciato su web e app.
Posso scrivere ed eseguire codice in questa lezione GraphQL APIs with Spring Boot?
Sì. Ogni lezione GraphQL APIs with Spring Boot include un editor di codice integrato, quindi scrivi ed esegui codice reale direttamente nel tuo browser e ricevi feedback istantaneo dall'IA — nessuna configurazione locale necessaria.
Tutte le lezioni di questo corso
- Che cos'è GraphQL?
- Configurare Spring Boot per GraphQL
- Progettare il primo schema GraphQL
- GraphQL vs REST: scegliere l'approccio giusto