refactor: extract browser-safe core from graphql-codegen into graphql-query#762
Merged
pyramation merged 3 commits intomainfrom Mar 1, 2026
Merged
Conversation
…-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
Contributor
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
refactor: extract browser-safe core from graphql-codegen into graphql-query
Summary
Moves the pure-function query generation core from
@constructive-io/graphql-codegeninto@constructive-io/graphql-query(the original upstream runtime package). Codegen now depends ongraphql-queryfor 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-helperscore/ast.ts,core/custom-ast.ts,core/query-builder.tsclient/—TypedDocumentString, error handling,executetypes/—CleanTable,CleanField,QueryOptions, introspection types, etc.introspect/—infer-tables,transform,transform-schema,schema-querymeta-object/—convert,validateutils—stripSmartCommentsKept in codegen (Node.js-only):
All 301 codegen tests + 18 query tests pass. Both packages build clean.
Updates since last revision
Rewrote
graphql-queryREADME to showcase only the new generators API (removed old QueryBuilder fluent API section):buildSelect→ mutation generators, each with developer code and generated GraphQL outputbuildSelectwithfieldSelection.include— demonstrates automatic hasMany Connection wrapping (nodes { ... }withfirst: 20) vs direct belongsTo nesting'minimal','all','full') and custom selection (select,exclude,include)buildFindOneandbuildCountexamples with generated outputQueryBuilderstandalone example and its mention from the OverviewReview & Testing Checklist for Human
@constructive-io/graphql-query. Check that no exports are missing by comparing the old file's exports vs. the shim's named exports — especiallycore/types.ts,generators/select.ts, andcore/introspect/transform-schema.ts. A missing re-export would be a silent breaking change for downstream consumers.FieldSelection→QueryFieldSelection,SelectionOptions→QuerySelectionOptions,IntrospectionSchema→QueryIntrospectionSchemain the query package'stypes/core.ts. The codegen shims re-export with original names, but verify no directgraphql-queryconsumers use the old names.inflektandajvare in query'spackage.json: The moved files depend oninflekt(naming helpers, AST) andajv(meta-object/validate). These must be declared dependencies in the query package, not just hoisted from the monorepo.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 actualclient/module.pnpm -C graphql/codegen run generateagainst 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
eslint.config.jsfiles). Lint validation was not performed on the new code.GraphQLErrorre-export was removed fromtypes/core.tsto avoid collision withclient/error.ts. Consumers importingGraphQLErrorfrom the types may be affected.Link to Devin run: https://app.devin.ai/sessions/cc15c94da78646f28f931048c542c26f
Requested by: @pyramation