如何使用突变在graphql中使用postgis的点类型坐标信息?

How can I use the point type coordinate information of postgis in graphql using mutations?

我创建了一个 mutation 来将新数据插入到名为 location 的 postgresql 中。列坐标必须接收和存储数据,例如 ST_GeomFromGeoJSON ('{ "type": "Point", "coordinates": [-48.23456,20.12345]}').

但是graphql不行,不知道修改哪里。我认为这是因为我制作的名为 GeoJSONPoint 的标量无法正常工作。如果 graphql 将数据放在上面,你能告诉我如何创建标量吗?

GeoJSONPoint 标量

import { GraphQLScalarType, Kind } from 'graphql';

export const GeoJSONPoint = new GraphQLScalarType({
    name: 'GeoJSONPoint',
    description: 'Geometry scalar type',
    parseValue(value) {
        return value;
    },

    serialize(value) {
        return value;
    },

    parseLiteral(ast) {
        if (ast.kind === Kind.OBJECT) {
            console.log(ast);
            return new Object(ast);
        }
        return null;
    }
});

location.entity

import {
    Column,
    CreateDateColumn,
    Entity,
    JoinColumn,
    ManyToOne,
    PrimaryGeneratedColumn
} from 'typeorm';
import { Location_Group } from './location_group.entity';
import { Geometry } from 'geojson';
import { Field, ID, Int, ObjectType } from '@nestjs/graphql';
import { GeoJSONPoint } from 'src/scalar/geoJSONPoint.scalar';

@ObjectType()
@Entity('location')
export class Location {
    @Field(() => ID)
    @PrimaryGeneratedColumn('increment')
    id: number;

    @Field(() => String)
    @Column({ type: 'varchar' })
    name: string;

    @Field(() => GeoJSONPoint)
    @Column({
        type: 'geometry',
        nullable: true,
        spatialFeatureType: 'Point',
        srid: 4326
    })
    coordinate: Geometry;

    @Field(() => Int)
    @Column({ type: 'int' })
    order_number: number;

    @Field()
    @CreateDateColumn({ type: 'timestamptz' })
    created_at: Date;

    @Field(() => Location_Group)
    @ManyToOne(
        () => Location_Group,
        (location_group) => location_group.location
    )
    @JoinColumn([{ name: 'location_group_id', referencedColumnName: 'id' }])
    location_group: Location_Group;
}

解析器

    @Mutation(() => Location)
    async createLocation(
        @Args('data') data: LocationDataInput
    ): Promise<Location> {
        console.log(data);
        return await this.locationService.setLocation(data);
    }

我解决了这个问题。首先我们将标量中parseLiteral输入的值分成

{type: '', coordinates: []} 

并删除了外键列。