graphile-postgis 0.0.1 → 0.1.1

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.
Files changed (83) hide show
  1. package/LICENSE +3 -1
  2. package/PostgisExtensionDetectionPlugin.d.ts +3 -0
  3. package/PostgisExtensionDetectionPlugin.js +28 -0
  4. package/PostgisInflectionPlugin.d.ts +3 -0
  5. package/PostgisInflectionPlugin.js +36 -0
  6. package/PostgisRegisterTypesPlugin.d.ts +3 -0
  7. package/PostgisRegisterTypesPlugin.js +232 -0
  8. package/PostgisVersionPlugin.d.ts +3 -0
  9. package/PostgisVersionPlugin.js +23 -0
  10. package/Postgis_GeometryCollection_GeometriesPlugin.d.ts +3 -0
  11. package/Postgis_GeometryCollection_GeometriesPlugin.js +43 -0
  12. package/Postgis_LineString_PointsPlugin.d.ts +3 -0
  13. package/Postgis_LineString_PointsPlugin.js +40 -0
  14. package/Postgis_MultiLineString_LineStringsPlugin.d.ts +3 -0
  15. package/Postgis_MultiLineString_LineStringsPlugin.js +38 -0
  16. package/Postgis_MultiPoint_PointsPlugin.d.ts +3 -0
  17. package/Postgis_MultiPoint_PointsPlugin.js +38 -0
  18. package/Postgis_MultiPolygon_PolygonsPlugin.d.ts +3 -0
  19. package/Postgis_MultiPolygon_PolygonsPlugin.js +38 -0
  20. package/Postgis_Point_LatitudeLongitudePlugin.d.ts +3 -0
  21. package/Postgis_Point_LatitudeLongitudePlugin.js +43 -0
  22. package/Postgis_Polygon_RingsPlugin.d.ts +3 -0
  23. package/Postgis_Polygon_RingsPlugin.js +49 -0
  24. package/README.md +129 -1
  25. package/constants.d.ts +12 -0
  26. package/constants.js +34 -0
  27. package/esm/PostgisExtensionDetectionPlugin.js +26 -0
  28. package/esm/PostgisInflectionPlugin.js +34 -0
  29. package/esm/PostgisRegisterTypesPlugin.js +227 -0
  30. package/esm/PostgisVersionPlugin.js +21 -0
  31. package/esm/Postgis_GeometryCollection_GeometriesPlugin.js +41 -0
  32. package/esm/Postgis_LineString_PointsPlugin.js +38 -0
  33. package/esm/Postgis_MultiLineString_LineStringsPlugin.js +36 -0
  34. package/esm/Postgis_MultiPoint_PointsPlugin.js +36 -0
  35. package/esm/Postgis_MultiPolygon_PolygonsPlugin.js +36 -0
  36. package/esm/Postgis_Point_LatitudeLongitudePlugin.js +41 -0
  37. package/esm/Postgis_Polygon_RingsPlugin.js +47 -0
  38. package/esm/constants.js +31 -0
  39. package/esm/index.js +33 -0
  40. package/esm/makeGeoJSONType.js +39 -0
  41. package/esm/types.js +1 -0
  42. package/esm/utils.js +47 -0
  43. package/index.d.ts +15 -0
  44. package/index.js +49 -0
  45. package/makeGeoJSONType.d.ts +1 -0
  46. package/makeGeoJSONType.js +42 -0
  47. package/package.json +37 -49
  48. package/types.d.ts +59 -0
  49. package/types.js +2 -0
  50. package/utils.d.ts +5 -0
  51. package/utils.js +53 -0
  52. package/main/PostgisExtensionDetectionPlugin.js +0 -43
  53. package/main/PostgisInflectionPlugin.js +0 -51
  54. package/main/PostgisRegisterTypesPlugin.js +0 -349
  55. package/main/PostgisVersionPlugin.js +0 -35
  56. package/main/Postgis_GeometryCollection_GeometriesPlugin.js +0 -55
  57. package/main/Postgis_LineString_PointsPlugin.js +0 -51
  58. package/main/Postgis_MultiLineString_LineStringsPlugin.js +0 -51
  59. package/main/Postgis_MultiPoint_PointsPlugin.js +0 -51
  60. package/main/Postgis_MultiPolygon_PolygonsPlugin.js +0 -51
  61. package/main/Postgis_Point_LatitudeLongitudePlugin.js +0 -59
  62. package/main/Postgis_Polygon_RingsPlugin.js +0 -64
  63. package/main/constants.js +0 -39
  64. package/main/debug.js +0 -11
  65. package/main/index.js +0 -99
  66. package/main/makeGeoJSONType.js +0 -89
  67. package/main/utils.js +0 -56
  68. package/module/PostgisExtensionDetectionPlugin.js +0 -31
  69. package/module/PostgisInflectionPlugin.js +0 -44
  70. package/module/PostgisRegisterTypesPlugin.js +0 -268
  71. package/module/PostgisVersionPlugin.js +0 -25
  72. package/module/Postgis_GeometryCollection_GeometriesPlugin.js +0 -55
  73. package/module/Postgis_LineString_PointsPlugin.js +0 -53
  74. package/module/Postgis_MultiLineString_LineStringsPlugin.js +0 -51
  75. package/module/Postgis_MultiPoint_PointsPlugin.js +0 -51
  76. package/module/Postgis_MultiPolygon_PolygonsPlugin.js +0 -51
  77. package/module/Postgis_Point_LatitudeLongitudePlugin.js +0 -64
  78. package/module/Postgis_Polygon_RingsPlugin.js +0 -66
  79. package/module/constants.js +0 -30
  80. package/module/debug.js +0 -2
  81. package/module/index.js +0 -34
  82. package/module/makeGeoJSONType.js +0 -79
  83. package/module/utils.js +0 -40
