UNPKG

graphql-compose-elasticsearch

Version:
81 lines 3.12 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getDistanceCalculationModeFC = exports.getDistanceUnitFC = exports.getGeoPointFC = exports.ElasticGeoPointType = void 0; const graphql_1 = require("graphql"); const utils_1 = require("../../utils"); exports.ElasticGeoPointType = new graphql_1.GraphQLScalarType({ name: 'ElasticGeoPointType', description: (0, utils_1.desc)(` Elastic Search GeoPoint Type. Object format: { "lat" : 52.3760, "lon" : 4.894 }. String format (lat, lon): "52.3760, 4.894". Array GeoJson format (lat, lon): [4.894, 52.3760] `), serialize: (v) => v, parseValue: (v) => v, parseLiteral(ast) { switch (ast.kind) { case graphql_1.Kind.STRING: return ast.value; case graphql_1.Kind.OBJECT: { let lat; let lon; ast.fields.forEach((field) => { if (field.name.value === 'lat') { if (field.value.kind === 'StringValue') { lat = parseFloat(field.value.value); } else if (field.value.kind === 'FloatValue') { lat = field.value.value; } } if (field.name.value === 'lon') { if (field.value.kind === 'StringValue') { lon = parseFloat(field.value.value); } else if (field.value.kind === 'FloatValue') { lon = field.value.value; } } }); return { lat, lon }; } case graphql_1.Kind.LIST: if (ast.values.length === 2) { if (ast.values[0].kind === 'StringValue' && ast.values[1].kind === 'StringValue') { return [parseFloat(ast.values[0].value || '0'), parseFloat(ast.values[1].value || '0')]; } } return null; default: return null; } }, }); function getGeoPointFC(_opts) { return exports.ElasticGeoPointType; } exports.getGeoPointFC = getGeoPointFC; function getDistanceUnitFC(_opts) { return { type: 'String', description: (0, utils_1.desc)(` By default, the distance unit is m (metres) but it can also accept: mi (miles), in (inches), yd (yards), km (kilometers), cm (centimeters), mm (millimeters). `), }; } exports.getDistanceUnitFC = getDistanceUnitFC; function getDistanceCalculationModeFC(_opts) { return { type: 'String', description: (0, utils_1.desc)(` \`sloppy_arc\` (the default) \`arc\` (most accurate) for very large areas like cross continent search. \`plane\` (fastest) for smaller geographical areas like cities or even countries. `), }; } exports.getDistanceCalculationModeFC = getDistanceCalculationModeFC; //# sourceMappingURL=Geo.js.map