Skip to content
This repository has been archived by the owner on Sep 3, 2021. It is now read-only.

Commit

Permalink
Don't include node labels and properties with invalid names
Browse files Browse the repository at this point in the history
Fix #432, #428, #427
  • Loading branch information
johnymontana committed May 15, 2020
1 parent cef4fff commit 19b576f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
2 changes: 1 addition & 1 deletion example/autogenerated/autogen.js
Original file line number Diff line number Diff line change
@@ -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',
Expand Down
25 changes: 20 additions & 5 deletions src/neo4j-schema/Neo4jSchemaTree.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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 =>
Expand Down

0 comments on commit 19b576f

Please sign in to comment.