This repository has been archived by the owner on Sep 3, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #334 from michaeldgraham/master
Initial spatial support using Point type
- Loading branch information
Showing
15 changed files
with
1,253 additions
and
297 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { GraphQLInt, GraphQLString } from 'graphql'; | ||
import { buildNeo4jTypes } from '../types/types'; | ||
|
||
/** | ||
* An enum describing the name of the Neo4j Point type | ||
*/ | ||
export const SpatialType = { | ||
POINT: 'Point' | ||
}; | ||
|
||
/** | ||
* An enum describing the property names of the Neo4j Point type | ||
* See: https://neo4j.com/docs/cypher-manual/current/syntax/spatial/#cypher-spatial-instants | ||
*/ | ||
const Neo4jPointField = { | ||
X: 'x', | ||
Y: 'y', | ||
Z: 'z', | ||
LONGITUDE: 'longitude', | ||
LATITUDE: 'latitude', | ||
HEIGHT: 'height', | ||
CRS: 'crs', | ||
SRID: 'srid' | ||
}; | ||
|
||
/** | ||
* A map of the Neo4j Temporal Time type fields to their respective | ||
* GraphQL types | ||
*/ | ||
export const Neo4jPoint = { | ||
[Neo4jPointField.X]: GraphQLInt.name, | ||
[Neo4jPointField.Y]: GraphQLInt.name, | ||
[Neo4jPointField.Z]: GraphQLInt.name, | ||
[Neo4jPointField.LONGITUDE]: GraphQLInt.name, | ||
[Neo4jPointField.LATITUDE]: GraphQLInt.name, | ||
[Neo4jPointField.HEIGHT]: GraphQLInt.name, | ||
[Neo4jPointField.CRS]: GraphQLString.name, | ||
[Neo4jPointField.SRID]: GraphQLInt.name | ||
}; | ||
|
||
/** | ||
* The main export for building the GraphQL input and output type definitions | ||
* for Neo4j Temporal property types | ||
*/ | ||
export const augmentSpatialTypes = ({ typeMap, config = {} }) => { | ||
config.spatial = decideSpatialConfig({ config }); | ||
return buildNeo4jTypes({ | ||
typeMap, | ||
neo4jTypes: SpatialType, | ||
config: config.spatial | ||
}); | ||
}; | ||
|
||
/** | ||
* A helper function for ensuring a fine-grained spatial | ||
* configmration | ||
*/ | ||
const decideSpatialConfig = ({ config }) => { | ||
let defaultConfig = { | ||
point: true | ||
}; | ||
const providedConfig = config ? config.spatial : defaultConfig; | ||
if (typeof providedConfig === 'boolean') { | ||
if (providedConfig === false) { | ||
defaultConfig.point = false; | ||
} | ||
} else if (typeof providedConfig === 'object') { | ||
defaultConfig = providedConfig; | ||
} | ||
return defaultConfig; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.