UNPKG

@graphile/postgis

Version:

PostGIS support for PostGraphile

47 lines 1.99 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const constants_1 = require("./constants"); const utils_1 = require("./utils"); const plugin = builder => { builder.hook("GraphQLObjectType:fields", (fields, build, context) => { const { scope: { isPgGISType, pgGISType, pgGISTypeDetails }, } = context; if (!isPgGISType || !pgGISTypeDetails || pgGISTypeDetails.subtype !== constants_1.GIS_SUBTYPE.Polygon) { return fields; } const { extend, getPostgisTypeByGeometryType, graphql: { GraphQLList }, } = build; const { hasZ, hasM, srid } = pgGISTypeDetails; const LineString = getPostgisTypeByGeometryType(pgGISType, constants_1.GIS_SUBTYPE.LineString, hasZ, hasM, srid); return extend(fields, { exterior: { type: LineString, resolve(data) { return { __gisType: utils_1.getGISTypeName(constants_1.GIS_SUBTYPE.LineString, hasZ, hasM), __srid: data.__srid, __geojson: { type: "LineString", coordinates: data.__geojson.coordinates[0], }, }; }, }, interiors: { type: new GraphQLList(LineString), resolve(data) { return data.__geojson.coordinates.slice(1).map((coord) => ({ __gisType: utils_1.getGISTypeName(constants_1.GIS_SUBTYPE.LineString, hasZ, hasM), __srid: data.__srid, __geojson: { type: "LineString", coordinates: coord, }, })); }, }, }); }); }; exports.default = plugin; //# sourceMappingURL=Postgis_Polygon_RingsPlugin.js.map