[Apollo] 1장. Apollo Client 소개

Apollo 써보기

출처 : Apollo 공식 레퍼런스

목차


Apollo Client 소개

Data management shouldn’t have to be so difficult!


Declarative data fetching

function Feed() {
  const { loading, error, data } = useQuery(GET_DOGS);
  if (error) return <Error />;
  if (loading || !data) return <Fetching />;

  return <DogList dogs={data.dogs} />;
}

Advanced features like optimistic UI, refetching, and pagination are all easily accessible through useQuery options.


Zero-config caching

import ApolloClient from 'apollo-boost';

// the Apollo cache is set up automatically
const client = new ApolloClient();
import ApolloClient from 'apollo-boost';

const client = new ApolloClient({
  cacheRedirects: {
    Query: {
      dog: (_, { id }, { getCacheKey }) => getCacheKey({ id, __typename: 'Dog' })
    }
  }
})

Combine local & remote data

const GET_DOG = gql`
  query GetDogByBreed($breed: String!) {
    dog(breed: $breed) {
      images {
        url
        id
        isLiked @client
      }
    }
  }
`;

Your components are made up of local and remote data, now your queries can be too!


Vibrant ecosystem