Skip to content

feat: consolidate codegen test helper + runtime deep path#1023

Merged
pyramation merged 9 commits intomainfrom
devin/1776760093-codegen-test-helper-and-runtime
Apr 27, 2026
Merged

feat: consolidate codegen test helper + runtime deep path#1023
pyramation merged 9 commits intomainfrom
devin/1776760093-codegen-test-helper-and-runtime

Conversation

@pyramation
Copy link
Copy Markdown
Contributor

@pyramation pyramation commented Apr 21, 2026

Summary

Three packaging consolidations that emerged from the PR #934 refactoring work:

#1 — Move runCodegenAndLoad into @constructive-io/graphql-test

The codegen test helper (introspect → infer tables → generate ORM → compile TS → load createClient) was duplicated between orm-test and constructive-db. This PR:

  • Adds graphql/test/src/codegen-helper.ts with a version that supports both positional (GraphQLQueryFn) and object-style (GraphQLQueryFnObj) query signatures
  • Re-exports getDbConnections and related types from pgsql-test for two-phase test patterns
  • Updates all 4 orm-test suites to import from @constructive-io/graphql-test
  • Deletes the local orm-test/__tests__/helpers/codegen-helper.ts

#2 — Add @constructive-io/graphql-query/runtime deep path module

Generated ORM code currently imports from 3 separate runtime packages (@0no-co/graphql.web, gql-ast, @constructive-io/graphql-types). This PR consolidates two of the three:

  • Adds graphql/query/src/runtime/index.ts that re-exports @0no-co/graphql.web (parseType, print) and @constructive-io/graphql-types (GraphQLAdapter, GraphQLError, QueryResult)
  • Adds @0no-co/graphql.web and @constructive-io/graphql-types as explicit dependencies of graphql-query (they were previously only transitive)
  • Updates query-builder.ts template: parseType/print now import from @constructive-io/graphql-query/runtime
  • Updates orm-client.ts template: GraphQLAdapter/GraphQLError/QueryResult types now import from @constructive-io/graphql-query/runtime
  • gql-ast is intentionally not re-exported — import * as t from 'gql-ast' stays as-is to avoid polluting the t namespace
  • Updates snapshot + assertion in client-generator.test.ts
  • Deep path import works via dist-folder publishing (publishConfig.directory: "dist") — no exports map needed, per Constructive standard

#3 — Replace require.resolve hack with deep path import for generateOrm

The codegen-helper previously used a fragile require.resolve + path.join hack to reach into @constructive-io/graphql-codegen internals for generateOrm. This PR replaces it with a clean deep path import:

  • codegen-helper.ts now uses import { generateOrm } from '@constructive-io/graphql-codegen/core/codegen/orm' — a standard deep path import that works via dist-folder publishing
  • Removes the CJS-only require.resolve + require() + as any pattern that had no type safety
  • cli-e2e.test.ts already used deep path imports (@constructive-io/graphql-codegen/core/codegen/cli and core/codegen/orm) — no change needed there

Updates since last revision

  1. Removed exports map anti-pattern — per the Constructive publishing standard, the exports field should never be used. Dist-folder publishing (publishConfig.directory: "dist") makes deep nested imports work naturally. Removed exports and typesVersions from graphql-codegen/package.json and exports from graphql-query/package.json. Reverted cli-e2e.test.ts and codegen-helper.ts to use deep path imports (e.g. @constructive-io/graphql-codegen/core/codegen/orm) instead of sub-path exports.

Review & Testing Checklist for Human

  • Template import change is intentionally breaking for codegen consumers. query-builder.ts and orm-client.ts now import from @constructive-io/graphql-query/runtime instead of @0no-co/graphql.web and @constructive-io/graphql-types. All downstream repos will produce new import paths on next codegen run. Verify they already have @constructive-io/graphql-query as a dependency and that the /runtime deep path resolves correctly with dist-folder publishing.
  • Deep path imports depend on internal directory structure. codegen-helper.ts imports from @constructive-io/graphql-codegen/core/codegen/orm and cli-e2e.test.ts imports from core/codegen/cli and core/codegen/orm. These work via dist-folder publishing but will break if the internal core/codegen/ directory structure changes. Confirm this coupling is acceptable.
  • Arity-based query function detection in codegen-helper.ts: queryFn.length <= 1 to distinguish object-style from positional. Verify this heuristic is correct for all graphile-test query wrappers.
  • Run orm-test and server-test suites against a real DB to confirm the deep path imports resolve correctly end-to-end (CI covers this, but worth watching).

