programing

Apollo Client를 사용하여 상태 업데이트

prostudy 2022. 5. 28. 09:05
반응형

Apollo Client를 사용하여 상태 업데이트

Vuex에서 ApolloClient를 사용하려고 하는데 해결할 수 없는 문제가 발생했습니다.

나는 전화한다ApolloClient.query()vuex 액션에 포함된 함수이지만 함수는 항상 첫 번째 액션콜에서 해결된 약속을 반환하는 것처럼 보입니다.따라서 함수가 한 번 실행된 후에는 서버에 요청이 전송되지 않고 페이지를 로드할 때와 동일한 결과가 나타납니다(데이터베이스의 실제 데이터는 변경되지만).

Apollo Dev Tools를 살펴보면 Apollo 상태에 대한 변경도 적용되지 않았기 때문에 Apollo Client 작업의 핵심 개념을 놓쳤다는 생각이 듭니다.제가 무엇을 하거나 읽어야 하는지 아이디어를 주실 수 있나요?

Vuex 액션:

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);
   }
})

쿼리(이것은 전혀 도움이 되지 않는 것 같습니다):

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,
});

언급URL : https://stackoverflow.com/questions/48491160/update-state-with-apollo-client

반응형