0Pricing
GraphQL APIs with Spring Boot · レッスン

Schema Stitchingの基礎

異なるサービスから統合されたGraphQL APIを構成するSchema Stitchingの原則について学びます。

「Schema Stitchingの基礎」はCoddyKit上の無料GraphQL APIs with Spring Bootレッスンです。 これはレッスン2/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはGraphQL APIs with Spring Boot学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 GraphQL APIs with Spring Bootコースには全4レッスンが含まれています。

このレッスンの一部はまだ翻訳されておらず、英語で表示されています。

Stitching: Unifying Your APIs

Imagine having multiple GraphQL services, perhaps from different teams or even different backend technologies. How do you present them as a single, cohesive API to your frontend? That's where Schema Stitching comes in!

It allows you to combine multiple independent GraphQL schemas into one unified gateway schema.

Breaking Down the Monolith

In large applications, a single, massive API (a "monolith") can become hard to manage. Different teams might step on each other's toes, and deployments become risky.

  • Slow Development: Changes impact the entire system.
  • Deployment Risks: A bug in one part can bring down everything.
  • Scaling Issues: Hard to scale specific parts independently.

GraphQL in a Microservice World

Microservices break down an application into smaller, independent services. Each service can have its own data and API.

When each microservice exposes its own GraphQL schema, clients would need to know about and query multiple endpoints. This adds complexity for the frontend.

Stitching vs. Federation: A Quick Look

You might hear about GraphQL Federation too. While both unify APIs, they do it differently.

  • Stitching: Combines existing schemas, often ideal for integrating legacy or third-party APIs.
  • Federation: Designed for building new microservices from scratch, where each service contributes parts of a single, unified graph.

This lesson focuses on Stitching.

The Stitching Process: An Overview

Think of a "stitching gateway" or "API Gateway". This gateway acts as a single entry point for clients.

It fetches schemas from individual backend services (called "sub-schemas") and then combines them into one "unified schema" that clients interact with. The gateway then delegates queries to the correct sub-schema.

Imagining Sub-Schemas

Let's say we have two services:

  • User Service: Manages user profiles.
  • Product Service: Manages product listings.

Each exposes its own GraphQL schema:

# User Service Schema
type Query {
  user(id: ID!): User
}
type User {
  id: ID!
  name: String
  email: String
}

# Product Service Schema
type Query {
  product(id: ID!): Product
}
type Product {
  id: ID!
  name: String
  price: Float
}

Combining Query & Mutation Types

The stitching gateway merges the root Query and Mutation types from all sub-schemas into a single root Query and Mutation type for the unified schema.

So, a client can query user(id: "1") AND product(id: "101") from the same endpoint.

Connecting Related Data

What if a User needs to know about their Product orders? Stitching allows you to extend types. For example, the Product Service could extend the User type to add an orders field.

The gateway handles resolving this, by first querying the User Service for the user, then using that user's ID to query the Product Service for their orders.

Why Stitching is Great

Schema stitching offers several advantages:

  • Unified API: One endpoint for all your services.
  • Modularity: Teams can build and deploy services independently.
  • Flexibility: Easily integrate third-party APIs or legacy systems.
  • Frontend Simplicity: Clients don't need to know about backend service boundaries.

Stitching Fundamentals Check

You've learned the core concepts of GraphQL Schema Stitching. Let's test your understanding!

Stitching Up What We Learned

In this lesson, we explored Schema Stitching, a powerful technique to combine multiple GraphQL APIs into a single, unified API gateway. We saw how it helps manage microservices and simplifies the client experience by providing one endpoint for diverse data sources.

Next, we'll dive into the practical implementation of merging multiple GraphQL schemas in a Spring Boot environment.

よくある質問

「Schema Stitchingの基礎」レッスンは無料ですか?

はい。「Schema Stitchingの基礎」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、GraphQL APIs with Spring Bootコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 GraphQL APIs with Spring Bootコースには全4レッスンが含まれています。

「Schema Stitchingの基礎」で何を学びますか?

異なるサービスから統合されたGraphQL APIを構成するSchema Stitchingの原則について学びます。 ブラウザで直接実行するハンズオンコードでGraphQL APIs with Spring Bootを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

GraphQL APIs with Spring Bootを始めるのに経験は必要ですか?

事前経験は必要ありません。CoddyKitのGraphQL APIs with Spring Bootは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン2/4です。

「Schema Stitchingの基礎」レッスンにはどのくらい時間がかかりますか?

ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。

このGraphQL APIs with Spring Bootレッスンでコードを書いて実行できますか?

はい。すべてのGraphQL APIs with Spring Bootレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。

このコースのすべてのレッスン

  1. カスタムDirectiveの構築
  2. Schema Stitchingの基礎
  3. 複数のGraphQLスキーマの統合
  4. 型拡張によるスキーマのモジュール化
← GraphQL APIs with Spring Bootに戻る