0

I am writing a custom cypher query for mutation using GRAND stack. However, I am having problem accessing the user object stored in Apollo Server's context from the cypher queries I am writing.

So instead of doing this,

createUser(id: String): User
    @cypher(
      statement: "CREATE (u:User {id: $id}) RETURN u"
    )

I would like to do something similar to

createUser: User
    @cypher(
      statement: "CREATE (u:User {id: context.user.id}) RETURN u"
    )

Tony Kim
  • 3
  • 1

1 Answers1

1

The Apollo context is not passed to the cypher query natively. So you have to write the corresponding resolver for your need.

Can you try something like that :

export const typeDefs = `
  ...
  type Mutation {
    ...
    createUser: User  @cypher(statement: "CREATE (u:User {id: context.user.id})  RETURN u")
     ...
  }`

export const resolvers = {
  ...
  Mutation: {
    ...
    createUser(object, params, ctx, resolveInfo) {
      let newParms = params;
      params.context = ctx;
      return neo4jgraphql(object, newParms, ctx, resolveInfo, true);
    }
    ...
  }
}
logisima
  • 7,340
  • 1
  • 18
  • 31