问题
I am trying to use ApolloClient with Vuex but I stumbled upon a problem I can't resolve.
I call ApolloClient.query()
function inside a vuex action but it seems like the function always returns a resolved promise from the first action call. So, after the function got fired once, no request goes to the server and I get the same result as when I load the page (although the actual data in database gets changes).
If I take a look at Apollo Dev Tools, there's also no changes to the Apollo state applied, which leads me to the belief that I missed some core concept of ApolloClient work. Could you give me an idea what should I do or read about?
Vuex action:
getTeams: ({ commit }) => new Promise(async (fulfill, reject) => {
try {
const response = await ApolloClient.query({ query: teamsQuery });
const { teams } = response.data || {};
commit(types.SET_TEAMS, teams);
fulfil(teams);
} catch (error) {
reject(error);
}
})
The query (I guess this is not helpful at all):
export const teamsQuery = gql`
query Teams {
teams {
id
name
}
}
`;
ApolloClient setup, this one is also as simple as it could be:
const link = new HttpLink({
uri: 'http://localhost:8080/graphql',
});
const apolloClient = new ApolloClient({
link,
cache: new InMemoryCache(),
connectToDevTools: true,
});
来源:https://stackoverflow.com/questions/48491160/update-state-with-apollo-client