Projetando seu Primeiro Esquema GraphQL
Aprenda a definir tipos e campos básicos de esquema e entenda a Linguagem de Definição de Esquemas (SDL).
Projetando seu Primeiro Esquema GraphQL é uma aula grátis de GraphQL APIs with Spring Boot no CoddyKit. Esta é a aula 3 de 4. Você pode ler a aula completa abaixo gratuitamente — depois pratica ao vivo no navegador com um editor de código integrado e um tutor de IA 24/7. Faz parte do caminho de aprendizado de GraphQL APIs with Spring Boot, e seu progresso é sincronizado entre a web e o app CoddyKit. O curso de GraphQL APIs with Spring Boot inclui 4 aulas no total.
Partes desta aula ainda não foram traduzidas e aparecem em 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.
Perguntas Frequentes
A aula “Projetando seu Primeiro Esquema GraphQL” é grátis?
Sim — o texto completo de “Projetando seu Primeiro Esquema GraphQL” é grátis para ler aqui na web. Para praticá-la interativamente (um editor de código integrado e um tutor de IA 24/7) e desbloquear o restante do curso de GraphQL APIs with Spring Boot, atualize para CoddyKit PRO. O curso de GraphQL APIs with Spring Boot inclui 4 aulas no total.
O que vou aprender em “Projetando seu Primeiro Esquema GraphQL”?
Aprenda a definir tipos e campos básicos de esquema e entenda a Linguagem de Definição de Esquemas (SDL). Você pratica GraphQL APIs with Spring Boot com código prático que executa diretamente no navegador, e um tutor de IA 24/7 responde suas dúvidas enquanto trabalha na aula.
Preciso ter experiência prévia para começar GraphQL APIs with Spring Boot?
Nenhuma experiência prévia é necessária. GraphQL APIs with Spring Boot no CoddyKit é estruturado para alunos iniciantes até avançados, então você pode começar aqui ou desde o início e aprender no seu ritmo. Esta é a aula 3 de 4.
Quanto tempo leva a aula “Projetando seu Primeiro Esquema GraphQL”?
A maioria das aulas CoddyKit leva cerca de 5–10 minutos. Cada uma é compacta e interativa, então você faz progresso constante e retoma exatamente de onde parou entre web e app.
Posso escrever e executar código nesta aula de GraphQL APIs with Spring Boot?
Sim. Cada aula de GraphQL APIs with Spring Boot inclui um editor de código integrado, então você escreve e executa código real direto no navegador e recebe feedback de IA instantaneamente — nenhuma configuração local necessária.
Todas as aulas deste curso
- O que é GraphQL?
- Configurando Spring Boot para GraphQL
- Projetando seu Primeiro Esquema GraphQL
- GraphQL versus REST: escolhendo a abordagem certa