Skip to content

Fix variable usage in cypher query #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/neo4j-graphql-binding.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 1 addition & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
"name": "neo4j-graphql-binding",
"version": "1.2.0",
"description": "A GraphQL binding for your Neo4j GraphQL API.",
"main": "dist/index.js",
"main": "src/index.js",
"author": "Michael D Graham (michaeldgrahams@gmail.com)",
"repository": "michaeldgraham/neo4j-graphql-binding",
"scripts": {
"build": "babel src --out-dir dist"
},
"keywords": [
"neo4j",
Expand All @@ -22,14 +21,9 @@
"license": "MIT",
"dependencies": {
"apollo-link": "^1.2.2",
"babel-runtime": "^6.26.0",
"cuid": "^2.1.1",
"graphql": "^0.13.2",
"graphql-binding": "^2.1.1",
"graphql-tools": "^3.0.4"
},
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-plugin-transform-runtime": "^6.23.0"
}
}
9 changes: 4 additions & 5 deletions src/binding.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { Binding } from 'graphql-binding';
import { makeRemoteExecutableSchema } from 'graphql-tools';
import { neo4jGraphQLLink } from './link.js';
import { buildTypeDefs } from './typedefs.js';
const{ Binding } = require('graphql-binding');
const { makeRemoteExecutableSchema } = require('graphql-tools');
const { neo4jGraphQLLink } = require('./link.js');

