graphql-request vs urql vs apollo-client vs react-apollo
GraphQL 클라이언트 라이브러리
graphql-requesturqlapollo-clientreact-apollo유사 패키지:

GraphQL 클라이언트 라이브러리

GraphQL 클라이언트 라이브러리는 GraphQL API와 상호작용하기 위해 사용되는 도구입니다. 이 라이브러리들은 데이터 요청, 캐싱, 상태 관리 및 UI와의 통합을 용이하게 하여 개발자가 효율적으로 애플리케이션을 구축할 수 있도록 돕습니다. 각 라이브러리는 고유한 기능과 사용 사례를 가지고 있어, 특정 요구 사항에 맞춰 선택할 수 있습니다.

npm 다운로드 트렌드

3 년

GitHub Stars 순위

통계 세부사항

패키지
다운로드
Stars
크기
Issues
발행일
라이선스
graphql-request13,112,8486,121420 kB601年前MIT
urql1,518,1508,985140 kB332ヶ月前MIT
apollo-client583,95619,781-4106年前MIT
react-apollo167,0586,790-2057年前MIT

기능 비교: graphql-request vs urql vs apollo-client vs react-apollo

설정 및 사용 용이성

  • graphql-request:

    graphql-request는 매우 간단한 API를 제공하여, 설정이 거의 필요 없고 빠르게 사용할 수 있습니다. 기본적인 GraphQL 요청을 위한 최소한의 코드로 시작할 수 있습니다.

  • urql:

    urql은 간단한 API와 설정을 제공하여, 빠르게 시작할 수 있습니다. 또한, 다양한 플러그인을 통해 기능을 확장할 수 있어 유연한 사용이 가능합니다.

  • apollo-client:

    Apollo Client는 다양한 기능을 제공하지만, 그만큼 설정이 복잡할 수 있습니다. 그러나 강력한 문서화와 커뮤니티 지원 덕분에 학습 곡선이 완만해질 수 있습니다.

  • react-apollo:

    React Apollo는 React의 컴포넌트와 훅을 활용하여 쉽게 사용할 수 있으며, Apollo Client의 모든 기능을 React 애플리케이션에 통합할 수 있도록 도와줍니다.

캐싱 및 상태 관리

  • graphql-request:

    graphql-request는 기본적으로 캐싱 기능이 없으며, 단순한 요청을 위한 라이브러리로 상태 관리는 별도로 처리해야 합니다.

  • urql:

    urql은 기본적인 캐싱 기능을 제공하며, 필요에 따라 커스터마이징할 수 있습니다. 상태 관리 솔루션과의 통합이 용이하여, 다양한 요구 사항에 맞춰 사용할 수 있습니다.

  • apollo-client:

    Apollo Client는 강력한 캐싱 메커니즘을 제공하여, 서버와의 데이터 요청을 최적화하고, 클라이언트 상태를 관리하는 데 유용합니다. 이를 통해 성능을 개선하고, 사용자 경험을 향상시킬 수 있습니다.

  • react-apollo:

    React Apollo는 Apollo Client의 캐싱 기능을 활용하여, React 컴포넌트에서 상태 관리를 쉽게 할 수 있도록 돕습니다. 데이터의 변경 사항을 자동으로 반영하여 UI를 업데이트합니다.

성능

  • graphql-request:

    graphql-request는 경량화된 라이브러리로, 요청이 간단하고 빠르며, 성능 저하가 거의 없습니다. 그러나 복잡한 상태 관리나 캐싱이 필요한 경우에는 한계가 있습니다.

  • urql:

    urql은 경량화된 구조로 성능이 뛰어나며, 필요한 경우에만 데이터를 요청하므로 불필요한 요청을 줄일 수 있습니다.

  • apollo-client:

    Apollo Client는 복잡한 쿼리와 변형을 처리할 수 있지만, 잘못된 캐싱 설정이나 과도한 쿼리로 인해 성능 저하가 발생할 수 있습니다. 최적화를 위해 쿼리를 효율적으로 작성하는 것이 중요합니다.

  • react-apollo:

    React Apollo는 Apollo Client의 성능을 그대로 활용하여, React의 상태 관리와 결합하여 효율적인 데이터 처리를 제공합니다. 그러나 많은 컴포넌트가 동시에 업데이트될 경우 성능 저하가 발생할 수 있습니다.

유연성 및 확장성

  • graphql-request:

    graphql-request는 단순한 요청을 위한 라이브러리로, 유연성은 제한적이지만, 다른 라이브러리와 함께 사용하여 기능을 확장할 수 있습니다.

  • urql:

    urql은 다양한 상태 관리 솔루션과 통합할 수 있는 유연성을 제공하며, 필요에 따라 기능을 쉽게 확장할 수 있습니다.

  • apollo-client:

    Apollo Client는 다양한 플러그인과 도구를 제공하여, 필요에 따라 기능을 확장할 수 있습니다. 그러나 이러한 유연성은 설정의 복잡성을 증가시킬 수 있습니다.

  • react-apollo:

    React Apollo는 React의 컴포넌트와 훅을 활용하여 유연하게 사용할 수 있으며, Apollo Client의 모든 기능을 React 애플리케이션에 통합할 수 있습니다.

커뮤니티 및 지원

  • graphql-request:

    graphql-request는 간단한 라이브러리이지만, 커뮤니티 지원이 제한적일 수 있습니다. 그러나 기본적인 사용법은 문서화되어 있어 쉽게 접근할 수 있습니다.

  • urql:

    urql은 비교적 새로운 라이브러리지만, 커뮤니티가 성장하고 있으며, 문서화가 잘 되어 있어 사용자가 쉽게 접근할 수 있습니다.

  • apollo-client:

    Apollo Client는 활발한 커뮤니티와 풍부한 문서화를 가지고 있어, 문제 해결이나 학습에 큰 도움이 됩니다. 다양한 예제와 튜토리얼이 제공됩니다.

  • react-apollo:

    React Apollo는 React 생태계 내에서 널리 사용되며, 활발한 커뮤니티와 많은 자료가 있어 학습과 문제 해결에 유리합니다.

