Skip to main content

Query composition

Query composition encourages clients to assemble operations from local, component-owned fragments so data requirements stay close to where data is used.

Practices implemented

Applies to

  • GraphQL clients
  • Client frameworks
  • Code generators and linting tooling

Configuration (suggested defaults)

ParameterDefaultNotes
fragmentColocationrequiredComponents own their fragments by default.
dataMaskingenabledPrevent access to fields not requested by a fragment.
compositionModeautomaticCompose queries from fragments without manual roots.

Implementation notes

  • Encourage fragments to live alongside components that render the data.
  • Assemble operations automatically from fragment dependencies.
  • Mask fields so root query additions do not leak into components.

Cautions

  • Composition must be deterministic to avoid cache churn.
  • Data masking can feel restrictive; provide clear errors and tooling support.
  • Ensure fragments can be statically analyzed for build-time tooling.

Problems addressed