Javascript Graphql参数传递

Javascript Graphql参数传递,javascript,graphql,Javascript,Graphql,嘿,伙计们,我刚刚开始学习如何使用react/graphql编写代码,我很难理解参数传递是如何工作的。在下面的代码示例中,我不知道resolve函数何时填充参数edge和conn。有人能告诉我一些细节吗 export function connectionFromUrls( name: string, prop: string, type: GraphQLOutputType ): GraphQLFieldConfig<*, *> { const {connectio

嘿,伙计们,我刚刚开始学习如何使用react/graphql编写代码,我很难理解参数传递是如何工作的。在下面的代码示例中,我不知道resolve函数何时填充参数edge和conn。有人能告诉我一些细节吗

export function connectionFromUrls(
  name: string,
  prop: string,
  type: GraphQLOutputType
): GraphQLFieldConfig<*, *> {
  const {connectionType} = connectionDefinitions({
    name,
    nodeType: type,
    resolveNode: edge => getObjectFromUrl(edge.node),
    connectionFields: () => ({
      totalCount: {
        type: GraphQLInt,
        resolve: conn => conn.totalCount,
        description:
`A count of the total number of objects in this connection, ignoring pagination.
This allows a client to fetch the first five objects by passing "5" as the
argument to "first", then fetch the total count so it could display "5 of 83",
for example.`
      },
      [prop]: {
        type: new GraphQLList(type),
        resolve: conn => conn.edges.map(edge => getObjectFromUrl(edge.node)),
        description:
`A list of all of the objects returned in the connection. This is a convenience
field provided for quickly exploring the API; rather than querying for
"{ edges { node } }" when no edge data is needed, this field can be be used
instead. Note that when clients like Relay need to fetch the "cursor" field on
the edge to enable efficient pagination, this shortcut cannot be used, and the
full "{ edges { node } }" version should be used instead.`
      }
    })
  });
  return {
    type: connectionType,
    args: connectionArgs,
    resolve: (obj, args) => {
      const array = obj[prop] || [];
      return {
        ...connectionFromArray(array, args),
        totalCount: array.length
      };
    },
  };
}

GraphQL执行器在处理查询时调用resolve函数。作为开发人员,您不必管理执行者的行为;您唯一的目标是在resolve函数中指定字段返回的内容。关于executor,您只需要知道它递归地调用每个字段,直到它到达查询树的所有分支,并将解析的对象向下传递到层次结构

定义GraphQL类型时,需要指定它们所具有的字段、每个字段返回的类型(例如,类型用户有一个名为address的字段,可以是address等类型),以及一个响应查询而执行的解析函数。resolve函数的第一个参数始终是父对象;在本例中,conn.实际上,edge被传递给resolveNode,这是一种处理连接边的自定义方法,但这超出了本问题的范围