React Apollo 中本地解析器的执行顺序是什么?

What is the execution order of local resolvers in React Apollo?

假设我有以下查询:

query Foo {
  foo {
    bar
    baz
    qux @client
  }
}

还有这些解析器:

Foo: {
  qux: () => {
    console.log("qux");
    return "qux";
  },
  bar: obj => {
    console.log("bar");
    return obj.bar;
  },
  baz: obj => {
    console.log("baz");
    return obj.baz;
  }
}

解析器的执行顺序是取决于查询中的顺序还是相反?

我想通了:没有"resolver order"。顺序仅由查询给出。

如果您 运行 模拟查询,则会记录以下内容:

bar
baz
qux

尽管 qux 是第一个声明的解析器。如果在查询中将 qux @client 向上移动,则只能先记录它,如下所示:

query Foo {
  foo {
    qux @client
    bar
    baz
  }
}

那么日志将是:

qux
bar
baz

当然,此行为可能会因您使用的版本而异。这是我的:

  • @apolo/react-hooks@3.1.3
  • apollo-cache-inmemory@1.6.3
  • apollo-client@2.6.4
  • 阿波罗-link-http@1.5.16
  • graphql@14.5.8
  • graphql-tag@2.10.1