Notes

  • gql-ast remains a direct import in query-builder.ts (import * as t from 'gql-ast') — this is intentional to keep the t namespace clean. The runtime module consolidates the other two runtime deps only.
  • The pnpm-lock.yaml diff is mostly formatting noise from a pnpm version change — the actual dependency changes are just the added workspace deps.
  • No exports map is used anywhere in this PR — all sub-module access uses deep path imports per Constructive's dist-folder publishing standard.

Link to Devin session: https://app.devin.ai/sessions/18879be982854a40abe5c9b915aa4a84
Requested by: @pyramation

#1: Move runCodegenAndLoad into @constructive-io/graphql-test
- New codegen-helper.ts in graphql-test/src/ with full codegen pipeline
- Supports both positional (GraphQLQueryFn) and object-style (GraphQLQueryFnObj)
- Re-exports getDbConnections and types from pgsql-test for two-phase patterns
- orm-test now imports from @constructive-io/graphql-test instead of local copy
- Deleted local orm-test codegen-helper.ts

#2: Add runtime sub-export to @constructive-io/graphql-query
- New graphql-query/src/runtime/index.ts re-exports:
  - parseType, print from @0no-co/graphql.web
  - All gql-ast exports
  - GraphQLAdapter, GraphQLError, QueryResult types from graphql-types
- Updated codegen templates (query-builder.ts, orm-client.ts) to import
  from @constructive-io/graphql-query/runtime instead of 3 separate packages
- Updated codegen test snapshots and assertions to match new import paths
@devin-ai-integration
Copy link
Copy Markdown
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

The runtime sub-export re-exports parseType, print, and type-only symbols.
Using 'import * as t from runtime' would pollute the t namespace with
unrelated symbols. Keep 'import * as t from gql-ast' as-is in templates.
…tion

The cli-e2e tests generate ORM code in /tmp and require the runtime
sub-path. Without an explicit exports map, Node cannot resolve
@constructive-io/graphql-query/runtime. This adds exports for both
the root and ./runtime sub-paths (CJS, ESM, and types).
…lution

The cli-e2e tests spawn child processes in /tmp that need to resolve
@constructive-io/graphql-query/runtime. Adding the package to
resolveNodePaths() so its node_modules path is included in NODE_PATH.
…b-path resolution

The cli-e2e tests spawn child processes that need to resolve
@constructive-io/graphql-query/runtime via NODE_PATH. Adding the
package as a devDependency so pnpm creates a symlink in
server-test/node_modules, making the exports field accessible.
@socket-security
Copy link
Copy Markdown

socket-security Bot commented Apr 21, 2026

All alerts resolved. Learn more about Socket for GitHub.

This PR previously contained dependency changes with security issues that have been resolved, removed, or ignored.

View full report

Add exports field to graphql-codegen package.json with ./orm sub-path
so generateOrm is a stable contract instead of a filesystem crawl.
Update codegen-helper.ts to use clean import from
@constructive-io/graphql-codegen/orm.
…ructive standard

The Constructive dist-folder publishing pattern (publishConfig.directory: dist)
makes deep nested imports work naturally — no exports map needed.

- Remove exports + typesVersions from graphql-codegen/package.json
- Remove exports from graphql-query/package.json
- Revert cli-e2e.test.ts to deep path imports (core/codegen/cli, core/codegen/orm)
- Update codegen-helper.ts to deep path import (core/codegen/orm)
@socket-security
Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Added@​types/​babel__generator@​7.27.01001007280100
Added@​testing-library/​react@​11.2.510010010087100
Added@​testing-library/​jest-dom@​5.11.1010010010089100

View full report

@devin-ai-integration devin-ai-integration Bot changed the title feat: consolidate codegen test helper + runtime sub-export feat: consolidate codegen test helper + runtime deep path Apr 26, 2026
@pyramation pyramation merged commit 88698ea into main Apr 27, 2026
52 checks passed
@pyramation pyramation deleted the devin/1776760093-codegen-test-helper-and-runtime branch April 27, 2026 01:42
Zetazzz pushed a commit to Zetazzz/Constructive that referenced this pull request May 6, 2026
…ate ORM code

PR constructive-io#1023 changed codegen templates to import from
@constructive-io/graphql-query/runtime instead of directly from
@constructive-io/graphql-types and @0no-co/graphql.web.

The SDK packages (constructive-cli, constructive-sdk, constructive-react,
migrate-client) were missing @constructive-io/graphql-query as a dependency,
causing TS2307 'Cannot find module' errors when building regenerated code.

Fix:
- Add @constructive-io/graphql-query: workspace:^ to all 4 SDK package.json
- Regenerate all SDK ORM code with updated codegen templates
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