export const Neo4jGraphQLBinding = class Neo4jGraphQLBinding extends Binding {
exports.Neo4jGraphQLBinding = class Neo4jGraphQLBinding extends Binding {
constructor({ typeDefs, driver, log, indexConfig }) {
super({
schema: makeRemoteExecutableSchema({
Expand Down
24 changes: 12 additions & 12 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { parse, print } from 'graphql';
import { getModelFieldMaps } from './link.js';
import { Neo4jGraphQLBinding } from './binding.js';
import { buildTypeDefs, buildOperationMap, buildTypeMaps, buildResolvers } from './typedefs.js';
const { parse, print } = require('graphql');
const { getModelFieldMaps } = require('./link.js');
const { Neo4jGraphQLBinding } = require('./binding.js');
const { buildTypeDefs, buildOperationMap, buildTypeMaps, buildResolvers } = require('./typedefs.js');

export const neo4jAssertConstraints = async ({ driver, typeDefs, log }) => {
exports.neo4jAssertConstraints = async ({ driver, typeDefs, log }) => {
if(driver && typeDefs) {
const constraints = buildAssertionArguments(typeDefs);
const session = driver.session();
return await session
.run(`CALL apoc.schema.assert({indexes}, {constraints}) YIELD label, key, unique, action RETURN { label: label, key: key, unique: unique, action: action }`, {
.run(`CALL apoc.schema.assert($indexes, $constraints) YIELD label, key, unique, action RETURN { label: label, key: key, unique: unique, action: action }`, {
indexes: {},
constraints: constraints
})
Expand All @@ -22,7 +22,7 @@ export const neo4jAssertConstraints = async ({ driver, typeDefs, log }) => {
});
}
};
export const neo4jIDL = async ({ driver, typeDefs, log }) => {
exports.neo4jIDL = async ({ driver, typeDefs, log }) => {
if(driver && typeDefs) {
const cleanedTypeDefs = cleanCypherStatements(typeDefs);
const remoteTypeDefs = buildTypeDefs({
Expand All @@ -33,7 +33,7 @@ export const neo4jIDL = async ({ driver, typeDefs, log }) => {
});
const session = driver.session();
return await session
.run(`CALL graphql.idl({schema}) YIELD value RETURN value`, {schema: remoteTypeDefs})
.run(`CALL graphql.idl($schema) YIELD value RETURN value`, {schema: remoteTypeDefs})
.then(function (result) {
if(log) logIDLResult(result);
return result;
Expand All @@ -44,10 +44,10 @@ export const neo4jIDL = async ({ driver, typeDefs, log }) => {
});
}
};
export const neo4jGraphQLBinding = (config) => {
exports.neo4jGraphQLBinding = (config) => {
return new Neo4jGraphQLBinding(config);
};
export const neo4jExecute = (params, ctx, info, binding) => {
exports.neo4jExecute = (params, ctx, info, binding) => {
if(typeof binding !== "string") binding = "neo4j";
switch(info.parentType.name) {
case "Query": {
Expand All @@ -62,8 +62,8 @@ export const neo4jExecute = (params, ctx, info, binding) => {
}
throw Error(`Unsupported value for parentType.name`);
}
export const buildNeo4jTypeDefs = buildTypeDefs;
export const buildNeo4jResolvers = buildResolvers;
exports.buildNeo4jTypeDefs = buildTypeDefs;
exports.buildNeo4jResolvers = buildResolvers;
const buildAssertionArguments = (typeDefs) => {
const parsed = parse(typeDefs);
const models = buildTypeMaps(parsed).models;
Expand Down
13 changes: 7 additions & 6 deletions src/link.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { ApolloLink, Observable } from 'apollo-link';
import { print, parse } from 'graphql';
import { buildTypeMaps, buildOperationMap, getFieldType } from './typedefs.js';
const { ApolloLink, Observable } = require('apollo-link');
const { print, parse } = require('graphql');
const { buildTypeMaps, buildOperationMap, getFieldType } = require('./typedefs.js');
const cuid = require('cuid');

export const neo4jGraphQLLink = ({ typeDefs, driver, log=false, indexConfig }) => {
exports.neo4jGraphQLLink = ({ typeDefs, driver, log=false, indexConfig }) => {
const parsed = parse(typeDefs);
const generatedMutations = getGeneratedMutations(parsed);
const modelMap = buildModelMap(parsed);
Expand All @@ -25,7 +25,7 @@ export const neo4jGraphQLLink = ({ typeDefs, driver, log=false, indexConfig }) =
});
});
};
export const getModelFieldMaps = (fields) => {
const getModelFieldMaps = (fields) => {
let relationMap = {};
let propertyMap = {};
let listMap = {};
Expand Down Expand Up @@ -54,7 +54,8 @@ export const getModelFieldMaps = (fields) => {
uniqueProperties: uniqueProperties,
listMap: listMap
};
}
};
exports.getModelFieldMaps = getModelFieldMaps;

const getOperationType = (operation) => {
// After the binding delegates, the operation definition
Expand Down
31 changes: 19 additions & 12 deletions src/typedefs.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { parse, print } from 'graphql';
const { parse, print } = require('graphql');

export const buildTypeDefs = ({
exports.buildTypeDefs = ({
typeDefs,
query=true,
mutation=true,
Expand Down Expand Up @@ -98,7 +98,7 @@ export const buildTypeDefs = ({
});
return print(parsed);
}
export const buildResolvers = ({ typeDefs, resolvers, query, mutation, bindingKey="neo4j" }) => {
exports.buildResolvers = ({ typeDefs, resolvers, query, mutation, bindingKey="neo4j" }) => {
if(typeDefs === undefined) { throw Error(`buildNeo4jResolvers: typeDefs are undefined.`); }
if(resolvers === undefined) { throw Error(`buildNeo4jResolvers: resolvers are undefined.`); }
let augmentedResolvers = {};
Expand Down Expand Up @@ -140,7 +140,7 @@ export const buildResolvers = ({ typeDefs, resolvers, query, mutation, bindingKe
}
return augmentedResolvers;
}
export const getOperationTypes = (parsed) => {
const getOperationTypes = (parsed) => {
const arr = parsed ? parsed.definitions : [];
const len = arr.length;
let i = 0;
Expand All @@ -163,7 +163,8 @@ export const getOperationTypes = (parsed) => {
mutation: mutation
};
};
export const buildRelationalFieldNestedInputTypes = ({ action, modelName, isForRemote }) => {
exports.getOperationTypes = getOperationTypes;
const buildRelationalFieldNestedInputTypes = ({ action, modelName, isForRemote }) => {
const inputs = [];
// TODO only add those you need, check the arity of the value...
switch(action) {
Expand Down Expand Up @@ -374,7 +375,8 @@ export const buildRelationalFieldNestedInputTypes = ({ action, modelName, isForR
}
return inputs;
};
export const buildNestedMutationInputType = ({ action, modelName, modelAST, mutations, isForRemote }) => {
exports.buildRelationalFieldNestedInputTypes = buildRelationalFieldNestedInputTypes
const buildNestedMutationInputType = ({ action, modelName, modelAST, mutations, isForRemote }) => {
// Prevent overwriting any existing mutation of the same name
if(mutations.fieldMap[`${action}${modelName}`] === undefined) {
const inputFields = [];
Expand Down Expand Up @@ -486,7 +488,8 @@ export const buildNestedMutationInputType = ({ action, modelName, modelAST, muta
}
return undefined;
}
export const buildTypeMaps = (parsed) => {
exports.buildNestedMutationInputType = buildNestedMutationInputType;
const buildTypeMaps = (parsed) => {
const arr = parsed ? parsed.definitions : [];
const len = arr.length;
let i = 0;
Expand Down Expand Up @@ -521,7 +524,8 @@ export const buildTypeMaps = (parsed) => {
types: types
};
};
export const buildOperationMap = (parsed) => {
exports.buildTypeMaps = buildTypeMaps;
const buildOperationMap = (parsed) => {
const arr = parsed ? parsed.definitions : [];
const len = arr.length;
let i = 0;
Expand Down Expand Up @@ -551,14 +555,17 @@ export const buildOperationMap = (parsed) => {
mutations: mutations
};
};
export const getNamedType = (definition) => {
exports.buildOperationMap = buildOperationMap;
const getNamedType = (definition) => {
let type = definition.type;
while(type.kind !== "NamedType") type = type.type;
return type;
}
export const getFieldType = (field) => {
};
exports.getNamedType = getNamedType;
const getFieldType = (field) => {
return field ? getNamedType(field).name.value : undefined;
}
};
exports.getFieldType = getFieldType;

const hasDirective = (field, match) => {
const directives = field.directives;
Expand Down