0

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?

Vinnie
  • 35
  • 4

1 Answers1

0

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?

William Lyon
  • 8,371
  • 1
  • 17
  • 22
  • Yup, that was it. I used to wonder how these functions were being called; is it from the augmented schema? (Knew it had to be something simple I was missing). I wish the error message had been more useful though :(. – Vinnie Jul 31 '19 at 22:22