Search code examples
neo4jgraphqlapollograndstack

Why does "run seedDb" fail when I add in relations between nodes moving from graphql to neo4j


I got the demo example from grand-stack and was able to start up graphql, start up the Neo4J sandbox and populate the test database using

npm run seedDb 

However, when I try to write my own data entries to populate into a neo4j database, I cannot get the relation between nodes to work at all. The error message is the most non-useful message (and I believe it is from the apollo client, and is a status code 400 error). I simplified the code to the most simplest case to make it work, and it still does not. Here is the schema.graphql file:

  type Patient {
  id: ID!
  name: String
  reviews: [Review] @relation(name:"WROTE", direction:"OUT")

}

type Review {
  id: ID!
  stars: Int
  text: String
  date: Date
  user: Patient @relation(name: "WROTE", direction: "IN")
}

and here is the seed-mutation.js file:

export default /* GraphQL */ `
  mutation {
    p1: CreatePatient(
      id: "p1", 
      name: "John Doe 1"
    ) {
      id
      name
    } 

   r1: CreateReview(id: "r1", stars: 4, text: "Great IPA selection!", date: { formatted: "2016-01-03"}) {
      id
    }

  ar1: AddUserReviews(from: { id: "p1"}, to: { id: "r1" }) { from {id}}    

  }
`;

When I do "npm run seedDb", this yields the error message:

{ Error: Network error: Response not successful: Received status code 400
    at new ApolloError (/Users/xxxx/Downloads/grand-stack-starter-master/api/node_modules/apollo-client/bundle.esm.js:60:28)
    at Object.error (/Users/xxxx/Downloads/grand-stack-starter-master/api/node_modules/apollo-client/bundle.esm.js:1032:48)
    at notifySubscription (/Users/xxxx/Downloads/grand-stack-starter-master/api/node_modules/zen-observable/lib/Observable.js:134:18)
    at onNotify (/Users/xxxx/Downloads/grand-stack-starter-master/api/node_modules/zen-observable/lib/Observable.js:165:3)
    at SubscriptionObserver.error (/Users/xxxx/Downloads/grand-stack-starter-master/api/node_modules/zen-observable/lib/Observable.js:224:7)
    at /Users/xxxx/Downloads/grand-stack-starter-master/api/node_modules/apollo-link-http/src/httpLink.ts:184:20
    at <anonymous>
    at process._tickDomainCallback (internal/process/next_tick.js:228:7)
  graphQLErrors: [],
  networkError: 
   { ServerError: Response not successful: Received status code 400
    at Object.exports.throwServerError (/Users/xxxx/Downloads/grand-stack-starter-master/api/node_modules/apollo-link-http-common/src/index.ts:114:17)
    at /Users/xxxx/Downloads/grand-stack-starter-master/api/node_modules/apollo-link-http-common/src/index.ts:145:11
    at <anonymous>
    at process._tickDomainCallback (internal/process/next_tick.js:228:7)
     name: 'ServerError',
     response: 
      Response {
        size: 0,
        timeout: 0,
        [Symbol(Body internals)]: [Object],
        [Symbol(Response internals)]: [Object] },
     statusCode: 400,
     result: { errors: [Array] } },
  message: 'Network error: Response not successful: Received status code 400',
  extraInfo: undefined }

I started with multiple complex codes and this is pretty much the most stripped down version. When I run the seedDB command after the seed-mutation.js file was modified to:

export default /* GraphQL */ `
  mutation {
    p1: CreatePatient(
      id: "p1", 
      name: "John Doe 1"
    ) {
      id
      name
    } 

   r1: CreateReview(id: "r1", stars: 4, text: "Great IPA selection!", date: { formatted: "2016-01-03"}) {
      id
    }
  }
`;

the database gets populated, however the two nodes are not connected to each other, as expected (basically, this is the code with the AddUserReviews removed). How do I build the relation between the nodes through using graphql and seedDb? What am I missing?


Solution

  • You can use GraphQL Playground to inspect the GraphQL API (in the "Docs" tab):

    GraphQL Playground type definitions

    to ensure the mutations you are calling have the correct name and arguments. From inspecting the schema, it looks like instead of AddUserReviews, you want AddPatientReviews?