diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..e7e9d11 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,2 @@ +# Default ignored files +/workspace.xml diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..28a804d --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..a34d7aa --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/neo4j-graphql-binding.iml b/.idea/neo4j-graphql-binding.iml new file mode 100644 index 0000000..c956989 --- /dev/null +++ b/.idea/neo4j-graphql-binding.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/package.json b/package.json index 82561d9..6625667 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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" } } diff --git a/src/binding.js b/src/binding.js index 210a6ea..7769f7d 100644 --- a/src/binding.js +++ b/src/binding.js @@ -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({ diff --git a/src/index.js b/src/index.js index b462f81..81452c2 100644 --- a/src/index.js +++ b/src/index.js @@ -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 }) @@ -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({ @@ -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; @@ -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": { @@ -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; diff --git a/src/link.js b/src/link.js index c926caa..e7c1622 100644 --- a/src/link.js +++ b/src/link.js @@ -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); @@ -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 = {}; @@ -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 diff --git a/src/typedefs.js b/src/typedefs.js index 4bce3dd..5fd4179 100644 --- a/src/typedefs.js +++ b/src/typedefs.js @@ -1,6 +1,6 @@ -import { parse, print } from 'graphql'; +const { parse, print } = require('graphql'); -export const buildTypeDefs = ({ +exports.buildTypeDefs = ({ typeDefs, query=true, mutation=true, @@ -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 = {}; @@ -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; @@ -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) { @@ -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 = []; @@ -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; @@ -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; @@ -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;