Reputation: 5431
I have this rest app that gets data like this, with thunk + promise middlewares for redux:
export const fetchVenues = () => ({
type: 'FETCH_VENUES',
payload: axios.get('http://localhost:3000/mock/venues'),
});
The data from this goes into the store and components use the fetched data from there.
Can I swap the rest request in "payload" with a graphql query or something?
What confuses me is that Redux says: "Data lives in the store and can only be changed by actions", but Apollo binds the data directly to the components. I've already made a GraphQL API, works great in the graphiql devtool, but I'm a bit confused by the way it's handled in the client after reading this article.
Upvotes: 2
Views: 546
Reputation: 480
My understanding is that internally, apollo uses redux. Basically it makes you collocate the query with the component and injects (connect) the related data + functions as props. It also manages the store for you, by updating the cache / store upon request completion.
You can see that ApolloProvider is a redux provider on steroids: https://github.com/apollostack/react-apollo/blob/01425b3df5f05e7f389b36f3385433c89a39977b/src/ApolloProvider.tsx
I hope this helps your understanding a little.
Upvotes: 3