From 19b576ffef6a09f435389d096c59c8f387b586c7 Mon Sep 17 00:00:00 2001 From: johnymontana Date: Fri, 15 May 2020 13:23:49 -0600 Subject: [PATCH] Don't include node labels and properties with invalid names Fix #432, #428, #427 --- example/autogenerated/autogen.js | 2 +- src/neo4j-schema/Neo4jSchemaTree.js | 25 ++++++++++++++++++++----- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/example/autogenerated/autogen.js b/example/autogenerated/autogen.js index 047061be..11e8579a 100644 --- a/example/autogenerated/autogen.js +++ b/example/autogenerated/autogen.js @@ -1,6 +1,6 @@ import { makeAugmentedSchema, inferSchema } from '../../src/index'; import { ApolloServer } from 'apollo-server'; -import { v1 as neo4j } from 'neo4j-driver'; +import neo4j from 'neo4j-driver'; const driver = neo4j.driver( process.env.NEO4J_URI || 'bolt://localhost:7687', diff --git a/src/neo4j-schema/Neo4jSchemaTree.js b/src/neo4j-schema/Neo4jSchemaTree.js index d8b78be9..cc2039b1 100644 --- a/src/neo4j-schema/Neo4jSchemaTree.js +++ b/src/neo4j-schema/Neo4jSchemaTree.js @@ -47,12 +47,24 @@ export default class Neo4jSchemaTree { initialize() { const nodeTypeProperties = session => session - .run('CALL db.schema.nodeTypeProperties()') + .run( + `CALL db.schema.nodeTypeProperties() + YIELD nodeType, nodeLabels, propertyName, propertyTypes, mandatory + WITH * + WHERE propertyName =~ "[_A-Za-z][_0-9A-Za-z]*" + AND all(x IN nodeLabels WHERE (x =~ "[A-Za-z][_0-9A-Za-z]*")) + RETURN *` + ) .then(results => results.records.map(rec => rec.toObject())); const relTypeProperties = session => session - .run('CALL db.schema.relTypeProperties()') + .run( + `CALL db.schema.relTypeProperties() + YIELD relType, propertyName, propertyTypes, mandatory + WITH * WHERE propertyName =~ "[_A-Za-z][_0-9A-Za-z]*" OR propertyName IS NULL + RETURN *` + ) .then(results => results.records.map(rec => rec.toObject())); console.log('Initializing your Neo4j Schema'); @@ -73,9 +85,12 @@ export default class Neo4jSchemaTree { const promises = okapiIds.map(okapiId => { const q = ` - MATCH (n)-[r${okapiId}]->(m) - WITH n, r, m LIMIT 10 - RETURN distinct(labels(n)) as from, labels(m) as to + MATCH (n)-[r${okapiId}]->(m) + WITH n, r, m LIMIT 100 + WITH DISTINCT labels(n) AS from, labels(m) AS to + WITH [x IN from WHERE x =~ "[A-Za-z][_0-9A-Za-z]*"] AS from, [x IN to WHERE x =~ "[A-Za-z][_0-9A-Za-z]*"] AS to + WITH from, to WHERE SIZE(from) > 0 AND SIZE(to) > 0 + RETURN from, to `; return withSession(this.driver, this.config.database, s =>