Apollo 2.1中的多个查询/突变 [英] Multiple Queries/Mutation in Apollo 2.1

查看:81
本文介绍了Apollo 2.1中的多个查询/突变的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用Apollo 2.1中的新查询和突变组件时,我需要一些帮助,尤其是对于多个查询和突变.

I need some help using the new Query and Mutation component in Apollo 2.1, especially with multiple queries and mutations.

我遇到以下问题:

  1. 我有一个graphql请求,它取决于以前的graphql结果,我该如何处理?
  2. 如何在已经有查询的组件中添加两个不同的突变(在我的组件中,我需要执行两个不同的操作)?

推荐答案

编辑2019/08/24 来自阿波罗文档:

用于Apollo Client的新的hooks API是一种更简单的方式来获取数据您的React应用没有渲染道具组件的样板高阶成分(HOC).我们建议对所有新产品使用钩子阿波罗代码向前发展.

The new hooks API for Apollo Client is a simpler way to fetch data in your React app without the boilerplate of render prop components and higher-order components (HOC). We recommend using hooks for all new Apollo code going forward.

原始答案:您应该将它们嵌套.参见以下示例:

original answer: You are supposed to nest them. See this example:

const NumbersWithData = () => (
  <Query query={QueryOne}>
    {({ loading: loadingOne, data: { one } }) => (
      <Query query={QueryTwo}>
        {({ loading: loadingTwo, data: { two }}) => {
          if (loadingOne || loadingTwo) return <span>loading...</span>
          return <h3>{one} is less than {two}</h3>
        }}
      </Query>
    )}
  </Query>
);

为帮助使嵌套易于管理,您可以检查 react-adopt .他们有一个Apollo ToDo App示例,其中结合了一个查询和多个变异.

To help with keeping the nesting manageable, you could check react-adopt. They have an Apollo ToDo App example, where they combine a Query and multiple Mutations.

这篇关于Apollo 2.1中的多个查询/突变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