【问题标题】:What is the execution order of local resolvers in React Apollo?React Apollo 中本地解析器的执行顺序是什么?
【发布时间】:2019-11-03 23:06:22
【问题描述】:

假设我有以下查询:

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

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

【问题讨论】:

    标签: graphql apollo react-apollo apollo-client


    【解决方案1】:

    我想通了:没有“解析器顺序”。顺序仅由查询给出。

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

    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
    • apollo-link-http@1.5.16
    • graphql@14.5.8
    • graphql-tag@2.10.1

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-10-26
      • 2020-08-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-20
      • 1970-01-01
      相关资源
      最近更新 更多