Using Apollo Client’s InMemoryCache
and Local Resolvers, it’s possible to have it query your Redux store:
import store from "./Store";
const typeDefs = gql`
type Query {
users: [User]
}
type User {
groups: [Group]
}
type Group {}
`;
const client = new ApolloClient({
cache: new InMemoryCache(),
typeDefs,
resolvers: {
Query: {
users: () => store.getState().users,
},
User: {
groups: user =>
store
.getState()
.groups.filter(group => user.group_ids.includes(group.id)),
},
},
});
Neat “hack”. A shame the Local Resolvers are deprecated in Apollo 3.0 and will most likely be removed in a future version.
Querying your Redux store with GraphQL →
Apollo Client Local Resolvers →