graphile-postgis 2.9.7 → 2.9.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,7 @@
1
1
  import 'graphile-build-pg';
2
2
  import sql from 'pg-sql2';
3
+ import { GIS_SUBTYPE_NAME } from '../constants';
4
+ import { getGISTypeDetails } from '../utils';
3
5
  /**
4
6
  * Map from PostGIS uppercase geometry type names (from geometrytype()) to
5
7
  * our mixed-case format used by resolveType lookups.
@@ -45,6 +47,11 @@ const GIS_TYPE_NORMALIZE = {
45
47
  function normalizeGisType(raw) {
46
48
  return GIS_TYPE_NORMALIZE[raw] ?? raw;
47
49
  }
50
+ function getGeometrySubtypeName(typmod) {
51
+ const { subtype } = getGISTypeDetails(typmod);
52
+ const subtypeName = GIS_SUBTYPE_NAME[subtype];
53
+ return subtypeName && subtypeName !== 'Geometry' ? subtypeName : null;
54
+ }
48
55
  /**
49
56
  * Build a codec for a PostGIS geometry or geography type.
50
57
  *
@@ -168,6 +175,39 @@ export const PostgisCodecPlugin = {
168
175
  event.pgCodec = buildGisCodec('geography', typeNamespace.nspname, type._id, serviceName);
169
176
  return;
170
177
  }
178
+ },
179
+ /**
180
+ * Annotate geometry/geography attributes with their subtype (Point,
181
+ * Polygon, LineString, etc.) decoded from the PostgreSQL type modifier.
182
+ *
183
+ * The atttypmod encodes subtype + SRID + Z/M flags. We decode it with
184
+ * getGISTypeDetails() and store the human-readable subtype name on
185
+ * attribute.extensions.geometrySubtype so the _meta plugin can expose it.
186
+ */
187
+ async pgCodecs_attribute(_info, event) {
188
+ const { pgAttribute, attribute } = event;
189
+ const codecName = attribute.codec?.name;
190
+ if (codecName !== 'geometry' && codecName !== 'geography') {
191
+ return;
192
+ }
193
+ const typmod = pgAttribute.atttypmod;
194
+ // atttypmod of -1 or null means no modifier (unconstrained geometry)
195
+ if (typmod == null || typmod === -1) {
196
+ return;
197
+ }
198
+ try {
199
+ const subtypeName = getGeometrySubtypeName(typmod);
200
+ if (subtypeName) {
201
+ if (!attribute.extensions) {
202
+ attribute.extensions = {};
203
+ }
204
+ attribute.extensions.geometrySubtype = subtypeName;
205
+ }
206
+ }
207
+ catch {
208
+ // If the modifier can't be decoded, silently skip — the column
209
+ // will still work, just without subtype info in _meta.
210
+ }
171
211
  }
172
212
  }
173
213
  }
@@ -41,7 +41,7 @@ export const PostgisExtensionDetectionPlugin = {
41
41
  }
42
42
  // PostGIS is detected when at least one of geometry or geography
43
43
  // codecs is present. Some databases use only geography columns
44
- // (e.g. use_geography: true in DataPostGIS), so PostGraphile may
44
+ // (e.g. use_geography: true in SearchSpatial), so PostGraphile may
45
45
  // introspect geography but not geometry.
46
46
  if (!geometryCodec && !geographyCodec) {
47
47
  return build;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "graphile-postgis",
3
- "version": "2.9.7",
3
+ "version": "2.9.9",
4
4
  "description": "PostGIS support for PostGraphile v5",
5
5
  "author": "Constructive <developers@constructive.io>",
6
6
  "homepage": "https://github.com/constructive-io/constructive",
@@ -46,7 +46,7 @@
46
46
  "graphile-build": "5.0.0",
47
47
  "graphile-build-pg": "5.0.0",
48
48
  "graphile-config": "1.0.0",
49
- "graphile-connection-filter": "^1.3.6",
49
+ "graphile-connection-filter": "^1.3.7",
50
50
  "graphql": "16.13.0",
51
51
  "pg-sql2": "5.0.0",
52
52
  "postgraphile": "5.0.0"
@@ -59,9 +59,9 @@
59
59
  "devDependencies": {
60
60
  "@types/geojson": "^7946.0.14",
61
61
  "@types/node": "^22.19.11",
62
- "graphile-test": "^4.7.6",
62
+ "graphile-test": "^4.7.7",
63
63
  "makage": "^0.3.0",
64
- "pgsql-test": "^4.7.6"
64
+ "pgsql-test": "^4.7.7"
65
65
  },
66
- "gitHead": "0b7edbd088ca9661503c5038134ee15311eac027"
66
+ "gitHead": "d1cfd698f829c6fae346a5004f735acd44519bb7"
67
67
  }
