Skip to content

Commit 7a44740

Browse files
committed
fix(graphile-postgis): detect PostGIS when only geography codecs are present
Previously, PostgisExtensionDetectionPlugin required a geometry codec to detect PostGIS. Databases that use only geography columns (e.g. all DataPostGIS nodes with use_geography: true) would not have a geometry codec introspected, causing PostGIS detection to silently fail and geography columns to be omitted from the GraphQL schema with warnings: Do not know how to convert PgCodec 'geography' into a GraphQL type Changes: - detect-extension.ts: Accept either geometry OR geography codec - detect-extension.ts: Extract schemaName from geography codec when geometry is absent - types.ts: Make geometryCodec nullable (PgCodec | null) - connection-filter-operators.ts: Handle null geometryCodec in codec pairs - within-distance-operator.ts: Handle null geometryCodec in codec pairs
1 parent 5e7eeca commit 7a44740

4 files changed

Lines changed: 23 additions & 9 deletions

File tree

graphile/graphile-postgis/src/plugins/connection-filter-operators.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import 'graphile-build';
2+
import 'graphile-build-pg';
23
import 'graphile-connection-filter';
4+
import type { PgCodec } from '@dataplan/pg';
35
import type {
46
ConnectionFilterOperatorFactory,
57
ConnectionFilterOperatorRegistration,
@@ -225,7 +227,10 @@ export function createPostgisOperatorFactory(): ConnectionFilterOperatorFactory
225227
geography: []
226228
};
227229

228-
const codecPairs: [string, typeof geometryCodec][] = [['geometry', geometryCodec]];
230+
const codecPairs: [string, PgCodec][] = [];
231+
if (geometryCodec) {
232+
codecPairs.push(['geometry', geometryCodec]);
233+
}
229234
if (geographyCodec) {
230235
codecPairs.push(['geography', geographyCodec]);
231236
}

graphile/graphile-postgis/src/plugins/detect-extension.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,17 @@ export const PostgisExtensionDetectionPlugin: GraphileConfig.Plugin = {
4343
schemaName = pg.schemaName || 'public';
4444
} else if (pg.name === 'geography') {
4545
geographyCodec = codec;
46+
if (!geometryCodec) {
47+
schemaName = pg.schemaName || 'public';
48+
}
4649
}
4750
}
4851

49-
// PostGIS requires at least the geometry codec to be present.
50-
// Geography is optional — not all databases use geography columns,
51-
// so PostGraphile may not introspect the geography type at all.
52-
if (!geometryCodec) {
52+
// PostGIS is detected when at least one of geometry or geography
53+
// codecs is present. Some databases use only geography columns
54+
// (e.g. use_geography: true in DataPostGIS), so PostGraphile may
55+
// introspect geography but not geometry.
56+
if (!geometryCodec && !geographyCodec) {
5357
return build;
5458
}
5559

graphile/graphile-postgis/src/plugins/within-distance-operator.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import 'graphile-build';
2+
import 'graphile-build-pg';
23
import 'graphile-connection-filter';
4+
import type { PgCodec } from '@dataplan/pg';
35
import type {
46
ConnectionFilterOperatorFactory,
57
ConnectionFilterOperatorRegistration,
@@ -57,7 +59,10 @@ export function createWithinDistanceOperatorFactory(): ConnectionFilterOperatorF
5759
geography: []
5860
};
5961

60-
const codecPairs: [string, typeof geometryCodec][] = [['geometry', geometryCodec]];
62+
const codecPairs: [string, PgCodec][] = [];
63+
if (geometryCodec) {
64+
codecPairs.push(['geometry', geometryCodec]);
65+
}
6166
if (geographyCodec) {
6267
codecPairs.push(['geography', geographyCodec]);
6368
}

graphile/graphile-postgis/src/types.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ export interface GisFieldValue {
2323
export interface PostgisExtensionInfo {
2424
/** The schema name where PostGIS is installed (e.g. 'public') */
2525
schemaName: string;
26-
/** The geometry codec from the registry */
27-
geometryCodec: PgCodec;
28-
/** The geography codec from the registry (optional — not all databases use geography columns) */
26+
/** The geometry codec from the registry (null if only geography columns are used) */
27+
geometryCodec: PgCodec | null;
28+
/** The geography codec from the registry (null if only geometry columns are used) */
2929
geographyCodec: PgCodec | null;
3030
}
3131

0 commit comments

Comments
 (0)