Neo4j currently supports the spatial
Pointtype, which can represent both 2D (such as latitude and longitude) and 3D (such as x,y,z or latitude, longitude, height) points. Read more about the Point type and associated functions, such as the index-backed distance function in the Neo4j docs.
Point type in SDL
neo4j-graphql.js makes available the
Point type for use in your GraphQL type definitions. You can use it like this:
The GraphQL schema augmentation process will translate the
location field to a
_Neo4jPoint type in the augmented schema.
Point In Queries
Point object type exposes the following fields that can be used in the query selection set:
Point Query Arguments
As part of the GraphQL schema augmentation process point input types are added to the schema and can be used as field arguments. For example if I wanted to find businesses with exact values of longitude and latitude:
However, with Point data the auto-generated filters are likely to be more useful, especially when we consider arbitrary precision.
Point Query Filter
When querying using point data, often we want to find things that are close to other things. For example, what businesses are within 1.5km of me? We can accomplish this using the auto-generated filter argument. For example:
For points using the Geographic coordinate reference system (latitude and longitude)
distance is measured in meters.
Point In Mutations
The schema augmentation process adds mutations for creating, updating, and deleting nodes and relationships, including for setting values for
Point fields using the
For example, to create a new Business node and set the value of the location field:
Note that not all fields of the
_Neo4jPointInput type need to specified. In general, you have the choice of:
- Fields (latitude,longitude or x,y) If the coordinate is specified using the fields
longitudethen the Geographic coordinate reference system will be used. If instead
yfields are used then the coordinate reference system would be Cartesian.
- Number of dimensions You can specify
latitudefor 3D, or
See the Neo4j Cypher docs for more details on the spatial point type.
- Blog post: Working With Spatial Data In Neo4j GraphQL In The Cloud - Serverless GraphQL, Neo4j Aura, and GRANDstack