UNPKG

@graphile/postgis

Version:

PostGIS support for PostGraphile

34 lines 1.45 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.MultiPoint) { return fields; } const { extend, getPostgisTypeByGeometryType, graphql: { GraphQLList }, } = build; const { hasZ, hasM, srid } = pgGISTypeDetails; const Point = getPostgisTypeByGeometryType(pgGISType, constants_1.GIS_SUBTYPE.Point, hasZ, hasM, srid); return extend(fields, { points: { type: new GraphQLList(Point), resolve(data) { return data.__geojson.coordinates.map((coord) => ({ __gisType: utils_1.getGISTypeName(constants_1.GIS_SUBTYPE.Point, hasZ, hasM), __srid: data.__srid, __geojson: { type: "Point", coordinates: coord, }, })); }, }, }); }); }; exports.default = plugin; //# sourceMappingURL=Postgis_MultiPoint_PointsPlugin.js.map