정의

**Apollo Client**는 GrpahQL API를 클라이언트에서 호출할 수 있도록 연결해주는 Node.js 기반 라이브러리이다.


설치 및 사용 방법

yarn add @apollo/client graphql
  1. GraphQL의 쿼리를 작성한다. → gql(쿼리문)

    const USERS_QUERY = gql`
      {
        users{
           id
           name
           status
        }
      }
    `
    
  2. 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>
    )