Skip to content

Commit 0dccae7

Browse files
authored
Merge pull request #935 from constructive-io/devin/1774858518-fix-postgis-geography-only-detection
fix(graphile-postgis): detect PostGIS when only geography codecs are present
2 parents 5e7eeca + 7a44740 commit 0dccae7

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)