React Apollo - Make Multiple Queries

后端 未结 10 1935
渐次进展
渐次进展 2021-01-30 16:36

I have a queries file that looks like this:

import {gql} from \'react-apollo\';

const queries = {
  getApps: gql`
    {
      apps {
        id
        name
            


        
10条回答
  •  走了就别回头了
    2021-01-30 17:25

    Another way around this is to use the props option.

    export default compose(
      graphql(QUERY_2, {
        props: ({ data }) => ({ ...data }),
      }),
      graphql(QUERY_1, {
        props: ({ data }) => ({ ...data, myCustomAttribute: data.foo }),
      }),
    )(Component);
    

    I've found that this approach is a bit nicer for my use case.

    Here is a link to the docs: https://www.apollographql.com/docs/react/api/react-apollo.html#graphql-config-props

提交回复
热议问题