선택 방법: graphql-request vs urql vs apollo-client vs react-apollo

  • graphql-request:

    graphql-request는 간단하고 가벼운 API 요청을 위한 라이브러리로, 작은 프로젝트나 간단한 데이터 요청이 필요한 경우에 적합합니다. 사용이 간편하고 설정이 필요 없어 빠르게 시작할 수 있습니다.

  • urql:

    urql은 경량화된 GraphQL 클라이언트로, 유연한 API와 간단한 사용법을 제공합니다. 다양한 상태 관리 솔루션과 통합이 가능하여, 필요에 따라 기능을 확장할 수 있습니다.

  • apollo-client:

    Apollo Client는 복잡한 상태 관리와 캐싱이 필요한 대규모 애플리케이션에 적합합니다. 다양한 기능과 플러그인을 제공하며, GraphQL 생태계와의 통합이 뛰어나므로, GraphQL을 중심으로 한 프로젝트에 적합합니다.

  • react-apollo:

    React Apollo는 React 애플리케이션에 최적화된 Apollo Client의 래퍼로, React의 컴포넌트 기반 아키텍처와 잘 통합됩니다. React를 사용하는 프로젝트에서 GraphQL을 쉽게 사용할 수 있도록 돕습니다.

graphql-request의 README

graphql-request

Minimal GraphQL client supporting Node and browsers for scripts or simple apps.

GitHub Action npm version

Highlights

  • Most simple & lightweight GraphQL client
  • Promise-based API (works with async / await)
  • Pure ESM package
  • First class TypeScript support
    • Including TypedDocumentNode
  • Isomorphic (works in both Node and Browsers)

Install

npm add graphql-request graphql

TypeScript Setup

This package uses package.exports. Therefore if you are a TypeScript user you must:

  1. have your tsconfig.json moduleResolution set to "bundler" or "node16"/"nodenext".
  2. Have your package.json type set to "module".

Quick Start

Send a GraphQL document using a static request function:

import { gql, request } from 'graphql-request'

const document = gql`
  {
    company {
      ceo
    }
  }
`
await request('https://api.spacex.land/graphql/', document)

The function can be passed a configuration object for more complex cases:

await request({
  url,
  document,
  variables,
  requestHeaders,
})

A class is available for constructing your own instances:

import { gql, GraphQLClient } from 'graphql-request'

const document = gql`
  {
    company {
      ceo
    }
  }
`
const endpoint = 'https://api.spacex.land/graphql/'
const client = new GraphQLClient(endpoint)
await client.request(document)

Examples

Node Version Support

We only (officially) support versions of Nodejs of the following status:

  • Current
  • LTS
  • Maintenance and end of life not yet reached

So for example on Oct 24 2023 that would mean these versions: 18, 20, 21.

Any issue that exists solely for an unsupported version of Nodejs will be rejected (not worked on).

Reference

⚠️ This reference is incomplete. Check out the examples for more reference material.

Configuration

ErrorPolicy

By default GraphQLClient will throw when an error is received. However, sometimes you still want to resolve the (partial) data you received. You can define errorPolicy in the GraphQLClient constructor.

const client = new GraphQLClient(endpoint, { errorPolicy: 'all' })
None (default)

Allow no errors at all. If you receive a GraphQL error the client will throw.

Ignore

Ignore incoming errors and resolve like no errors occurred

All

Return both the errors and data, only works with rawRequest.

IgnoreOperationName

OperationName has been introduced to address issues reported here Support operation name, However, on certain occasions this information may not be needed in requests. In such cases, you might consider ignoring operationName to avoid the extraction steps currently performed by a parsing operation when the document is provided in string format.

By default the GraphQLClient tries to extract the operationName from the document. You can define excludeOperationName in the constructor of GraphQLClient to avoid the extraction process if it is not needed. This can be useful if you don't use operationName and want to optimise queries by reducing the amount of computation as much as possible, especially if we are in a context where we are using documents in string format to reduce bundle size.

// example where the operation name is not ignored
const client = new GraphQLClient(endpoint, {
  method: 'POST',
})
// example in which the operation name is ignored
const client = new GraphQLClient(endpoint, {
  method: 'POST',
  excludeOperationName: true,
})

Knowledge Base

Why was the file upload feature taken away? Will it return?

In this issue we decided to make this library more stable and maintainable. In principal the feature is still in scope of this library and will make a return when we find time to do the feature right.

Why do I have to install graphql?

graphql-request uses methods exposed by the graphql package to handle some internal logic. On top of that, for TypeScript users, some types are used from the graphql package to provide better typings.

Do I need to wrap my GraphQL documents inside the gql template exported by graphql-request?

No. It is there for convenience so that you can get the tooling support like automatic formatting and syntax highlighting. You can use gql from graphql-tag if you need it for some reason too.

What sets graphql-request apart from other clients like Apollo, Relay, etc.?

graphql-request is the most minimal and simplest to use GraphQL client. It's perfect for small scripts or simple apps.

Compared to GraphQL clients like Apollo or Relay, graphql-request doesn't have a built-in cache and has no integrations for frontend frameworks. The goal is to keep the package and API as minimal as possible.

Project Stats

Package Installs

NPM Usage Trend of graphql-request

Repo Beats

Alt