Spatial 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, add a field with a type Point to any other type(s) in your schema, like the following:

type TypeWithPoint {
    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.

Type definition

type Point {
    latitude: Float!
    longitude: Float!
    height: Float
}

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
            }
        }
    }
}

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 {
    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.

Type definition

type CartesianPoint {
    x: Float!
    y: Float!
    z: Float
}

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
}