Introduction
Relationships help connect different pieces of data, just like how things in real life are connected. They make data easier to understand and use.
Relationships help connect different pieces of data, just like how things in real life are connected. They make data easier to understand and use.
type Author {
id: ID!
name: String!
books: [Book!]!
}
type Book {
id: ID!
title: String!
author: Author!
}type User {
id: ID!
name: String!
posts: [Post!]!
}
type Post {
id: ID!
content: String!
author: User!
}type Student {
id: ID!
name: String!
classes: [Class!]!
}
type Class {
id: ID!
title: String!
students: [Student!]!
}This query gets a customer and all the products they ordered, showing how relationships connect data.
type Customer {
id: ID!
name: String!
orders: [Order!]!
}
type Order {
id: ID!
product: String!
customer: Customer!
}
query GetCustomerOrders {
customer(id: "1") {
name
orders {
product
}
}
}Relationships make data more meaningful by showing connections.
They help avoid repeating the same information in many places.
Using relationships makes it easier to ask questions about connected data.
Relationships link different data types to reflect real-world connections.
They help organize data clearly and avoid duplication.
GraphQL uses fields to show these connections between types.
fieldName: TypeName without extra symbols or quotes.type Author { id: ID name: String books: [Book] } type Book { id: ID title: String author: Author }type User { id: ID name: String posts: Post }Pass the test and this pattern moves unknown