Add opt-in schema-scoped PostgreSQL introspection - #2
Draft
Zetazzz wants to merge 8 commits into
Draft
Conversation
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.
What this changes
PostgreSQL introspection currently reads the full catalog even when a service
exposes only a small set of schemas. On databases with large catalogs, most of
that work and result data is unrelated to the generated GraphQL schema.
This PR adds opt-in schema-scoped introspection. It starts from the schemas in
pgService.schemas, recursively retains the catalog objects needed by thoseschemas, and validates the result against the same plan that built the query.
When scoped introspection is omitted or disabled, the service uses the existing
stock query. The stock SQL and the existing parse, cache, watch, registry, and
entity-event lifecycles remain unchanged.
This PR and #3 use the same
pg-introspectionquery-plan API and scopedalgorithm. This PR integrates the feature directly into
PgIntrospectionPlugin; #3 is the hook-based alternative. Only one of the twoPRs should merge.
Configuration
No additional plugin or preset is required. Configuration is keyed by the
nameof an existing entry inpgServices.The preset below is abbreviated:
mainPgServiceandanalyticsPgServicerepresent the existing connection, adaptor, and otherservice settings.
The keys
mainandanalyticsare not fixed names or schema names. Eachkey must match a
pgServices[].name. The matching service'sschemasarray supplies the scoped root schemas, so schemas are not repeated inside
pgScopedIntrospection.falsetrueServices omitted from
pgScopedIntrospectioncontinue to use stockintrospection.
Options
catalogTypes: "all"is the default. It retains types required by thedependency closure plus all types in
pg_catalog. This is the moreconservative compatibility setting.
catalogTypes: "dependency-closure"retains only types reachable from thescoped roots and their dependencies.
capabilityExtensionsexplicitly retains extension metadata even when noretained object currently depends on that extension. It retains the
extension record, not every object owned by the extension.
Extensions required by retained tables, indexes, functions, or support objects
are discovered automatically. They do not need to be repeated in
capabilityExtensions.Schema and dependency behaviour
pgService.schemasranges, multiranges, indexes, inheritance parents, and extension metadata
enter the dependency closure automatically
them
have similar names or belong to the same extension
Fail-fast behaviour
Ownership and execution flow
pg-introspectionpg-introspectionpg-introspectiongraphile-build-pggraphile-build-pggraphile-build-pghas no separate scoped-introspection adapter module. Theremaining Graphile-specific logic lives directly in
PgIntrospectionPlugin:The benefit is a direct integration with no new plugin or hook contract. The
trade-off, and the main review question for this PR, is that the stock plugin
becomes aware of scoped configuration and query selection.
Compatibility and safety
makeIntrospectionQuery()retains its existing public behaviour and exactgenerated SQL; a golden test protects it
entity-event behaviour changes
Validation
pg-introspection: build passed; 46/46 tests passeddangling column types, and types retained in internal lookups
graphile-build-pg: build passed; 23/23 tests passedexecution, cross-schema types and functions, ranges and multiranges, foreign
keys, inheritance, ordinary indexes, and
pg_trgmGIN/GiST indexesgit diff --checkpassed; no format-only changes