You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
exportdefaultcompose(graphql(gql`query MyQuery1 { ... }`,{skip: props=>!props.useQuery1}),graphql(gql`query MyQuery2 { ... }`,{skip: props=>props.useQuery1}),)(MyComponent);functionMyComponent({ data }){// The data may be from `MyQuery1` or `MyQuery2` depending on the value// of the prop `useQuery1`.console.log(data);}
However, this still seems very static, and "declarative". Consider you have 2 very similar Scroll components, that has exactly the same type of View. One lists the top 100 movies, the other lists all movies matching a given set of movie Director names. The only difference here would be the gql queries, and query variables for them. It'd be nice to pass the gql query down as props.
I want to discuss some concepts about ability to use/switch to multiple gql query while connecting it to the same component. What I meant was something like this:
http://dev.apollodata.com/react/api-graphql.html#graphql-config-skip
However, this still seems very static, and "declarative". Consider you have 2 very similar Scroll components, that has exactly the same type of View. One lists the top 100 movies, the other lists all movies matching a given set of movie Director names. The only difference here would be the gql queries, and query variables for them. It'd be nice to pass the gql query down as props.
Consider these 2 views: IndexView, MoviesView.
The way i consume the dynamic gql query and connect it to the component is to create a wrapper component like this. (In comments)
or to simplify it further (without the added recompose and gqlConfig options, only the idea of the Wrapper Component):
I've abstracted the wrapper component as a HOC to something like this:
so we can use it like this:
Which results in 2 different query by passing it down as props,
Is there already something similar provided by apollo-core/apollo libraries? Any thoughts?
The text was updated successfully, but these errors were encountered: