GraphQL APIs with Spring Boot · 강의

엔터티 참조와 @key 지시문

Apollo Federation의 핵심인 서브그래프 간 엔터티 공유 방식을 익히세요. @key 지시문을 사용하고 Spring Boot에서 다른 서브그래프의 참조를 해결하는 방법을 배웁니다.

레슨 4/413개 단계

엔터티 참조와 @key 지시문은(는) CoddyKit의 무료 GraphQL APIs with Spring Boot 강의입니다. 이것은 4개 중 4번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 GraphQL APIs with Spring Boot 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. GraphQL APIs with Spring Boot 강의에는 총 4개의 강의가 포함되어 있습니다.

이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.

Entities Span Subgraphs

In federation, a single type like Product can be owned and extended by several subgraphs. The mechanism that lets them agree on the same object is the entity.

What Makes an Entity

An entity is a type with a @key directive. The key names the field(s) that uniquely identify an instance across subgraphs, like a primary key in a database.

type Product @key(fields: "id") {
  id: ID!
  name: String!
}

The Owning Subgraph

The subgraph that defines a type's core fields is its owner. It is responsible for fetching a full entity given just its key, so the gateway can stitch data together.

Extending an Entity Elsewhere

Another subgraph can add fields to the same entity. It declares the type with the matching @key and marks borrowed fields as external context.

type Product @key(fields: "id") {
  id: ID!
  reviews: [Review!]!
}

The Reference Resolver

When the gateway needs an entity from a subgraph, it calls a special reference resolver, passing only the key fields. The subgraph returns the matching object.

Resolving References in Spring

Spring for GraphQL Federation provides @EntityMapping to implement the reference resolver. The key fields arrive as arguments.

@EntityMapping
public Product product(@Argument String id) {
    return productService.findById(id);
}

Adding the Federation Library

Enable federation by adding the Apollo federation JVM support, which generates the _entities and _service fields the gateway requires.

// build.gradle
implementation 'com.apollographql.federation:federation-graphql-java-support'

Compound Keys

An entity can be identified by multiple fields. List them space-separated in the @key, useful when no single field is unique.

type OrderItem @key(fields: "orderId sku") {
  orderId: ID!
  sku: String!
}

Multiple Keys

A type can declare several @key directives, letting different subgraphs reference it by whichever identifier they hold.

type User @key(fields: "id") @key(fields: "email") {
  id: ID!
  email: String!
}

How the Gateway Stitches Data

The gateway queries the owning subgraph, then sends the entity's keys to other subgraphs via _entities to fetch their extra fields, merging everything into one response.

Best Practices

Design entities carefully:

  • Pick stable, unique key fields
  • One subgraph owns the core fields
  • Keep reference resolvers fast (consider DataLoaders)
  • Use compound keys only when necessary

Quick Check

Test your federation entity knowledge.

Recap

You learned federated entities:

  • An entity is a type with a @key
  • One subgraph owns it; others extend it
  • Reference resolvers (@EntityMapping) fetch by key
  • Compound and multiple keys handle complex identity

Entities and @key are how federation stitches a unified graph from many subgraphs.

무료로 시작

AI 튜터와 함께 GraphQL APIs with Spring Boot을(를) 배우세요 — 무료

브라우저에서 실제 코드를 작성하고 실행하며, 24/7 AI 튜터로부터 즉각적인 도움을 받고, 웹이나 앱에서 중단한 부분부터 계속 학습하세요.

코스
12
레슨
48

자주 묻는 질문

“엔터티 참조와 @key 지시문” 강의는 무료인가요?

네 — “엔터티 참조와 @key 지시문” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 GraphQL APIs with Spring Boot 강의 전체를 잠금 해제할 수 있습니다. GraphQL APIs with Spring Boot 강의에는 총 4개의 강의가 포함되어 있습니다.

“엔터티 참조와 @key 지시문”에서 뭘 배우나요?

Apollo Federation의 핵심인 서브그래프 간 엔터티 공유 방식을 익히세요. @key 지시문을 사용하고 Spring Boot에서 다른 서브그래프의 참조를 해결하는 방법을 배웁니다. 브라우저에서 직접 실행하는 실습 코드로 GraphQL APIs with Spring Boot을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.

GraphQL APIs with Spring Boot을(를) 시작하는 데 경험이 필요한가요?

사전 경험은 필요하지 않습니다. CoddyKit의 GraphQL APIs with Spring Boot은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 4번째 강의입니다.

“엔터티 참조와 @key 지시문” 강의는 얼마나 걸리나요?

대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.

이 GraphQL APIs with Spring Boot 강의에서 코드를 작성하고 실행할 수 있나요?

네. 모든 GraphQL APIs with Spring Boot 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.

이 강의의 모든 강의

  1. Apollo Federation 소개
  2. 페더레이션 서브그래프 구축
  3. 게이트웨이 설정 및 관리
  4. 엔터티 참조와 @key 지시문
← GraphQL APIs with Spring Boot(으)로 돌아가기