**Apollo Client
**는 GrpahQL API
를 클라이언트에서 호출할 수 있도록 연결해주는 Node.js
기반 라이브러리이다.
yarn add @apollo/client graphql
GraphQL의 쿼리를 작성한다. → gql(쿼리문)
const USERS_QUERY = gql`
{
users{
id
name
status
}
}
`
GraphQL 쿼리를 prop으로 전달하는 컴포넌트를 사용
return (
<Query query={USERS_QUERY}>
{({ loading, error, data }) => {
if (loading) return <div>Fetching</div>
if (error) return <div>Error</div>
const usersToRender = data.users
return (
<div>
{usersToRender.map(user=> <User key={user.id} info={user} />)}
</div>
)
}}
</Query>
)