Skip to content

refactor(client): infer request types from TypedDocumentNode - #246

Merged
iamfj merged 3 commits into
nextfrom
issue-194
Jul 2, 2026
Merged

refactor(client): infer request types from TypedDocumentNode#246
iamfj merged 3 commits into
nextfrom
issue-194

Conversation

@iamfj

@iamfj iamfj commented Jul 2, 2026

Copy link
Copy Markdown
Member

What does this PR do?

Changes GraphQLClient.request to accept a TypedDocumentNode<TResult, TVariables> so both the result and variables types are inferred directly from the codegen-generated document, and makes the variables argument optional only for variable-less operations. This removes ~300 lines of redundant explicit generic type arguments across every resolver and service, and lets TypeScript catch mismatched documents, result types, or variables at each call site. Adds the @graphql-typed-document-node/core dependency.

Closes #194

Type of change

  • Bug fix
  • New feature
  • Refactor (no behavior change)
  • Documentation
  • Tests
  • Build / CI

Checklist

  • npm run check:ci passes (lint + format)
  • npx tsc --noEmit passes (type check)
  • npm test passes (unit tests)
  • New code has tests (happy path + primary error case)
  • Commit messages follow Conventional Commits

Testing

npm run check:ci, npx tsc --noEmit, and npm test all pass. No new tests added — this is a type-only refactor with no behavior change, covered by the existing suite.

Notes for reviewers

Type safety now flows from the generated document, so the previous as TResult casts and per-call generics are gone. The one remaining cast is at the rawRequest boundary in graphql-client.ts, which only accepts an untyped variables bag; the public signature stays strongly typed via TypedDocumentNode.

…ntNode

Change GraphQLClient.request to accept a TypedDocumentNode<TResult,
TVariables> so both the result and variables types are inferred from the
generated document. This removes redundant explicit generic type
arguments across resolvers and services and lets TypeScript catch
mismatched documents, result types, and variables at the call site.

Adds the @graphql-typed-document-node/core dependency.

Closes #194
@github-actions

github-actions Bot commented Jul 2, 2026

Copy link
Copy Markdown

✅ knip — no dead code

No unused files, exports, types, or dependencies detected.

iamfj added 2 commits July 2, 2026 22:46
The TypedDocumentNode import is type-only and fully erased at build, and
linearis ships CLI JS only (declaration: false, no published types), so a
consumer never needs the package at runtime. Classify it as a dev
dependency to match reality; revisit if declarations are ever shipped, since
the type surfaces in GraphQLClient.request.

Refs #194
Constrain the variables generic to `Record<string, unknown>` so `variables`
satisfies rawRequest's own bound directly, removing the variables cast and
rejecting untyped documents. Replace the unconditional `data as TResult`
assertion with a null guard so a dataless response throws a clear error
instead of returning a `TResult`-typed `undefined`.

Refs #194
@iamfj
iamfj merged commit 8d2680f into next Jul 2, 2026
12 checks passed
@iamfj
iamfj deleted the issue-194 branch July 2, 2026 20:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

type-architecture: make GraphQLClient.request infer result and variables from TypedDocumentNode

1 participant