@@ -1,268 +0,0 @@
1
- import { getGISTypeDetails, getGISTypeModifier, getGISTypeName } from "./utils";
2
- import { SQL } from "pg-sql2";
3
- import makeGeoJSONType from "./makeGeoJSONType";
4
-
5
- function identity(input) {
6
- return input;
7
- }
8
-
9
- const plugin = builder => {
10
- builder.hook("build", build => {
11
- const GeoJSON = makeGeoJSONType(build.graphql, build.inflection.builtin("GeoJSON"));
12
- build.addType(GeoJSON);
13
- return build.extend(build, {
14
- getPostgisTypeByGeometryType(pgGISType, subtype, hasZ = false, hasM = false, srid = 0) {
15
- const typeModifier = getGISTypeModifier(subtype, hasZ, hasM, srid);
16
- return this.pgGetGqlTypeByTypeIdAndModifier(pgGISType.id, typeModifier);
17
- },
18
-
19
- pgGISIncludedTypes: [],
20
-
21
- pgGISIncludeType(Type) {
22
- this.pgGISIncludedTypes.push(Type);
23
- }
24
-
25
- });
26
- });
27
- builder.hook("init", (_, build) => {
28
- const {
29
- newWithHooks,
30
- pgIntrospectionResultsByKind: introspectionResultsByKind,
31
- graphql: {
32
- GraphQLInt,
33
- GraphQLNonNull,
34
- GraphQLInterfaceType,
35
- GraphQLObjectType
36
- },
37
- pgRegisterGqlTypeByTypeId,
38
- pgRegisterGqlInputTypeByTypeId,
39
- pgTweaksByTypeIdAndModifer,
40
- getTypeByName,
41
- pgSql: sql,
42
- pg2gql,
43
- pg2GqlMapper,
44
- inflection,
45
- pgGISGraphQLTypesByTypeAndSubtype: constructedTypes,
46
- pgGISGraphQLInterfaceTypesByType: _interfaces,
47
- pgGISGeometryType: GEOMETRY_TYPE,
48
- pgGISGeographyType: GEOGRAPHY_TYPE,
49
- pgGISExtension: POSTGIS,
50
- pgGISIncludeType: includeType
51
- } = build;
52
-
53
- if (!GEOMETRY_TYPE || !GEOGRAPHY_TYPE) {
54
- return _;
55
- }
56
-
57
- debug("PostGIS plugin enabled");
58
- const GeoJSON = getTypeByName(inflection.builtin("GeoJSON"));
59
- const geojsonFieldName = inflection.geojsonFieldName();
60
-
61
- function getGisInterface(type) {
62
- const zmflag = -1; // no dimensional constraint; could be xy/xyz/xym/xyzm
63
-
64
- if (!_interfaces[type.id]) {
65
- _interfaces[type.id] = {};
66
- }
67
-
68
- if (!_interfaces[type.id][zmflag]) {
69
- _interfaces[type.id][zmflag] = newWithHooks(GraphQLInterfaceType, {
70
- name: inflection.gisInterfaceName(type),
71
- fields: {
72
- [geojsonFieldName]: {
73
- type: GeoJSON,
74
- description: "Converts the object to GeoJSON"
75
- },
76
- srid: {
77
- type: new GraphQLNonNull(GraphQLInt),
78
- description: "Spatial reference identifier (SRID)"
79
- }
80
- },
81
-
82
- resolveType(value, _info) {
83
- const Type = constructedTypes[type.id] && constructedTypes[type.id][value.__gisType];
84
- return Type;
85
- },
86
-
87
- description: `All ${type.name} types implement this interface`
88
- }, {
89
- isPgGISInterface: true,
90
- pgGISType: type,
91
- pgGISZMFlag: zmflag
92
- }); // Force creation of all GraphQL types that could be resolved from this interface
93
-
94
- const subtypes = [1, 2, 3, 4, 5, 6, 7];
95
-
96
- for (const subtype of subtypes) {
97
- for (const hasZ of [false, true]) {
98
- for (const hasM of [false, true]) {
99
- const typeModifier = getGISTypeModifier(subtype, hasZ, hasM, 0);
100
- const Type = getGisType(type, typeModifier);
101
- includeType(Type);
102
- }
103
- }
104
- }
105
- }
106
-
107
- return _interfaces[type.id][zmflag];
108
- }
109
-
110
- function getGisDimensionInterface(type, hasZ, hasM) {
111
- const zmflag = (hasZ ? 2 : 0) + (hasM ? 1 : 0); // Equivalent to ST_Zmflag: https://postgis.net/docs/ST_Zmflag.html
112
-
113
- const coords = {
114
- 0: "XY",
115
- 1: "XYM",
116
- 2: "XYZ",
117
- 3: "XYZM"
118
- }[zmflag];
119
-
120
- if (!_interfaces[type.id]) {
121
- _interfaces[type.id] = {};
122
- }
123
-
124
- if (!_interfaces[type.id][zmflag]) {
125
- _interfaces[type.id][zmflag] = newWithHooks(GraphQLInterfaceType, {
126
- name: inflection.gisDimensionInterfaceName(type, hasZ, hasM),
127
- fields: {
128
- [geojsonFieldName]: {
129
- type: GeoJSON,
130
- description: "Converts the object to GeoJSON"
131
- },
132
- srid: {
133
- type: new GraphQLNonNull(GraphQLInt),
134
- description: "Spatial reference identifier (SRID)"
135
- }
136
- },
137
-
138
- resolveType(value, _info) {
139
- const Type = constructedTypes[type.id] && constructedTypes[type.id][value.__gisType];
140
- return Type;
141
- },
142
-
143
- description: `All ${type.name} ${coords} types implement this interface`
144
- }, {
145
- isPgGISDimensionInterface: true,
146
- pgGISType: type,
147
- pgGISZMFlag: zmflag
148
- }); // Force creation of all GraphQL types that could be resolved from this interface
149
-
150
- const subtypes = [1, 2, 3, 4, 5, 6, 7];
151
-
152
- for (const subtype of subtypes) {
153
- const typeModifier = getGISTypeModifier(subtype, hasZ, hasM, 0);
154
- const Type = getGisType(type, typeModifier);
155
- includeType(Type);
156
- }
157
- }
158
-
159
- return _interfaces[type.id][zmflag];
160
- }
161
-
162
- function getGisType(type, typeModifier) {
163
- const typeId = type.id;
164
- const typeDetails = getGISTypeDetails(typeModifier);
165
- const {
166
- subtype,
167
- hasZ,
168
- hasM,
169
- srid
170
- } = typeDetails;
171
- debug(`Getting ${type.name} type ${type.id}|${typeModifier}|${subtype}|${hasZ}|${hasM}|${srid}`);
172
-
173
- if (!constructedTypes[type.id]) {
174
- constructedTypes[type.id] = {};
175
- }
176
-
177
- const typeModifierKey = typeModifier != null ? typeModifier : -1;
178
-
179
- if (!pgTweaksByTypeIdAndModifer[typeId]) {
180
- pgTweaksByTypeIdAndModifer[typeId] = {};
181
- }
182
-
183
- if (!pgTweaksByTypeIdAndModifer[typeId][typeModifierKey]) {
184
- pgTweaksByTypeIdAndModifer[typeId][typeModifierKey] = (fragment, _resolveData) => {
185
- const params = [sql.literal("__gisType"), sql.fragment`${sql.identifier(POSTGIS.namespaceName || "public", "postgis_type_name" // MUST be lowercase!
186
- )}(
187
- ${sql.identifier(POSTGIS.namespaceName || "public", "geometrytype" // MUST be lowercase!
188
- )}(${fragment}),
189
- ${sql.identifier(POSTGIS.namespaceName || "public", "st_coorddim" // MUST be lowercase!
190
- )}(${fragment}::text)
191
- )`, sql.literal("__srid"), sql.fragment`${sql.identifier(POSTGIS.namespaceName || "public", "st_srid" // MUST be lowercase!
192
- )}(${fragment})`, sql.literal("__geojson"), sql.fragment`${sql.identifier(POSTGIS.namespaceName || "public", "st_asgeojson" // MUST be lowercase!
193
- )}(${fragment})::JSON`];
194
- return sql.fragment`(case when ${fragment} is null then null else json_build_object(
195
- ${sql.join(params, ", ")}
196
- ) end)`;
197
- };
198
- }
199
-
200
- const gisTypeKey = typeModifier != null ? getGISTypeName(subtype, hasZ, hasM) : -1;
201
-
202
- if (!constructedTypes[type.id][gisTypeKey]) {
203
- if (typeModifierKey === -1) {
204
- constructedTypes[type.id][gisTypeKey] = getGisInterface(type);
205
- } else if (subtype === 0) {
206
- constructedTypes[type.id][gisTypeKey] = getGisDimensionInterface(type, hasZ, hasM);
207
- } else {
208
- const intType = introspectionResultsByKind.type.find(t => t.name === "int4" && t.namespaceName === "pg_catalog");
209
- const jsonType = introspectionResultsByKind.type.find(t => t.name === "json" && t.namespaceName === "pg_catalog");
210
- constructedTypes[type.id][gisTypeKey] = newWithHooks(GraphQLObjectType, {
211
- name: inflection.gisType(type, subtype, hasZ, hasM, srid),
212
- interfaces: () => [getGisInterface(type), getGisDimensionInterface(type, hasZ, hasM)],
213
- fields: {
214
- [geojsonFieldName]: {
215
- type: GeoJSON,
216
- resolve: (data, _args, _context, _resolveInfo) => {
217
- return pg2gql(data.__geojson, jsonType);
218
- }
219
- },
220
- srid: {
221
- type: new GraphQLNonNull(GraphQLInt),
222
- resolve: (data, _args, _context, _resolveInfo) => {
223
- return pg2gql(data.__srid, intType);
224
- }
225
- }
226
- }
227
- }, {
228
- isPgGISType: true,
229
- pgGISType: type,
230
- pgGISTypeDetails: typeDetails
231
- });
232
- }
233
- }
234
-
235
- return constructedTypes[type.id][gisTypeKey];
236
- }
237
-
238
- debug(`Registering handler for ${GEOGRAPHY_TYPE.id}`);
239
- pgRegisterGqlInputTypeByTypeId(GEOGRAPHY_TYPE.id, () => GeoJSON);
240
- pg2GqlMapper[GEOGRAPHY_TYPE.id] = {
241
- map: identity,
242
- unmap: o => sql.fragment`st_geomfromgeojson(${sql.value(JSON.stringify(o))}::text)::${sql.identifier(POSTGIS.namespaceName || "public", "geography")}`
243
- };
244
- pgRegisterGqlTypeByTypeId(GEOGRAPHY_TYPE.id, (_set, typeModifier) => {
245
- return getGisType(GEOGRAPHY_TYPE, typeModifier);
246
- });
247
- debug(`Registering handler for ${GEOMETRY_TYPE.id}`);
248
- pgRegisterGqlInputTypeByTypeId(GEOMETRY_TYPE.id, () => GeoJSON);
249
- pg2GqlMapper[GEOMETRY_TYPE.id] = {
250
- map: identity,
251
- unmap: o => sql.fragment`st_geomfromgeojson(${sql.value(JSON.stringify(o))}::text)`
252
- };
253
- pgRegisterGqlTypeByTypeId(GEOMETRY_TYPE.id, (_set, typeModifier) => {
254
- return getGisType(GEOMETRY_TYPE, typeModifier);
255
- });
256
- return _;
257
- }, ["PostgisTypes"], ["PgTables"], ["PgTypes"]);
258
- builder.hook("GraphQLSchema", (schema, build) => {
259
- if (!schema.types) {
260
- schema.types = [];
261
- }
262
-
263
- schema.types = [...schema.types, ...build.pgGISIncludedTypes];
264
- return schema;
265
- });
266
- };
267
-
268
- export default plugin;
@@ -1,25 +0,0 @@
1
- const plugin = builder => {
2
- builder.hook("build", build => {
3
- const pkg = require("./../package.json"); // Check dependencies
4
-
5
-
6
- if (!build.versions) {
7
- throw new Error(`Plugin ${pkg.name}@${pkg.version} requires graphile-build@^4.1.0 in order to check dependencies (current version: ${build.graphileBuildVersion})`);
8
- }
9
-
10
- const depends = (name, range) => {
11
- if (!build.hasVersion(name, range)) {
12
- throw new Error(`Plugin ${pkg.name}@${pkg.version} requires ${name}@${range} (${build.versions[name] ? `current version: ${build.versions[name]}` : "not found"})`);
13
- }
14
- };
15
-
16
- depends("graphile-build-pg", "^4.4.0"); // Register this plugin
17
-
18
- build.versions = build.extend(build.versions, {
19
- [pkg.name]: pkg.version
20
- });
21
- return build;
22
- });
23
- };
24
-
25
- export default plugin;
@@ -1,55 +0,0 @@
1
- import { GIS_SUBTYPE } from "./constants";
2
- import { getGISTypeName } from "./utils";
3
-
4
- const plugin = builder => {
5
- builder.hook("GraphQLObjectType:fields", function AddGeometriesToGeometryCollection(fields, build, context) {
6
- const {
7
- scope: {
8
- isPgGISType,
9
- pgGISType,
10
- pgGISTypeDetails
11
- }
12
- } = context;
13
-
14
- if (!isPgGISType || !pgGISTypeDetails || pgGISTypeDetails.subtype !== GIS_SUBTYPE.GeometryCollection) {
15
- return fields;
16
- }
17
-
18
- const {
19
- extend,
20
- pgGISGraphQLInterfaceTypesByType,
21
- graphql
22
- } = build;
23
- const {
24
- hasZ,
25
- hasM
26
- } = pgGISTypeDetails;
27
- const zmflag = (hasZ ? 2 : 0) + (hasM ? 1 : 0); // Equivalent to ST_Zmflag: https://postgis.net/docs/ST_Zmflag.html
28
-
29
- const Interface = pgGISGraphQLInterfaceTypesByType[pgGISType.id][zmflag];
30
-
31
- if (!Interface) {
32
- console.warn("Unexpectedly couldn't find the interface");
33
- return fields;
34
- }
35
-
36
- return extend(fields, {
37
- geometries: {
38
- type: new GraphQLList(Interface),
39
-
40
- resolve(data) {
41
- return data.__geojson.geometries.map(geom => {
42
- return {
43
- __gisType: getGISTypeName(GIS_SUBTYPE[geom.type], hasZ, hasM),
44
- __srid: data.__srid,
45
- __geojson: geom
46
- };
47
- });
48
- }
49
-
50
- }
51
- });
52
- });
53
- };
54
-
55
- export default plugin;
@@ -1,53 +0,0 @@
1
- import { GIS_SUBTYPE } from "./constants";
2
- import { getGISTypeName } from "./utils";
3
-
4
- const plugin = builder => {
5
- builder.hook("GraphQLObjectType:fields", (fields, build, context) => {
6
- const {
7
- scope: {
8
- isPgGISType,
9
- pgGISType,
10
- pgGISTypeDetails
11
- }
12
- } = context;
13
-
14
- if (!isPgGISType || !pgGISTypeDetails || pgGISTypeDetails.subtype !== GIS_SUBTYPE.LineString) {
15
- return fields;
16
- }
17
-
18
- const {
19
- extend,
20
- getPostgisTypeByGeometryType,
21
- graphql: {
22
- GraphQLList
23
- }
24
- } = build;
25
- const {
26
- hasZ,
27
- hasM,
28
- srid
29
- } = pgGISTypeDetails;
30
- const Point = getPostgisTypeByGeometryType(pgGISType, GIS_SUBTYPE.Point, hasZ, hasM, srid);
31
- return extend(fields, {
32
- points: {
33
- type: new GraphQLList(Point),
34
-
35
- resolve(data) {
36
- return data.__geojson.coordinates.map(coord => {
37
- return {
38
- __gisType: getGISTypeName(GIS_SUBTYPE.Point, hasZ, hasM),
39
- __srid: data.__srid,
40
- __geojson: {
41
- type: "Point",
42
- coordinates: coord
43
- }
44
- };
45
- });
46
- }
47
-
48
- }
49
- });
50
- });
51
- };
52
-
53
- export default plugin;
@@ -1,51 +0,0 @@
1
- import { GIS_SUBTYPE } from "./constants";
2
- import { getGISTypeName } from "./utils";
3
-
4
- const plugin = builder => {
5
- builder.hook("GraphQLObjectType:fields", (fields, build, context) => {
6
- const {
7
- scope: {
8
- isPgGISType,
9
- pgGISType,
10
- pgGISTypeDetails
11
- }
12
- } = context;
13
-
14
- if (!isPgGISType || !pgGISTypeDetails || pgGISTypeDetails.subtype !== GIS_SUBTYPE.MultiLineString) {
15
- return fields;
16
- }
17
-
18
- const {
19
- extend,
20
- getPostgisTypeByGeometryType,
21
- graphql: {
22
- GraphQLList
23
- }
24
- } = build;
25
- const {
26
- hasZ,
27
- hasM,
28
- srid
29
- } = pgGISTypeDetails;
30
- const LineString = getPostgisTypeByGeometryType(pgGISType, GIS_SUBTYPE.LineString, hasZ, hasM, srid);
31
- return extend(fields, {
32
- lines: {
33
- type: new GraphQLList(LineString),
34
-
35
- resolve(data) {
36
- return data.__geojson.coordinates.map(coord => ({
37
- __gisType: getGISTypeName(GIS_SUBTYPE.LineString, hasZ, hasM),
38
- __srid: data.__srid,
39
- __geojson: {
40
- type: "LineString",
41
- coordinates: coord
42
- }
43
- }));
44
- }
45
-
46
- }
47
- });
48
- });
49
- };
50
-
51
- export default plugin;
@@ -1,51 +0,0 @@
1
- import { GIS_SUBTYPE } from "./constants";
2
- import { getGISTypeName } from "./utils";
3
-
4
- const plugin = builder => {
5
- builder.hook("GraphQLObjectType:fields", (fields, build, context) => {
6
- const {
7
- scope: {
8
- isPgGISType,
9
- pgGISType,
10
- pgGISTypeDetails
11
- }
12
- } = context;
13
-
14
- if (!isPgGISType || !pgGISTypeDetails || pgGISTypeDetails.subtype !== GIS_SUBTYPE.MultiPoint) {
15
- return fields;
16
- }
17
-
18
- const {
19
- extend,
20
- getPostgisTypeByGeometryType,
21
- graphql: {
22
- GraphQLList
23
- }
24
- } = build;
25
- const {
26
- hasZ,
27
- hasM,
28
- srid
29
- } = pgGISTypeDetails;
30
- const Point = getPostgisTypeByGeometryType(pgGISType, GIS_SUBTYPE.Point, hasZ, hasM, srid);
31
- return extend(fields, {
32
- points: {
33
- type: new GraphQLList(Point),
34
-
35
- resolve(data) {
36
- return data.__geojson.coordinates.map(coord => ({
37
- __gisType: getGISTypeName(GIS_SUBTYPE.Point, hasZ, hasM),
38
- __srid: data.__srid,
39
- __geojson: {
40
- type: "Point",
41
- coordinates: coord
42
- }
43
- }));
44
- }
45
-
46
- }
47
- });
48
- });
49
- };
50
-
51
- export default plugin;
@@ -1,51 +0,0 @@
1
- import { GIS_SUBTYPE } from "./constants";
2
- import { getGISTypeName } from "./utils";
3
-
4
- const plugin = builder => {
5
- builder.hook("GraphQLObjectType:fields", (fields, build, context) => {
6
- const {
7
- scope: {
8
- isPgGISType,
9
- pgGISType,
10
- pgGISTypeDetails
11
- }
12
- } = context;
13
-
14
- if (!isPgGISType || !pgGISTypeDetails || pgGISTypeDetails.subtype !== GIS_SUBTYPE.MultiPolygon) {
15
- return fields;
16
- }
17
-
18
- const {
19
- extend,
20
- getPostgisTypeByGeometryType,
21
- graphql: {
22
- GraphQLList
23
- }
24
- } = build;
25
- const {
26
- hasZ,
27
- hasM,
28
- srid
29
- } = pgGISTypeDetails;
30
- const Polygon = getPostgisTypeByGeometryType(pgGISType, GIS_SUBTYPE.Polygon, hasZ, hasM, srid);
31
- return extend(fields, {
32
- polygons: {
33
- type: new GraphQLList(Polygon),
34
-
35
- resolve(data) {
36
- return data.__geojson.coordinates.map(coord => ({
37
- __gisType: getGISTypeName(GIS_SUBTYPE.Polygon, hasZ, hasM),
38
- __srid: data.__srid,
39
- __geojson: {
40
- type: "Polygon",
41
- coordinates: coord
42
- }
43
- }));
44
- }
45
-
46
- }
47
- });
48
- });
49
- };
50
-
51
- export default plugin;
@@ -1,64 +0,0 @@
1
- import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
-
3
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
4
-
5
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
6
-
7
- import { GIS_SUBTYPE } from "./constants";
8
-
9
- const plugin = builder => {
10
- builder.hook("GraphQLObjectType:fields", (fields, build, context) => {
11
- const {
12
- scope: {
13
- isPgGISType,
14
- pgGISType,
15
- pgGISTypeDetails
16
- }
17
- } = context;
18
-
19
- if (!isPgGISType || !pgGISTypeDetails || pgGISTypeDetails.subtype !== GIS_SUBTYPE.Point) {
20
- return fields;
21
- }
22
-
23
- const {
24
- extend,
25
- graphql: {
26
- GraphQLNonNull,
27
- GraphQLFloat
28
- },
29
- inflection
30
- } = build;
31
- const xFieldName = inflection.gisXFieldName(pgGISType);
32
- const yFieldName = inflection.gisYFieldName(pgGISType);
33
- const zFieldName = inflection.gisZFieldName(pgGISType);
34
- return extend(fields, _objectSpread({
35
- [xFieldName]: {
36
- type: new GraphQLNonNull(GraphQLFloat),
37
-
38
- resolve(data) {
39
- return data.__geojson.coordinates[0];
40
- }
41
-
42
- },
43
- [yFieldName]: {
44
- type: new GraphQLNonNull(GraphQLFloat),
45
-
46
- resolve(data) {
47
- return data.__geojson.coordinates[1];
48
- }
49
-
50
- }
51
- }, pgGISTypeDetails.hasZ ? {
52
- [zFieldName]: {
53
- type: new GraphQLNonNull(GraphQLFloat),
54
-
55
- resolve(data) {
56
- return data.__geojson.coordinates[2];
57
- }
58
-
59
- }
60
- } : {}));
61
- });
62
- };
63
-
64
- export default plugin;
@@ -1,66 +0,0 @@
1
- import { GIS_SUBTYPE } from "./constants";
2
- import { getGISTypeName } from "./utils";
3
-
4
- const plugin = builder => {
5
- builder.hook("GraphQLObjectType:fields", (fields, build, context) => {
6
- const {
7
- scope: {
8
- isPgGISType,
9
- pgGISType,
10
- pgGISTypeDetails
11
- }
12
- } = context;
13
-
14
- if (!isPgGISType || !pgGISTypeDetails || pgGISTypeDetails.subtype !== GIS_SUBTYPE.Polygon) {
15
- return fields;
16
- }
17
-
18
- const {
19
- extend,
20
- getPostgisTypeByGeometryType,
21
- graphql: {
22
- GraphQLList
23
- }
24
- } = build;
25
- const {
26
- hasZ,
27
- hasM,
28
- srid
29
- } = pgGISTypeDetails;
30
- const LineString = getPostgisTypeByGeometryType(pgGISType, GIS_SUBTYPE.LineString, hasZ, hasM, srid);
31
- return extend(fields, {
32
- exterior: {
33
- type: LineString,
34
-
35
- resolve(data) {
36
- return {
37
- __gisType: getGISTypeName(GIS_SUBTYPE.LineString, hasZ, hasM),
38
- __srid: data.__srid,
39
- __geojson: {
40
- type: "LineString",
41
- coordinates: data.__geojson.coordinates[0]
42
- }
43
- };
44
- }
45
-
46
- },
47
- interiors: {
48
- type: new GraphQLList(LineString),
49
-
50
- resolve(data) {
51
- return data.__geojson.coordinates.slice(1).map(coord => ({
52
- __gisType: getGISTypeName(GIS_SUBTYPE.LineString, hasZ, hasM),
53
- __srid: data.__srid,
54
- __geojson: {
55
- type: "LineString",
56
- coordinates: coord
57
- }
58
- }));
59
- }
60
-
61
- }
62
- });
63
- });
64
- };
65
-
66
- export default plugin;