RealComposer
Data & Payload Slimming

GraphQL Fragments

Direct Definition

GraphQL fragments are named, reusable sets of fields you embed in queries and mutations so multiple operations share the same selection shape. Fragments keep client queries DRY, align codegen output across screens, and make it easier for gateways to recognize consistent field lists when slimming upstream responses.

Technical Architecture & Deep-Dive

Without fragments, every screen duplicates nested field lists for types like User or Order. A fragment on User with id, name, and avatar centralizes that shape; queries spread it with ...UserFields.

Fragments also power typed client libraries: each fragment becomes a typed mask so components request only what they render. At the edge, a BFF can map fragment names to allowlists, stripping anything outside registered fragments before responses reach bandwidth-constrained mobile clients.

Key Architectural Benefits

Reuses field selections across queries and mutations.
Keeps generated clients aligned with shared UI shapes.
Supports edge allowlists tied to known fragment definitions.

Shared User Fragment

graphql
fragment UserFields on User {
  id
  name
  avatarUrl
}

query Profile {
  me {
    ...UserFields
    email
  }
}
REALCOMPOSER EDGE WORKSPACE

Implement GraphQL Fragments at the Edge

Deploy lightweight API aggregation, edge caching, and secret injection in minutes without Docker containers or complex servers.

START BUILDING FREE

Frequently Asked Questions

Q:Are fragments the same as GraphQL directives?

No. Fragments select fields. Directives such as @include attach runtime behavior to fields or operations.

Related Architecture Concepts

Ready-to-Use Edge Recipes