Spatial types
This is the documentation of the GraphQL Library version 6. For the long-term support (LTS) version 5, refer to GraphQL Library version 5 LTS. |
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, add a field with a type Point
to any other type(s) in your schema, like the following:
type TypeWithPoint @node {
location: Point!
}
The Point
type is automatically added to your schema, in addition to the input and output types that you need to query and manipulate spatial types through your API.
See Filtering spatial types for filter options.
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_EQ: { 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
}
}
}
}
CartesianPoint
The CartesianPoint
type is used to describe the two Cartesian coordinate reference systems supported by Neo4j.
To use it in your schema, add a field with a type CartesianPoint
to any type(s), such as in this example:
type TypeWithCartesianPoint @node {
location: CartesianPoint!
}
The CartesianPoint
type is automatically added to your schema, in addition to the input and output types that you need to query and manipulate spatial types through your API.
See Filtering spatial types for filter options.