Step1: 웹뷰에서 공유해야 할 Data를 모바일로 전달하여 Cache 하기(mobile, web)

이 단계에서는 웹 애플리케이션에서 데이터를 공유하고, 이를 모바일 환경에서 캐시하는 과정에 대해 설명합니다. 주로 **웹뷰(WebView)**와 모바일 환경 간의 데이터 전달 및 캐시 저장 작업을 다룹니다. 아래는 useDeviceCache 훅을 활용하여 데이터를 웹뷰에서 모바일로 전달하고, 모바일 디바이스에서 이를 캐시하는 흐름입니다.

모바일에서 웹뷰로부터 받은 데이터를 저장할 준비하기

const [apolloCache, setApolloCache] = useState({});
const createDeviceCacheForApolloSet = (variables) => {
  const { operationName, printedQuery, data } = variables;
  setApolloCache((prev) => ({
    ...prev,
    [operationName]: { printedQuery, data },
  }));
  onResponse({
    createDeviceCacheForApolloSet: {
      message: "저장완료",
    },
  });
};
const fetchDeviceCacheForApolloSet = () => {
  onResponse({
    fetchDeviceCacheForApolloSet: { ...apolloCache },
  });
};

<aside> 💡

웹뷰에서 모바일로 캐시할 Data 보내기

const operationName = operation.operationName;
const isSharedCache = operationName === "fetchBoards";
if (isSharedCache) {
  fetchApp({
    query: "createDeviceCacheForApolloSet",
    variables: {
      operationName, // 예: fetchBoards
      printedQuery: print(operation.query), // 쿼리를 문자열로 변환 (GraphQL Document Node → String)
      variables: operation.variables, // 요청 시 사용된 변수들
      data: res.data, // 서버로부터 받은 실제 응답 데이터
    },
  });
}