空间类型

空间类型

Neo4j GraphQL 空间类型转换为使用Point在数据库中存储的空间值。在 GraphQL 模式中使用任何这些类型会自动引入运行与这些空间类型相关的查询和变异所需的类型。

Point

Point 类型用于描述 Neo4j 支持的两种地理坐标参考系统

为了在您的模式中使用它,请向模式中的任何其他类型添加一个类型为 Point 的字段,如下所示

type TypeWithPoint {
    location: Point!
}

除了您需要通过 API 查询和操作空间类型所需的输入和输出类型外,Point 类型还会自动添加到您的模式中。

有关筛选选项,请参阅筛选空间类型

类型定义

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

查询和变异

由于 Point 是一个对象类型,因此它在查询和变异中的输入还有一个附加类型。但是,此输入类型与对象类型具有相同的形状

input PointInput {
    latitude: Float!
    longitude: Float!
    height: Float
}

例如,您可以查询具有精确位置的 User

query Users($longitude: Float!, $latitude: Float!) {
    users(where: { location: { longitude: $longitude, latitude: $latitude } }) {
        name
        location {
            longitude
            latitude
        }
    }
}

或者,您可以创建具有如下位置的 User

mutation CreateUsers($name: String!, $longitude: Float!, $latitude: Float!) {
    createUsers(input: [{ name: $name, location: { longitude: $longitude, latitude: $latitude } }]) {
        users {
            name
            location {
                longitude
                latitude
            }
        }
    }
}

CartesianPoint

CartesianPoint 类型用于描述 Neo4j 支持的两种笛卡尔坐标参考系统

要在您的模式中使用它,请向任何类型添加一个类型为 CartesianPoint 的字段,例如在此示例中

type TypeWithCartesianPoint {
    location: CartesianPoint!
}

除了您需要通过 API 查询和操作空间类型所需的输入和输出类型外,CartesianPoint 类型还会自动添加到您的模式中。

有关筛选选项,请参阅筛选空间类型

类型定义

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

查询和变异

由于 CartesianPoint 是一个对象类型,因此它在查询和变异中的输入还有一个附加类型。但是,此输入类型与对象类型具有相同的形状

input CartesianPointInput {
    x: Float!
    y: Float!
    z: Float
}