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

Basic schema with non nullable property gives error when calling mutation #124

Closed
itaylorweb opened this issue Oct 8, 2018 · 0 comments
Closed

Comments

@itaylorweb
Copy link

itaylorweb commented Oct 8, 2018

Using the following dependencies:

  "dependencies": {
    "apollo-server": "^2.1.0",
    "dotenv": "^6.0.0",
    "neo4j-driver": "^1.6.3",
    "neo4j-graphql-js": "^1.0.2"
  }

This Apollo Server definition:

import { ApolloServer } from 'apollo-server';
import { v1 as neo4j } from 'neo4j-driver';
import { makeAugmentedSchema } from 'neo4j-graphql-js';
import dotenv from 'dotenv';
import { typeDefs } from './gqlSchema/claimSchema';

dotenv.config();

const schema = makeAugmentedSchema({ typeDefs });

const driver = neo4j.driver(
  'bolt://localhost:7687',
  neo4j.auth.basic(process.env.NEO4JUSER, process.env.NEO4JPASS)
);

const server = new ApolloServer({
  schema,
  context: { driver }
});

server.listen(4040, '0.0.0.0').then(({ url }) => {
  console.log(`GraphQL API ready at ${url}`);
});

This type definition:

export const typeDefs = `
  type Incident {
    reference: String!
    circumstances: String
  }
`;

Then in GraphQL Playground (using the auto generated mutation) running:

mutation {
  CreateIncident(reference: "INC1", circumstances: "Some circumstances.") {
    reference
  }
}

I get the following error:

{
  "data": {
    "CreateIncident": null
  },
  "errors": [
    {
      "message": "Cannot read property 'value' of undefined",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "CreateIncident"
      ],
      "extensions": {
        "code": "INTERNAL_SERVER_ERROR",
        "exception": {
          "stacktrace": [
            "TypeError: Cannot read property 'value' of undefined",
            "    at /apollo-server/node_modules/neo4j-graphql-js/dist/index.js:308:53",
            "    at Array.find (native)",
            "    at cypherMutation (/apollo-server/node_modules/neo4j-graphql-js/dist/index.js:307:27)",
            "    at _callee$ (/apollo-server/node_modules/neo4j-graphql-js/dist/index.js:65:31)",
            "    at tryCatch (/apollo-server/node_modules/regenerator-runtime/runtime.js:62:40)",
            "    at Generator.invoke [as _invoke] (/apollo-server/node_modules/regenerator-runtime/runtime.js:296:22)",
            "    at Generator.prototype.(anonymous function) [as next] (/apollo-server/node_modules/regenerator-runtime/runtime.js:114:21)",
            "    at step (/apollo-server/node_modules/babel-runtime/helpers/asyncToGenerator.js:17:30)",
            "    at /apollo-server/node_modules/babel-runtime/helpers/asyncToGenerator.js:35:14",
            "    at new Promise (<anonymous>)"
          ]
        }
      }
    }
  ]
}

If I change reference to ID! instead of String! it works fine. Am I doing something wrong (im new to graphql and neo4j or is there an issue with non nullable properties?

Thanks for any help.

This appears to be the offending part in neo4j-graphql-js: dist/index.js

    var firstIdArg = args.find(function (e) {
      return (0, _graphql.getNamedType)(e).type.name.value; //reference as a NonNullType doesn't have type.name?
    });
    if (firstIdArg) {
      var argName = firstIdArg.name.value;
      if (params.params[argName] === undefined) {
        query += 'SET ' + variableName + '.' + argName + ' = apoc.create.uuid() ';  // this is another issue as it assumes you have apoc installed in neo4j 
      }
    }

console.log(args):

[ { kind: 'InputValueDefinition',
    description: undefined,
    name: { kind: 'Name', value: 'reference', loc: [Object] },
    type: { kind: 'NonNullType', type: [Object], loc: [Object] },
    defaultValue: undefined,
    directives: [],
    loc: { start: 252, end: 270 } },
  { kind: 'InputValueDefinition',
    description: undefined,
    name: { kind: 'Name', value: 'circumstances', loc: [Object] },
    type: { kind: 'NamedType', name: [Object], loc: [Object] },
    defaultValue: undefined,
    directives: [],
    loc: { start: 272, end: 293 } } ]
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant