Create a GraphQL Subgraph Definition
📖 Scenario: You are building a modular GraphQL API for a bookstore. Each part of the API is a subgraph that handles specific data. Your task is to define a subgraph schema for the Books part of the API.
🎯 Goal: Define a GraphQL subgraph schema for books with types and directives that enable it to work as a subgraph in a federated GraphQL architecture.
📋 What You'll Learn
Create a
type Book with fields id (ID!), title (String!), and author (String!)Add the
@key(fields: "id") directive to Book to specify the primary keyAdd the
@extends directive to Book if extending from another subgraph (optional for this project)Include the
@external directive on fields that are resolved by other subgraphs (optional for this project)Define the
Query type with a field books returning a list of Book💡 Why This Matters
🌍 Real World
GraphQL subgraphs allow teams to build modular APIs that can be composed into a single federated graph, improving scalability and collaboration.
💼 Career
Understanding subgraph definitions is essential for backend developers working with GraphQL federation in modern microservice architectures.
Progress0 / 4 steps