GraphQL自定义解析器根对象为空对象/空

时间:2020-04-30 03:37:55

标签: node.js neo4j graphql apollo-server neo4j-graphql-js

这是我的模式。

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
}

我已经写了我的自定义解析器

如下

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
        }
      } )})
    }
  }

我的查询按预期工作,但是每当执行advisor.hash时,它总是返回未定义的。并且顾问程序参数始终为空。

我的配置设置如下

//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 }});

对我而言,该解析器内部正在处理的对象的当前哈希值有什么办法吗?

0 个答案:

没有答案