Temporal types
Spatial Types
Neo4j GraphQL spatial types translate to spatial values stored using Point
in the database.
The use of either of these types in a GraphQL schema automatically introduces the types needed to run queries and mutations relevant to these spatial types.
Point
The Point
type is used to describe the two Geographic coordinate reference systems supported by Neo4j.
In order to use it in your schema, you quite simply add a field with a type Point
to any type or types in schema, like the following:
type TypeWithPoint {
location: Point!
}
Once this has been done, the Point
type is automatically added to your schema, in addition to all of the input and output types you need to query and manipulate spatial types through your API.
These are the automatically generated types and how to use them:
Queries and mutations
Due to the fact that Point
is an object type, it has an additional type for input in queries and mutations.
However, this input type has the same shape as the object type:
input PointInput {
latitude: Float!
longitude: Float!
height: Float
}
For example, you can query for a User
with an exact location:
query Users($longitude: Float!, $latitude: Float!) {
users(where: { location: { longitude: $longitude, latitude: $latitude } }) {
name
location {
longitude
latitude
}
}
}
Or you can create a User
with a location as follows:
mutation CreateUsers($name: String!, $longitude: Float!, $latitude: Float!) {
createUsers(input: [{ name: $name, location: { longitude: $longitude, latitude: $latitude } }]) {
users {
name
location {
longitude
latitude
}
}
}
}
Filtering
Besides the Numerical operators, the Point
type has an additional _DISTANCE
filter.
Here is a list of what each filter does:
-
_LT
: checks that the specifiedPoint
field is less than thedistance
away in meters from thePoint
being compared against. -
_LTE
: checks that the specifiedPoint
field is less than or equal to thedistance
away in meters from thePoint
being compared against. -
_DISTANCE
: checks that the specifiedPoint
field is the exactdistance
away in meters from thePoint
being compared against. -
_GTE
: checks that the specifiedPoint
field is greater than thedistance
away in meters from thePoint
being compared against. -
_GT
: checks that the specifiedPoint
field is greater than or equal to thedistance
away in meters from thePoint
being compared against.
All of the filters take the following type as an argument:
input PointDistance {
point: Point!
distance: Float!
}
In practice, you can construct queries such as the following which can find all users within a 5km (5000m) radius of a Point
:
query CloseByUsers($longitude: Float!, $latitude: Float!) {
users(where: { location_LTE: { point: { longitude: $longitude, latitude: $latitude }, distance: 5000 } }) {
name
location {
longitude
latitude
}
}
}
CartesianPoint
The CartesianPoint
type is used to describe the two Cartesian coordinate reference systems supported by Neo4j.
To use it in the schema, add a field with a type CartesianPoint
to any type or types, such as in this example:
type TypeWithCartesianPoint {
location: CartesianPoint!
}
Once this has been done, the CartesianPoint
type is automatically added to your schema, in addition to all of the input and output types you will need to query and manipulate spatial types through your API.
These are the automatically generated types and how to use them:
Queries and mutations
Due to the fact that CartesianPoint
is an object type, it has an additional type for input in queries and mutations.
However, this input type has the same shape as the object type:
input CartesianPointInput {
x: Float!
y: Float!
z: Float
}
Filtering
Besides the Numerical operators, the CartesianPoint
type has an additional _DISTANCE
filter.
Here is a list of what each filter does:
-
_LT
: checks that the specifiedPoint
field is less than thedistance
away from theCartesianPoint
being compared against, in the units used to specify the points. -
_LTE
: checks that the specifiedPoint
field is less than or equal to thedistance
away from theCartesianPoint
being compared against, in the units used to specify the points. -
_DISTANCE
: checks that the specifiedPoint
field is the exactdistance
away from theCartesianPoint
being compared against, in the units used to specify the points. -
_GTE
: checks that the specifiedPoint
field is greater than thedistance
away from theCartesianPoint
being compared against, in the units used to specify the points. -
_GT
: checks that the specifiedPoint
field is greater than or equal to thedistance
away from theCartesianPoint
being compared against, in the units used to specify the points.
All of the filters take the following type as an argument:
input CartesianPointDistance {
point: CartesianPoint!
distance: Float!
}