Skip to content

fix(codegen): detect pgvector/tsvector via GQL types; use _meta for blueprints#919

Merged
pyramation merged 5 commits intomainfrom
devin/1774643987-optional-introspection-json
Mar 27, 2026
Merged

fix(codegen): detect pgvector/tsvector via GQL types; use _meta for blueprints#919
pyramation merged 5 commits intomainfrom
devin/1774643987-optional-introspection-json

Conversation

@pyramation
Copy link
Copy Markdown
Contributor

@pyramation pyramation commented Mar 27, 2026

Summary

Two related simplifications that reduce reliance on direct Postgres introspection:

1. Codegen: detect pgvector/tsvector via GQL type names, not pgType

PostGraphile's codec plugins already translate PostgreSQL types into distinct GraphQL scalars — vectorVector, tsvectorFullText, geometry/geographyGeoJSON/etc. The codegen can detect these directly from the introspection schema without any additional metadata.

Changes:

  • isEmbeddingField(): Now checks gqlType === 'Vector' (primary) instead of pgType === 'vector' (which never fired). Retains the legacy name.endsWith('embedding') && Float[] heuristic as fallback.
  • isTsvectorField(): Added gqlType === 'FullText' fallback alongside the existing pgType === 'tsvector' check.
  • buildSearchHandler(): Tsvector detection in the search CLI handler now uses gqlType === 'FullText' instead of pgType === 'tsvector'.

What was removed (added earlier in this branch, never shipped):
The branch previously introduced metaFile config, --dump-meta CLI, enrichPgTypesFromMeta, MetaFieldInfo/MetaFieldType types, and associated test files (~630 lines). All removed once we realized GQL type detection makes the entire pgType enrichment machinery unnecessary.

M:N junction key enrichment from _meta remains unchanged — that genuinely requires _meta and is unaffected by this PR.

2. Node-type-registry: replace --introspection with --meta for blueprint type generation

Customers without direct Postgres access can now use the _meta GraphQL query output to generate typed blueprint interfaces. The --meta flag accepts _meta.json in any of these formats:

  • Raw MetaTableInfo[] array
  • { tables: [...] } (MetaSchema wrapper)
  • { data: { _meta: { tables: [...] } } } (full GQL query result)

When --meta is not provided, static fallback types are used — no breakage.

Types renamed from IntrospectionFieldMeta/IntrospectionTableMeta to MetaFieldInfo/MetaTableInfo to align with MetaSchemaPlugin naming.

Review & Testing Checklist for Human

  • FullText scalar assumption: Verify that no PostgreSQL types other than tsvector map to the FullText GraphQL scalar in PostGraphile/TsvectorCodecPlugin. If another type does, isTsvectorField() would produce false positives.
  • Vector scalar requires VectorCodecPlugin: The gqlType === 'Vector' check only works when VectorCodecPlugin is active. Without it, pgvector columns are invisible in the schema entirely (silently dropped), so this should be fine — but worth confirming.
  • --introspection--meta is a breaking flag rename: Verify no CI scripts or docs reference --introspection for generate-types.ts. The package.json script (pnpm generate:types) does not pass it, so this should be safe.
  • No runtime validation on --meta JSON: The parsed JSON is cast to MetaTableInfo[] without schema validation. Malformed input falls through to static fallbacks with a console warning, which is graceful but could silently produce incomplete types if the JSON is almost-but-not-quite right.
  • Test manually: Run codegen against a database with pgvector, tsvector, and PostGIS columns. Verify the generated docs/CLI correctly categorize these fields (embedding, search, geospatial groups) without any _meta or metaFile configuration. Also test pnpm generate:types with and without --meta to confirm both paths produce valid output.

Notes

  • isPostGISField() retains its existing pgType check alongside GQL type pattern matching. The pgType path is effectively dead code (never populated from introspection), but harmless — it would fire if pgType is ever set by another mechanism in the future.
  • Same applies to isTsvectorField() which still has pgType === 'tsvector' as a first check before the FullText fallback.
  • The node-type-registry package has no unit tests (pnpm test exits with "no tests found"). The build passing is the primary verification for the generate-types.ts changes.

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

…PostGIS detection

- Add pgTypesFile config option to GraphQLSDKConfigTarget
- Create enrichPgTypes() to load JSON and merge pgType into Table fields
- Add enrichment step to pipeline after inferTablesFromIntrospection()
- Add FullText GQL scalar fallback to isTsvectorField() detection
- Add --dump-pg-types CLI command to generate pg-types.json from introspection
- Add buildPgTypesMap() and writePgTypesFile() utilities
- Add 17 tests covering enrichment, loading, and dump functions
@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

…proach

- Expand MetaTableInfo to include fields[] with type.pgType from _meta
- Replace enrichPgTypes(PgTypesMap) with enrichPgTypesFromMeta(MetaTableInfo[])
- Rename pgTypesFile -> metaFile in config (full _meta dump, not pgType-specific)
- Rename --dump-pg-types -> --dump-meta in CLI (dumps MetaTableInfo[])
- Pipeline now auto-enriches pgType from _meta in database mode
- metaFile serves as sidecar for file/schemaDir/endpoint modes
- Heuristic fallbacks still work when no _meta is available
- Update all tests to match new API (19 tests passing)
@devin-ai-integration devin-ai-integration Bot changed the title feat(codegen): optional pgTypesFile enrichment for pgvector/tsvector/PostGIS detection feat(codegen): _meta-based pgType enrichment with metaFile sidecar support Mar 27, 2026
… type names

Remove metaFile config, --dump-meta CLI, enrichPgTypesFromMeta/MetaFile,
buildMetaFromTables/writeMetaFile, and all associated tests.

pgvector/tsvector/PostGIS detection now relies entirely on GraphQL type
names from introspection (Vector, FullText, GeoJSON, etc.) — the codec
plugins already translate pg types to distinct GQL scalars, so no _meta
or sidecar file is needed for type detection.

M:N junction key enrichment from _meta remains (genuinely needs it).
@devin-ai-integration devin-ai-integration Bot changed the title feat(codegen): _meta-based pgType enrichment with metaFile sidecar support fix(codegen): detect pgvector/tsvector via GQL type names, not pgType Mar 27, 2026
… blueprint type generation

Customers without direct Postgres access can now use the _meta GraphQL
query output to generate typed blueprint interfaces. The --meta flag
accepts _meta.json in any format: raw TableMeta[], { tables: [...] },
or { data: { _meta: { tables: [...] } } }.

When --meta is not provided, static fallback types are used (no breakage).

Renames IntrospectionFieldMeta/IntrospectionTableMeta to MetaFieldInfo/
MetaTableInfo to align with MetaSchemaPlugin naming.
@devin-ai-integration devin-ai-integration Bot changed the title fix(codegen): detect pgvector/tsvector via GQL type names, not pgType fix(codegen): detect pgvector/tsvector via GQL types; use _meta for blueprints Mar 27, 2026
@pyramation pyramation merged commit b055dd9 into main Mar 27, 2026
44 checks passed
@pyramation pyramation deleted the devin/1774643987-optional-introspection-json branch March 27, 2026 22:14
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