fix(codegen): detect pgvector/tsvector via GQL types; use _meta for blueprints#919
Merged
pyramation merged 5 commits intomainfrom Mar 27, 2026
Merged
Conversation
…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
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:
|
…onal-introspection-json
…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)
… 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).
… 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.
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.
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 —
vector→Vector,tsvector→FullText,geometry/geography→GeoJSON/etc. The codegen can detect these directly from the introspection schema without any additional metadata.Changes:
isEmbeddingField(): Now checksgqlType === 'Vector'(primary) instead ofpgType === 'vector'(which never fired). Retains the legacyname.endsWith('embedding') && Float[]heuristic as fallback.isTsvectorField(): AddedgqlType === 'FullText'fallback alongside the existingpgType === 'tsvector'check.buildSearchHandler(): Tsvector detection in the search CLI handler now usesgqlType === 'FullText'instead ofpgType === 'tsvector'.What was removed (added earlier in this branch, never shipped):
The branch previously introduced
metaFileconfig,--dump-metaCLI,enrichPgTypesFromMeta,MetaFieldInfo/MetaFieldTypetypes, 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
_metaremains unchanged — that genuinely requires_metaand is unaffected by this PR.2. Node-type-registry: replace
--introspectionwith--metafor blueprint type generationCustomers without direct Postgres access can now use the
_metaGraphQL query output to generate typed blueprint interfaces. The--metaflag accepts_meta.jsonin any of these formats:MetaTableInfo[]array{ tables: [...] }(MetaSchema wrapper){ data: { _meta: { tables: [...] } } }(full GQL query result)When
--metais not provided, static fallback types are used — no breakage.Types renamed from
IntrospectionFieldMeta/IntrospectionTableMetatoMetaFieldInfo/MetaTableInfoto align with MetaSchemaPlugin naming.Review & Testing Checklist for Human
FullTextscalar assumption: Verify that no PostgreSQL types other thantsvectormap to theFullTextGraphQL scalar in PostGraphile/TsvectorCodecPlugin. If another type does,isTsvectorField()would produce false positives.Vectorscalar requires VectorCodecPlugin: ThegqlType === '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→--metais a breaking flag rename: Verify no CI scripts or docs reference--introspectionforgenerate-types.ts. Thepackage.jsonscript (pnpm generate:types) does not pass it, so this should be safe.--metaJSON: The parsed JSON is cast toMetaTableInfo[]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._metaormetaFileconfiguration. Also testpnpm generate:typeswith and without--metato confirm both paths produce valid output.Notes
isPostGISField()retains its existingpgTypecheck 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.isTsvectorField()which still haspgType === 'tsvector'as a first check before the FullText fallback.pnpm testexits with "no tests found"). The build passing is the primary verification for thegenerate-types.tschanges.Link to Devin session: https://app.devin.ai/sessions/c92c3a11450342f8875625a60fa1be28
Requested by: @pyramation