是否可以将Recompose用于react-apollo
的查询组件?
https://www.apollographql.com/docs/react/essentials/queries.html#basic
我在想这样的事情:
const props = {component:"Query", query: gql(ListResults), children: ViewResults};
export default withProps(props)(componentFromProp('component'))
答案 0 :(得分:1)
您可以编写查询,而不使用查询组件。
使用您发布的链接中的示例。
import { compose } from 'recompose';
import gql from 'graphql-tag';
import { graphql } from 'react-apollo';
const Dogs = ({ data, onDogSelected }) => (
<select name="dog" onChange={onDogSelected}>
{data.dogs.map(dog => (
<option key={dog.id} value={dog.breed}>
{dog.breed}
</option>
))}
</select>
);
const GET_DOGS = gql`
{
dogs {
id
breed
}
}
`;
const getDogsQuery = graphql(GET_DOGS, {
options: props => ({
fetchPolicy: props.fetchPolicy // example of passing to the query from props.
})
});
export default compose(getDogsQuery)(Dogs); // { data } is now a prop with the query results.