[git] Graphql 3 ( Apollo/client & Graphql )
Apollo/client & Graphql
Apollo / client
특징
- 선언적 데이터 패칭(declarative data fetching)
- Zero-config caching
- Combine local & remote data
선언적 데이터 fetching
useQuery hooks를 통한 선언적 데이터 fetching hooks를 통해서 값들이 반환되기 때문에, 리덕스에서 사용되던 보일러플레이트 코드들이 필요없어짐.
const { loading, error, data } = useQuery(GET_DOGS);
Zero-config caching
캐성 처리 관련한 설정이 간단하다.
리스트를 보여주는 페이지 (GetAllDogs) –> 특정 강아지에 대한 정보 페이지(GetDog)로 넘어갈때
이에 대한 캐싱 작업을 캐시 정책에 의해서 처리
const GET_ALL_DOGS = gql`
query GetAllDogs {
dogs {
id
breed
displayImage
}
}
`;
const GET_DOG = gql`
query GetDog {
dog(id: "abc") {
id
breed
displayImage
}
}
`;
Combine local & remote data
이 부분은 이해가 안가네요.
#그래프큐엘/Apollo-client