package/plugins/codec.js CHANGED
@@ -6,6 +6,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.PostgisCodecPlugin = void 0;
7
7
  require("graphile-build-pg");
8
8
  const pg_sql2_1 = __importDefault(require("pg-sql2"));
9
+ const constants_1 = require("../constants");
10
+ const utils_1 = require("../utils");
9
11
  /**
10
12
  * Map from PostGIS uppercase geometry type names (from geometrytype()) to
11
13
  * our mixed-case format used by resolveType lookups.
@@ -51,6 +53,11 @@ const GIS_TYPE_NORMALIZE = {
51
53
  function normalizeGisType(raw) {
52
54
  return GIS_TYPE_NORMALIZE[raw] ?? raw;
53
55
  }
56
+ function getGeometrySubtypeName(typmod) {
57
+ const { subtype } = (0, utils_1.getGISTypeDetails)(typmod);
58
+ const subtypeName = constants_1.GIS_SUBTYPE_NAME[subtype];
59
+ return subtypeName && subtypeName !== 'Geometry' ? subtypeName : null;
60
+ }
54
61
  /**
55
62
  * Build a codec for a PostGIS geometry or geography type.
56
63
  *
@@ -174,6 +181,39 @@ exports.PostgisCodecPlugin = {
174
181
  event.pgCodec = buildGisCodec('geography', typeNamespace.nspname, type._id, serviceName);
175
182
  return;
176
183
  }
184
+ },
185
+ /**
186
+ * Annotate geometry/geography attributes with their subtype (Point,
187
+ * Polygon, LineString, etc.) decoded from the PostgreSQL type modifier.
188
+ *
189
+ * The atttypmod encodes subtype + SRID + Z/M flags. We decode it with
190
+ * getGISTypeDetails() and store the human-readable subtype name on
191
+ * attribute.extensions.geometrySubtype so the _meta plugin can expose it.
192
+ */
193
+ async pgCodecs_attribute(_info, event) {
194
+ const { pgAttribute, attribute } = event;
195
+ const codecName = attribute.codec?.name;
196
+ if (codecName !== 'geometry' && codecName !== 'geography') {
197
+ return;
198
+ }
199
+ const typmod = pgAttribute.atttypmod;
200
+ // atttypmod of -1 or null means no modifier (unconstrained geometry)
201
+ if (typmod == null || typmod === -1) {
202
+ return;
203
+ }
204
+ try {
205
+ const subtypeName = getGeometrySubtypeName(typmod);
206
+ if (subtypeName) {
207
+ if (!attribute.extensions) {
208
+ attribute.extensions = {};
209
+ }
210
+ attribute.extensions.geometrySubtype = subtypeName;
211
+ }
212
+ }
213
+ catch {
214
+ // If the modifier can't be decoded, silently skip — the column
215
+ // will still work, just without subtype info in _meta.
216
+ }
177
217
  }
178
218
  }
179
219
  }
@@ -44,7 +44,7 @@ exports.PostgisExtensionDetectionPlugin = {
44
44
  }
45
45
  // PostGIS is detected when at least one of geometry or geography
46
46
  // codecs is present. Some databases use only geography columns
47
- // (e.g. use_geography: true in DataPostGIS), so PostGraphile may
47
+ // (e.g. use_geography: true in SearchSpatial), so PostGraphile may
48
48
  // introspect geography but not geometry.
49
49
  if (!geometryCodec && !geographyCodec) {
50
50
  return build;