본문 바로가기
Error

Swift Apollo GraphQL | reload data

by pavi03 2022. 3. 12.

[Swift Apollo GraphQL]

 

Network.shared.apollo.fetch(query: LogRepoQuery(repo_name: Repo_Name)){ result in

 

다음과 같은 식으로 쿼리를 받았는데, 데이터가 변경되면 변경된 데이터를 받아와서 View를 바꿔주고 싶었다.

 

하지만 데이터를 변경하고 쿼리를 보내도 이전 데이터만 계속 받아왔다.

 

캐시가 남아있어서 그랬던거 같다.

 

Network.shared.apollo.fetch(query: LogRepoQuery(repo_name: Repo_Name), cachePolicy: CachePolicy.fetchIgnoringCacheData){ result in

 

CachePolicy 를 추가하여 해결하였다.

 

-----------

 

CachePolicy에는 여러가지가 있다.

 

  /// Return data from the cache if available, else fetch results from the server.

  case returnCacheDataElseFetch

  ///  Always fetch results from the server.

  case fetchIgnoringCacheData

  ///  Always fetch results from the server, and don't store these in the cache.

  case fetchIgnoringCacheCompletely

  /// Return data from the cache if available, else return nil.

  case returnCacheDataDontFetch

  /// Return data from the cache if available, and always fetch results from the server.

  case returnCacheDataAndFetch

 

적절한 것을 갖다 쓰면 된다.