Skip to content

Commit

Permalink
Merge branch 'meniRoy-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
enniel committed Jul 26, 2022
2 parents a1b24be + 95cd700 commit 629f287
Show file tree
Hide file tree
Showing 13 changed files with 51 additions and 84 deletions.
10 changes: 3 additions & 7 deletions src/Bbox.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import { GraphQLScalarType, GraphQLError } from 'graphql';
import { GraphQLScalarType } from 'graphql';
const GJV = require('geojson-validation');

import parseLiteral from './parseLiteral';
import validator from './validator';

const validate = value => {
if (!GJV.isBbox(value)) {
throw new GraphQLError(`Expected GeoJSON Bbox but got: ${JSON.stringify(value)}`);
}
return value;
};
const validate = value => validator(GJV.isBbox,value);

export default new GraphQLScalarType({
name: 'GeoJSONBboxScalar',
Expand Down
10 changes: 3 additions & 7 deletions src/Feature.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import { GraphQLScalarType, GraphQLError } from 'graphql';
import { GraphQLScalarType } from 'graphql';
const GJV = require('geojson-validation');

import parseLiteral from './parseLiteral';
import validator from './validator';

const validate = value => {
if (!GJV.isFeature(value)) {
throw new GraphQLError(`Expected GeoJSON Feature but got: ${JSON.stringify(value)}`);
}
return value;
};
const validate = value => validator(GJV.isFeature,value);

export default new GraphQLScalarType({
name: 'GeoJSONFeatureScalar',
Expand Down
10 changes: 3 additions & 7 deletions src/FeatureCollection.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import { GraphQLScalarType, GraphQLError } from 'graphql';
import { GraphQLScalarType } from 'graphql';
const GJV = require('geojson-validation');

import parseLiteral from './parseLiteral';
import validator from './validator';

const validate = value => {
if (!GJV.isFeatureCollection(value)) {
throw new GraphQLError(`Expected GeoJSON FeatureCollection but got: ${JSON.stringify(value)}`);
}
return value;
};
const validate = value => validator(GJV.isFeatureCollection,value);

export default new GraphQLScalarType({
name: 'GeoJSONFeatureCollectionScalar',
Expand Down
10 changes: 3 additions & 7 deletions src/Geometry.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import { GraphQLScalarType, GraphQLError } from 'graphql';
import { GraphQLScalarType } from 'graphql';
const GJV = require('geojson-validation');

import parseLiteral from './parseLiteral';
import validator from './validator';

const validate = value => {
if (!GJV.isGeometryObject(value)) {
throw new GraphQLError(`Expected GeoJSON Geometry but got: ${JSON.stringify(value)}`);
}
return value;
};
const validate = value => validator(GJV.isGeometryObject,value);

export default new GraphQLScalarType({
name: 'GeoJSONGeometryScalar',
Expand Down
10 changes: 3 additions & 7 deletions src/GeometryCollection.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import { GraphQLScalarType, GraphQLError } from 'graphql';
import { GraphQLScalarType } from 'graphql';
const GJV = require('geojson-validation');

import parseLiteral from './parseLiteral';
import validator from './validator';

const validate = value => {
if (!GJV.isGeometryCollection(value)) {
throw new GraphQLError(`Expected GeoJSON GeometryCollection but got: ${JSON.stringify(value)}`);
}
return value;
};
const validate = value => validator(GJV.isGeometryCollection,value);

export default new GraphQLScalarType({
name: 'GeoJSONGeometryCollectionScalar',
Expand Down
10 changes: 3 additions & 7 deletions src/LineString.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import { GraphQLScalarType, GraphQLError } from 'graphql';
import { GraphQLScalarType } from 'graphql';
const GJV = require('geojson-validation');

import parseLiteral from './parseLiteral';
import validator from './validator';

const validate = value => {
if (!GJV.isLineString(value)) {
throw new GraphQLError(`Expected GeoJSON LineString but got: ${JSON.stringify(value)}`);
}
return value;
};
const validate = value => validator(GJV.isLineString,value);

export default new GraphQLScalarType({
name: 'GeoJSONLineStringScalar',
Expand Down
11 changes: 4 additions & 7 deletions src/MultiLineString.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import { GraphQLScalarType, GraphQLError } from 'graphql';
import { GraphQLScalarType } from 'graphql';
const GJV = require('geojson-validation');

import parseLiteral from './parseLiteral';
import validator from './validator';

const validate = value => validator(GJV.isMultiLineString,value);

const validate = value => {
if (!GJV.isMultiLineString(value)) {
throw new GraphQLError(`Expected GeoJSON MultiLineString but got: ${JSON.stringify(value)}`);
}
return value;
};

export default new GraphQLScalarType({
name: 'GeoJSONMultiLineStringScalar',
Expand Down
11 changes: 4 additions & 7 deletions src/MultiPoint.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import { GraphQLScalarType, GraphQLError } from 'graphql';
import { GraphQLScalarType } from 'graphql';
const GJV = require('geojson-validation');

import parseLiteral from './parseLiteral';
import validator from './validator';

const validate = value => validator(GJV.isMultiPoint,value);

const validate = value => {
if (!GJV.isMultiPoint(value)) {
throw new GraphQLError(`Expected GeoJSON MultiPoint but got: ${JSON.stringify(value)}`);
}
return value;
};

export default new GraphQLScalarType({
name: 'GeoJSONMultiPointScalar',
Expand Down
11 changes: 4 additions & 7 deletions src/MultiPolygon.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import { GraphQLScalarType, GraphQLError } from 'graphql';
import { GraphQLScalarType } from 'graphql';
const GJV = require('geojson-validation');

import parseLiteral from './parseLiteral';
import validator from './validator';

const validate = value => validator(GJV.isMultiPolygon,value);

const validate = value => {
if (!GJV.isMultiPolygon(value)) {
throw new GraphQLError(`Expected GeoJSON MultiPolygon but got: ${JSON.stringify(value)}`);
}
return value;
};

export default new GraphQLScalarType({
name: 'GeoJSONMultiPolygonScalar',
Expand Down
10 changes: 3 additions & 7 deletions src/Point.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import { GraphQLScalarType, GraphQLError } from 'graphql';
import { GraphQLScalarType } from 'graphql';
const GJV = require('geojson-validation');

import parseLiteral from './parseLiteral';
import validator from './validator';

const validate = value => {
if (!GJV.isPoint(value)) {
throw new GraphQLError(`Expected GeoJSON Point but got: ${JSON.stringify(value)}`);
}
return value;
};
const validate = value => validator(GJV.isPoint,value);

export default new GraphQLScalarType({
name: 'GeoJSONPointScalar',
Expand Down
11 changes: 4 additions & 7 deletions src/Polygon.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import { GraphQLScalarType, GraphQLError } from 'graphql';
import { GraphQLScalarType } from 'graphql';
const GJV = require('geojson-validation');

import parseLiteral from './parseLiteral';
import validator from './validator';

const validate = value => validator(GJV.isPolygon,value);

const validate = value => {
if (!GJV.isPolygon(value)) {
throw new GraphQLError(`Expected GeoJSON Polygon but got: ${JSON.stringify(value)}`);
}
return value;
};

export default new GraphQLScalarType({
name: 'GeoJSONPolygonScalar',
Expand Down
11 changes: 4 additions & 7 deletions src/Position.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import { GraphQLScalarType, GraphQLError } from 'graphql';
import { GraphQLScalarType } from 'graphql';
const GJV = require('geojson-validation');

import parseLiteral from './parseLiteral';
import validator from './validator';

const validate = value => validator(GJV.isPosition,value);

const validate = value => {
if (!GJV.isPosition(value)) {
throw new GraphQLError(`Expected GeoJSON Position but got: ${JSON.stringify(value)}`);
}
return value;
};

export default new GraphQLScalarType({
name: 'GeoJSONPositionScalar',
Expand Down
10 changes: 10 additions & 0 deletions src/validator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import {GraphQLError} from 'graphql';

export default (validator, data) => {
validator(data, (isValid, errors) => {
if (!isValid) {
throw new GraphQLError(JSON.stringify(errors));
}
});
return data;
};

0 comments on commit 629f287

Please sign in to comment.