Multiple Queries/Mutation in Apollo 2.1

后端 未结 6 522
滥情空心
滥情空心 2021-02-05 12:10

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

I have the following problems:

  1. I
6条回答
  •  醉梦人生
    2021-02-05 12:47

    edit 2019/08/24 from the Apollo docs:

    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 = () => (
      
        {({ loading: loadingOne, data: { one } }) => (
          
            {({ loading: loadingTwo, data: { two }}) => {
              if (loadingOne || loadingTwo) return loading...
              return 

    {one} is less than {two}

    }}
    )}
    );

    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.

提交回复
热议问题