graphql 为什么我需要在解析器参数中声明一个额外的参数

graphql why do I need to declare a extra parameter within a resolvers parameter

我到处都在阅读有关 graphql 的内容,但在解析器函数中陷入了误解实现:

这是我的错误解析器,我得到的是一个未定义的参数:

const jobResolvers = {
   Query: {
     job(id) {
       //code where I call the db ODM function
     }
   }
 }

看了几个 post 我修正了它: (了解析构函数部分,但不明白为什么下划线_参数)

const jobResolvers = {
  Query: {
    job(_,{id}) {
      //code where I call the db ODM function
     }
   }
 }

在这里你可以看到这两个非常好的解释post 不幸的是他们没有解释,为什么它们是解析器函数中的两个参数这是个大问题)

GraphQL 解析器具有特定的函数签名。 resolver(obj, args, context) 你想使用 args,所以你需要填充 obj 以便正确传递参数。通常人们使用 _ 来表示人们不需要但必须在那里满足签名的参数。

http://graphql.org/learn/execution/#root-fields-resolvers