Apollo Server v2 - 未调用 GraphQL 解析器

Apollo Server v2 - GraphQL resolver not being invoked

我是 graphql 世界的新手,我正在尝试使用 Apollo Server v2 设置多个模块化模式和解析器。

我注意到一个奇怪的行为,我的解析器顺序有问题。 在 Object.assign({}, propertiesResolver, agreementsResolver) 行中,不会调用 propertiesResolver 定义的所有解析器,因为它是解析器顺序中的第一个。如果我交换了两组解析器,例如 Object.assign({}, agreementsResolver, propertiesResolver),现在不会调用由 agreementsResolver 定义的解析器。

我是否遗漏了一些关于 graphql 执行的重要细节?

注意:我所有的模式定义和相应的解析器都已正确定义,我觉得我导入东西的顺序有问题。

使用Object.assign时:

Properties in the target object will be overwritten by properties in the sources if they have the same key. Later sources' properties will similarly overwrite earlier ones.

Object.assign 不会执行 深度合并 ,这大概是您所期望的。如果两个来源具有相同的 属性,则只会使用最后一个来源的 属性。所以给定两个对象,如:

const a = {
  Query: {
    foo: () => 'FOO',
  },
}
const b = {
  Query: {
    bar: () => 'BAR',
  },
}

如果您使用 Object.assign 合并它们,生成的对象将有一个 Query 属性 匹配 ab(取决于后面的参数在上面)。为了进行 deep 合并,合并具有相同名称的属性对象,您应该使用现有的解决方案,例如 lodash:

const resolvers = _.merge(a, b)

something similar.