ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • #1.2 오프라인 아폴로 설정
    GraphQL로 오프라인 노트 앱 만들기 2020. 1. 12. 22:54
    • 아폴로 부스트로 하면 자동으로 셋업해주지만 지금의 프로젝트같은 경우는 제대로 동작하지 않을것이다 왜냐면 오프라인 즉 로컬로만 작업을 하기때문인데, 아폴로부스트는 http링크 같은걸 설정해줘야해서, 우리는 수동으로 코드를 써줬다.

    - index.js

    import React from "react";
    import ReactDOM from "react-dom";
    import App from "./App";
    import { ApolloProvider } from "react-apollo";
    import client from "./apollo";
    import "./globalStyles";
    
    ReactDOM.render(
      <ApolloProvider client={client}>
        <App />
      </ApolloProvider>,
      document.getElementById("root")
    );
    

     

    - clientState.js

    export const defaults = {};
    export const resolvers = {};
    export const typeDefs = {};
    

     

    - apollo.js

    import { ApolloClient } from "apollo-client";
    import { InMemoryCache } from "apollo-cache-inmemory";
    import { withClientState } from "apollo-link-state";
    import { ApolloLink } from "apollo-link";
    
    import { typeDefs, defaults, resolvers } from "./clientState";
    
    const cache = new InMemoryCache();
    
    const stateLink = withClientState({
      cache,
      typeDefs,
      defaults,
      resolvers
    });
    
    const client = new ApolloClient({
      cache,
      link: ApolloLink.from([stateLink])
    });
    
    export default client;
    

    'GraphQL로 오프라인 노트 앱 만들기' 카테고리의 다른 글

    설정  (0) 2020.01.12
    들어가면서..  (0) 2020.01.12

    댓글

Designed by Tistory.