Skip to content

refactor: extract browser-safe core from graphql-codegen into graphql-query#762

Merged
pyramation merged 3 commits intomainfrom
devin/1772321843-refactor-codegen-to-use-graphql-query
Mar 1, 2026
Merged

refactor: extract browser-safe core from graphql-codegen into graphql-query#762
pyramation merged 3 commits intomainfrom
devin/1772321843-refactor-codegen-to-use-graphql-query

Conversation

@pyramation
Copy link
Contributor

@pyramation pyramation commented Mar 1, 2026

refactor: extract browser-safe core from graphql-codegen into graphql-query

Summary

Moves the pure-function query generation core from @constructive-io/graphql-codegen into @constructive-io/graphql-query (the original upstream runtime package). Codegen now depends on graphql-query for the core logic and re-exports everything via thin shims for backward compatibility.

Modules moved to graphql-query:

  • generators/buildSelect, buildFindOne, buildCount, mutations, field-selector, naming-helpers
  • core/ast.ts, core/custom-ast.ts, core/query-builder.ts
  • client/TypedDocumentString, error handling, execute
  • types/CleanTable, CleanField, QueryOptions, introspection types, etc.
  • introspect/infer-tables, transform, transform-schema, schema-query
  • meta-object/convert, validate
  • utilsstripSmartComments

Kept in codegen (Node.js-only):

  • CLI, file output, watch mode, config, Babel codegen templates, React Query hooks, database connection, schema source fetching

All 301 codegen tests + 18 query tests pass. Both packages build clean.

Updates since last revision

Rewrote graphql-query README to showcase only the new generators API (removed old QueryBuilder fluent API section):

  • Quick Start workflow: introspect schema → buildSelect → mutation generators, each with developer code and generated GraphQL output
  • Nested Relations section showing buildSelect with fieldSelection.include — demonstrates automatic hasMany Connection wrapping (nodes { ... } with first: 20) vs direct belongsTo nesting
  • Field Selection section with proper presets ('minimal', 'all', 'full') and custom selection (select, exclude, include)
  • buildFindOne and buildCount examples with generated output
  • Relation field mapping (aliases), type-safe execution, error handling, and server-aware naming sections
  • Architecture diagram and full API reference tables
  • Removed old QueryBuilder standalone example and its mention from the Overview

Review & Testing Checklist for Human

  • Verify re-export shim completeness: Each codegen shim file re-exports from @constructive-io/graphql-query. Check that no exports are missing by comparing the old file's exports vs. the shim's named exports — especially core/types.ts, generators/select.ts, and core/introspect/transform-schema.ts. A missing re-export would be a silent breaking change for downstream consumers.
  • Check type renames don't break consumers: FieldSelectionQueryFieldSelection, SelectionOptionsQuerySelectionOptions, IntrospectionSchemaQueryIntrospectionSchema in the query package's types/core.ts. The codegen shims re-export with original names, but verify no direct graphql-query consumers use the old names.
  • Verify inflekt and ajv are in query's package.json: The moved files depend on inflekt (naming helpers, AST) and ajv (meta-object/validate). These must be declared dependencies in the query package, not just hoisted from the monorepo.
  • Spot-check README examples against actual API: The README examples (especially createGraphQLClient, execute, DataError, parseGraphQLError) are hand-written illustrations — verify these exports actually exist and the function signatures match the real code. The error handling and client sections reference APIs that may have different names or shapes in the actual client/ module.
  • Spot-check pnpm-lock.yaml changes: The lockfile has large diffs (many dependency removals). Verify these are benign deduplication from adding the workspace dependency, not accidental removal of required deps.
  • Test codegen CLI end-to-end: Run pnpm -C graphql/codegen run generate against a test schema to verify the full pipeline works with the new dependency chain. Unit tests pass but don't cover the full CLI → introspect → generate → write files flow.

Notes

  • Lint checks failed for both packages (pre-existing issue: no eslint.config.js files). Lint validation was not performed on the new code.
  • The GraphQLError re-export was removed from types/core.ts to avoid collision with client/error.ts. Consumers importing GraphQLError from the types may be affected.
  • Related issue: https://github.com/constructive-io/constructive-planning/issues/651

Link to Devin run: https://app.devin.ai/sessions/cc15c94da78646f28f931048c542c26f
Requested by: @pyramation

…-query

Move the pure-function query generation core (generators, AST builders,
naming helpers, introspection utilities, client layer, types) from
graphql-codegen into graphql-query as the canonical source.

graphql-codegen now depends on graphql-query and re-exports all moved
modules via thin shims for full backward compatibility.

Modules moved to graphql-query:
- generators/ (buildSelect, buildFindOne, buildCount, mutations, field-selector, naming-helpers)
- core/ast.ts, core/custom-ast.ts, core/query-builder.ts
- client/ (TypedDocumentString, error handling, execute)
- types/ (CleanTable, CleanField, QueryOptions, introspection, etc.)
- introspect/ (infer-tables, transform, transform-schema, schema-query)
- meta-object/ (convert, validate)
- utils (stripSmartComments)

Kept in codegen (Node.js-only):
- CLI entry points, file output, watch mode, config loading
- Babel codegen templates, React Query hook generation
- Database connection, schema source fetching

Both packages build clean, all 301 codegen tests + 18 query tests pass.

Related: constructive-io/constructive-planning#651
@devin-ai-integration
Copy link
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

Show developer code alongside generated GraphQL output for:
- Quick start (introspect → buildSelect → mutations)
- QueryBuilder fluent API (existing example preserved)
- FindOne and Count queries
- Field selection, relation aliases, type-safe execution
- Error handling with DataError
- Server-aware naming helpers
- Architecture diagram and API reference tables
…I examples

- Remove standalone QueryBuilder example (old API)
- Add 'Nested Relations' section showing buildSelect with fieldSelection.include
- Show automatic hasMany Connection wrapping vs direct belongsTo nesting
- Update Field Selection section with proper presets (minimal/all/full) and custom selection
@pyramation pyramation merged commit ed871c1 into main Mar 1, 2026
45 checks passed
@pyramation pyramation deleted the devin/1772321843-refactor-codegen-to-use-graphql-query branch March 1, 2026 02:20
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.

1 participant