Neo4j GraphQL 库模式检查器,属性名称用点分隔

问题描述 投票:0回答:1

我使用以下代码来自动内省现有的 Neo4j 模式:

import { toGraphQLTypeDefs } from "@neo4j/introspector";
import fs from "fs";
import neo4j from "neo4j-driver";

const driver = neo4j.driver(
    "neo4j://localhost:7687",
    neo4j.auth.basic("neo4j", "neo4j")
);

const sessionFactory = () => driver.session({ defaultAccessMode: neo4j.session.READ })

async function main() {
    const typeDefs = await toGraphQLTypeDefs(sessionFactory)
    fs.writeFileSync('schema.graphql', typeDefs)
    await driver.close();
}
main()

在现有的 Neo4j 数据库上,它会生成以下内容:

type BaseEntity10 @node(labels: ["BaseEntity", "CompanyType", "CompositeEntity", "Requirable"]) {
    baseEntity16SCompanyTypeOf: [BaseEntity16!]! @relationship(type: "COMPANY_TYPE_OF", direction: IN)
    createdAt: BigInt!
    createdByBaseEntity4S: [BaseEntity4!]! @relationship(type: "CREATED_BY", direction: OUT)
    id: BigInt!
    lowerName: String!
    name: String!
    nameSlug: String!
    properties.lowerNameMonolithic: String!
    properties.lowerNameWhitespace: String!
    status: String!
    system: Boolean!
    updatedAt: BigInt!
    uuid: String!
}

问题在于以下定义:

properties.lowerNameMonolithic: String!
properties.lowerNameWhitespace: String!

https://graphql-toolbox.neo4j.io/ 中,当我尝试构建此架构时,收到错误:

Syntax Error: Unexpected character: ".".
Locations: [{"line":24,"column":12}]

如何正确内省名称以点分隔的现有属性?

neo4j graphql neo4j-graphql-js neo4j-graphql-library
1个回答
0
投票

GraphQL 仅允许在 names 中使用字母数字字符和下划线。

如果您的图形数据模型的属性名称包含特殊符号(例如“.”),您应该考虑更改这些属性名称以符合 GraphQL 要求(例如,“properties_lowerNameMonolithic”而不是“properties.lowerNameMonolithic”)。

© www.soinside.com 2019 - 2024. All rights reserved.