Introduction
Object types let you define the shape of data you want to get or send. They organize information clearly.
Object types let you define the shape of data you want to get or send. They organize information clearly.
type TypeName {
fieldName1: FieldType1
fieldName2: FieldType2
...
}Each field has a name and a type.
Types can be scalars like String, Int, or other object types.
type User {
id: ID
name: String
age: Int
}type Book {
title: String
author: User
}type Query {
users: [User]
books: [Book]
}This schema defines a User object type and a Query to get one user.
type User {
id: ID
name: String
email: String
}
type Query {
getUser: User
}Object types are the main way to describe data in GraphQL.
Fields can be other object types, allowing nested data.
Use capitalized names for types by convention.
Object types define the shape of data in GraphQL.
They have named fields with specific types.
They help organize and reuse data structures.
Object type in GraphQL?Book with a title field of type String?type followed by the name and fields in braces.type Book { title: String }. Others use invalid keywords.type User {
id: ID
name: String
age: Int
}{ user { id name } }?id and name.age in query does not cause error; it is simply not returned.type Product {
id: ID!
name: String
price: Float
price: Int
}price is declared twice with different types (Float and Int), which is invalid.ID! is valid for non-null. Fields can be optional. Object type can have multiple fields.Author that includes a list of Book objects. Which is the correct way to define the books field?[Book].Pass the test and this pattern moves unknown