I am trying to use ApolloClient with Vuex, but I came across a problem that I cannot solve.
I call the ApolloClient.query()function inside the vuex action, but it seems that the function always returns an allowed promise from the first call to the action. Thus, after the function was run once, the server does not receive a request, and I get the same result as when the page was loaded (although the actual data in the database changes).
If I look at Apollo Dev Tools, there will also be no change in the state of Apollo, which leads me to believe that I missed some basic concepts of ApolloClient. Could you give me an idea of ββwhat to do or read?
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 request (I think this is not useful at all):
export const teamsQuery = gql`
query Teams {
teams {
id
name
}
}
`;
ApolloClient, , :
const link = new HttpLink({
uri: 'http://localhost:8080/graphql',
});
const apolloClient = new ApolloClient({
link,
cache: new InMemoryCache(),
connectToDevTools: true,
});
user5341580