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