React-apollo: Compose not working as expected with multiple queries

Created on 2 Feb 2017  路  4Comments  路  Source: apollographql/react-apollo

In the example below MeQuery will override EntitiesQuery and the entities prop will never be passed to Component. You can switch the two around and the reverse will happen, so whatever comes last overrides the previous query. Am I missing anything here? Thanks.

const EntitiesQuery = gql`query Entities {
  entities {
    id
    name
  }
}`

const MeQuery = gql`query Me {
  me {
    username
    id
  }
}`

const Container = compose(
  graphql(EntitiesQuery),
  graphql(MeQuery),
)(Component);

I'm on 0.8.3 btw.

Most helpful comment

nvm, you've gotta specify the name, e.g:

const Container = compose(
  graphql(EntitiesQuery, { name: 'EntitiesQuery' }),
  graphql(MeQuery, { name: 'MeQuery' }),
)(Component);

Then instead of accessing them off props.data e.g. props.data.me you just go props.MeQuery.me.

All 4 comments

nvm, you've gotta specify the name, e.g:

const Container = compose(
  graphql(EntitiesQuery, { name: 'EntitiesQuery' }),
  graphql(MeQuery, { name: 'MeQuery' }),
)(Component);

Then instead of accessing them off props.data e.g. props.data.me you just go props.MeQuery.me.

Weird... I'm using this approach but the responses for both queries are nested. In your example, some results of EntitiesQuery are returned in MeQuery. Have you ever had this issue?

Doing Same, but get only the latest query result.

I'm having the same issue as @thisbejim.

Was this page helpful?
0 / 5 - 0 ratings