neo4j-graphql / neo4j-graphql-js

NOTE: This project is no longer actively maintained. Please consider using the official Neo4j GraphQL Library (linked in README).
Other
609 stars 147 forks source link

Custom Resolver Root Object is always Undefined #421

Open kyeljmd opened 4 years ago

kyeljmd commented 4 years ago

This is my schema.

type Advisor {
  lastName: String
  nickName: String
  companyName: String
  birthDate: String
  titleCode: String
  birthPlace: String
  firstName: String
  number: String
  nationalityCode: String
  genderCode: String
  classificationCode: String
  civilStatusCode: String
  profileTypeCode: String
  middleName: String
  effectiveDate: String
  hash: ID!
  suffixCode: String
  hierarchyUpwards: [HierarchyTree] @neo4j_ignore
}

And I've written my custom resolver

as follows

resolvers = {
  // root entry point to GraphQL service
  Advisor: {
    hierarchyUpwards(advisor, _, ctx, resolveInfo) {
      let session = ctx.driver.session()
      let params = { hash: advisor.hash }
      console.log(advisor)
      let query = ....
      return session.run(query, params)
      .then(result => { return result.records.map(record => {
        return {
               //data conversion
        }
      } )})
    }
  }

My query was working as expected however whenever I perform the advisor.hash it always returns an undefined. and the advisor parameter is always empty.

My configuration was set up as follows

//neo4j-graphql-related stuff
const apolloTypeDef = typeDefs

// Provide resolver functions for your schema fields
const apolloResolvers = resolvers
const execSchema = makeAugmentedSchema({
  typeDefs,
  resolvers,
  config: {Advisor: {exclude: ['hierarchyUpwards']}}
});

const apolloServer = new ApolloServer({
  schema: execSchema,
  typeDefs: apolloTypeDef,
  resolvers: apolloResolvers,
  context:{ driver }});

I need the id of the current object being processed however

 ```console.log(advisor)```

always returns

{}

michaeldgraham commented 3 years ago

https://github.com/neo4j-graphql/neo4j-graphql-js/issues/608