Skip to content

Typed Multi-Operation GraphQL Documents with Amplify Gen 2 Data Client #3166

@RestingState

Description

@RestingState

Environment information

System:
  OS: Windows 11 10.0.26200
  CPU: (16) x64 13th Gen Intel(R) Core(TM) i7-13620H
  Memory: 3.99 GB / 15.73 GB
Binaries:
  Node: 22.22.0 - C:\Users\denys\AppData\Local\mise\installs\node\22.22.0\node.EXE
  Yarn: undefined - undefined
  npm: 10.9.4 - C:\Users\denys\AppData\Local\mise\installs\node\22.22.0\npm.CMD
  pnpm: undefined - undefined
NPM Packages:
  @aws-amplify/auth-construct: 1.11.2
  @aws-amplify/backend: 1.22.0
  @aws-amplify/backend-ai: Not Found
  @aws-amplify/backend-auth: 1.9.3
  @aws-amplify/backend-cli: 1.8.2
  @aws-amplify/backend-data: 1.6.4
  @aws-amplify/backend-function: 1.18.0
  @aws-amplify/backend-output-storage: 1.3.4
  @aws-amplify/backend-secret: 1.4.2
  @aws-amplify/backend-storage: 1.4.3
  @aws-amplify/cli-core: 2.2.4
  @aws-amplify/client-config: 1.10.1
  @aws-amplify/data-construct: 1.17.0
  @aws-amplify/data-schema: 1.22.2
  @aws-amplify/deployed-backend-client: 1.8.1
  @aws-amplify/form-generator: 1.2.6
  @aws-amplify/model-generator: 1.2.2
  @aws-amplify/platform-core: 1.11.0
  @aws-amplify/plugin-types: 1.12.0
  @aws-amplify/sandbox: 2.1.4
  @aws-amplify/schema-generator: 1.4.1
  @aws-cdk/toolkit-lib: 1.16.0
  aws-amplify: 6.16.3
  aws-cdk-lib: 2.235.0
  typescript: 6.0.2
No AWS environment variables
No CDK environment variables

Describe the feature

In Amplify Gen 2, generated queries are type-safe when invoked one at a time, but there is no ergonomic typed way to compose several of them into a single dataClient.graphql call.

GraphQL already allows multiple root-level fields (and, where supported, multiple named operations) in one document so the client issues one network request and the server executes those queries together. To use that today with the typed client, we still have to hand-write a raw GraphQL string. That drops generated typing and makes mistakes in selection sets or variables easier to introduce.

Requested feature:

  • Provide a first-class typed API to combine existing generated query documents into a single document suitable for one dataClient.graphql request (multiple root fields and/or multiple operations, as the schema allows).
  • Preserve full TypeScript types for variables and the combined response shape.
  • Reuse generated query definitions instead of maintaining duplicate handwritten documents.

Potential API shapes (examples):

  • A helper to merge generated documents, e.g. composeQueries(queryA, queryB, queryC).
  • Support for passing an array or object of generated query refs into dataClient.graphql.
  • Any similar API that preserves end-to-end type safety while still issuing a single HTTP request.

Use case

A common GraphQL pattern is to request several independent queries in one round trip—for example loading reference data, multiple list views, or unrelated slices of state that the UI needs together. That keeps latency and connection overhead down compared to firing separate requests per query.

I want to rely on that capability while still using Amplify’s generated, typed queries end to end: one network request, one typed response object, no hand-maintained query strings that drift from the schema.

Without this feature, the choice is either multiple sequential or parallel requests (more round trips) or a single raw graphql document (correct for batching, but not aligned with the generated client’s typings). Typed composition would close that gap for any app that batches reads over GraphQL.

Metadata

Metadata

Assignees

No one assigned

    Labels

    pending-triageIncoming issues that need categorization

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions