Diseño de su primer esquema de GraphQL
Aprenda a definir tipos y campos básicos del esquema, y comprenda el Schema Definition Language (SDL).
Diseño de su primer esquema de GraphQL es una lección gratuita de GraphQL APIs with Spring Boot en CoddyKit. Esta es la lección 3 de 4. Puedes leer la lección completa abajo gratuitamente — luego la practicas en el navegador con un editor de código integrado y un tutor de IA 24/7. Forma parte de la ruta de aprendizaje de GraphQL APIs with Spring Boot, y tu progreso se sincroniza en la web y la app de CoddyKit. El curso de GraphQL APIs with Spring Boot incluye 4 lecciones en total.
Partes de esta lección aún no han sido traducidas y se muestran en inglés.
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.
Preguntas frecuentes
¿La lección «Diseño de su primer esquema de GraphQL» es gratis?
Sí — el texto completo de «Diseño de su primer esquema de GraphQL» es gratis para leer aquí en la web. Para practicarla de forma interactiva (editor de código integrado y tutor de IA 24/7) y desbloquear el resto del curso de GraphQL APIs with Spring Boot, actualiza a CoddyKit PRO. El curso de GraphQL APIs with Spring Boot incluye 4 lecciones en total.
¿Qué aprenderé en «Diseño de su primer esquema de GraphQL»?
Aprenda a definir tipos y campos básicos del esquema, y comprenda el Schema Definition Language (SDL). Practicas GraphQL APIs with Spring Boot con código real que ejecutas directamente en el navegador, y un tutor de IA 24/7 responde tus preguntas mientras trabajas en la lección.
¿Necesito experiencia previa para empezar GraphQL APIs with Spring Boot?
No se requiere experiencia previa. GraphQL APIs with Spring Boot en CoddyKit está estructurado para principiantes hasta estudiantes avanzados, así que puedes empezar aquí o desde el inicio y avanzar a tu ritmo. Esta es la lección 3 de 4.
¿Cuánto tiempo toma la lección «Diseño de su primer esquema de GraphQL»?
La mayoría de las lecciones de CoddyKit toman alrededor de 5–10 minutos. Cada una es compacta e interactiva, así que avanzas constantemente y retomas exactamente por donde dejaste en la web y la app.
¿Puedo escribir y ejecutar código en esta lección de GraphQL APIs with Spring Boot?
Sí. Cada lección de GraphQL APIs with Spring Boot incluye un editor de código integrado, así que escribes y ejecutas código real directamente en tu navegador y obtienes retroalimentación instantánea de IA — sin configuración local necesaria.
Todas las lecciones de este curso
- ¿Qué es GraphQL?
- Configuración de Spring Boot para GraphQL
- Diseño de su primer esquema de GraphQL
- GraphQL frente a REST: elija el enfoque adecuado