neo4jgraphqlneo4j-graphql-jsneo4j-graphql-library

Neo4j GraphQL library schema instrospector wtih property names separated by a dot


I use the following code in order to automatically introspect the existent Neo4j schema:

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()

On the existent Neo4j database it produces the following:

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

The issue is with the following definitions:

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

In the https://graphql-toolbox.neo4j.io/ when I try to build this schema, I receive the error:

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

How to properly introspect existing properties with names separated by a dot?


Solution

  • GraphQL only allows alphanumeric characters and underscores in names.

    If your graph data model has property names containing special symbols like ".", you should consider changing those property names to conform to the GraphQL requirements (e.g., "properties_lowerNameMonolithic" instead of "properties.lowerNameMonolithic").