UNPKG

@graphile/postgis

Version:

PostGIS support for PostGraphile

39 lines 1.61 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const constants_1 = require("./constants"); 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.Point) { return fields; } const { extend, graphql: { GraphQLNonNull, GraphQLFloat }, inflection, } = build; const xFieldName = inflection.gisXFieldName(pgGISType); const yFieldName = inflection.gisYFieldName(pgGISType); const zFieldName = inflection.gisZFieldName(pgGISType); return extend(fields, Object.assign({ [xFieldName]: { type: new GraphQLNonNull(GraphQLFloat), resolve(data) { return data.__geojson.coordinates[0]; }, }, [yFieldName]: { type: new GraphQLNonNull(GraphQLFloat), resolve(data) { return data.__geojson.coordinates[1]; }, } }, (pgGISTypeDetails.hasZ ? { [zFieldName]: { type: new GraphQLNonNull(GraphQLFloat), resolve(data) { return data.__geojson.coordinates[2]; }, }, } : {}))); }); }; exports.default = plugin; //# sourceMappingURL=Postgis_Point_LatitudeLongitudePlugin.js.map