graphql-request vs urql vs apollo-client vs react-apollo
GraphQL İstemci Kütüphaneleri
graphql-requesturqlapollo-clientreact-apolloBenzer Paketler:

GraphQL İstemci Kütüphaneleri

GraphQL istemci kütüphaneleri, GraphQL API'leri ile etkileşim kurmak için kullanılan araçlardır. Bu kütüphaneler, verileri sorgulamak, mutasyonlar yapmak ve GraphQL sunucusuyla iletişim kurmak için gerekli olan işlevselliği sağlar. Her biri farklı özellikler ve kullanım senaryoları sunarak geliştiricilere esneklik ve performans sağlar.

npm İndirme Trendi

3 Yıl

GitHub Stars Sıralaması

İstatistik Detayı

Paket
İndirmeler
Stars
Boyut
Issues
Yayın Tarihi
Lisans
graphql-request13,112,8486,121420 kB60il y a un anMIT
urql1,518,1508,985140 kB33il y a 2 moisMIT
apollo-client583,95619,781-410il y a 6 ansMIT
react-apollo167,0586,790-205il y a 7 ansMIT

Özellik Karşılaştırması: graphql-request vs urql vs apollo-client vs react-apollo

Önbellekleme

  • graphql-request:

    GraphQL Request, önbellekleme özelliği sunmaz. Her istek yapıldığında sunucudan veri alır, bu da basit projelerde yeterli olabilir ancak daha büyük uygulamalarda performans sorunlarına yol açabilir.

  • urql:

    Urql, önbellekleme mekanizması sunar ancak Apollo Client kadar kapsamlı değildir. Önbellek yönetimi, geliştiricinin ihtiyaçlarına göre özelleştirilebilir.

  • apollo-client:

    Apollo Client, güçlü bir önbellekleme mekanizması sunar. Verileri önbelleğe alarak, gereksiz ağ isteklerini azaltır ve uygulamanızın performansını artırır. Ayrıca, önbellek güncellemeleri ve sorgu sonuçları üzerinde tam kontrol sağlar.

  • react-apollo:

    React Apollo, Apollo Client'ın sunduğu önbellekleme özelliklerini kullanır. Bu, bileşenlerin yeniden render edilmeden önce önbellekten veri almasını sağlar ve performansı artırır. Ayrıca, bileşen bazlı önbellekleme stratejileri sunar.

Kullanım Kolaylığı

  • graphql-request:

    GraphQL Request, basit bir API sunar ve öğrenmesi oldukça kolaydır. Hızlı bir şekilde projeye entegre edilebilir ve temel ihtiyaçları karşılar.

  • urql:

    Urql, minimalist bir yapıya sahip olduğu için öğrenmesi kolaydır. Ancak, daha karmaşık senaryolar için bazı ek yapılandırmalar gerektirebilir.

  • apollo-client:

    Apollo Client, geniş bir özellik setine sahip olduğu için başlangıçta öğrenme eğrisi biraz dik olabilir. Ancak, iyi bir dokümantasyon ve topluluk desteği ile bu zorluk aşılabilir.

  • react-apollo:

    React Apollo, React bileşenleri ile entegre bir şekilde çalıştığı için React geliştiricileri için oldukça sezgisel bir deneyim sunar. Bileşen bazlı yapısı sayesinde kullanım kolaylığı sağlar.

Performans

  • graphql-request:

    GraphQL Request, her istekte sunucuya eriştiği için büyük veri setlerinde performans sorunları yaşayabilir. Ancak, basit projelerde hızlı ve etkilidir.

  • urql:

    Urql, hafif bir yapıya sahip olduğu için hızlıdır. Ancak, daha karmaşık senaryolar için performans optimizasyonları gerektirebilir.

  • apollo-client:

    Apollo Client, büyük veri setleri ile çalışırken performans sorunları yaşayabilir. Ancak, önbellekleme ve sorgu optimizasyonları ile bu sorunlar minimize edilebilir.

  • react-apollo:

    React Apollo, bileşen bazlı yapısı sayesinde performansı artırır. Ancak, karmaşık uygulamalarda önbellek yönetimi dikkatli yapılmalıdır.

Esneklik

  • graphql-request:

    GraphQL Request, basit bir yapı sunduğu için esneklik açısından sınırlıdır. Ancak, hızlı prototipleme için idealdir.

  • urql:

    Urql, esneklik ve özelleştirilebilirlik sunar. Geliştiricilerin ihtiyaçlarına göre yapılandırılabilir.

  • apollo-client:

    Apollo Client, geniş bir özellik setine sahip olduğu için esneklik sunar. Ancak, bu bazen karmaşıklığa yol açabilir.

  • react-apollo:

    React Apollo, React uygulamaları için özel olarak tasarlandığı için esneklik sunar. Ancak, bazı durumlarda Apollo Client'ın karmaşıklığına maruz kalabilirsiniz.

Topluluk Desteği

  • graphql-request:

    GraphQL Request, daha küçük bir topluluğa sahiptir. Ancak, basit yapısı nedeniyle genellikle sorunlar hızlı bir şekilde çözülür.

  • urql:

    Urql, büyüyen bir topluluğa sahiptir. Ancak, Apollo Client kadar geniş bir destek sunmayabilir.

  • apollo-client:

    Apollo Client, büyük bir topluluk ve kapsamlı dokümantasyon sunar. Bu, sorunların çözülmesi ve destek almayı kolaylaştırır.

  • react-apollo:

    React Apollo, React topluluğunun bir parçasıdır ve bu nedenle geniş bir destek ve kaynak sunar.

Nasıl Seçilir: graphql-request vs urql vs apollo-client vs react-apollo

  • graphql-request:

    GraphQL Request, basit ve hafif bir istemci arıyorsanız tercih edilmelidir. Küçük projeler veya hızlı prototipleme için idealdir. Kullanımı kolaydır ve sadece temel özellikleri sunar.

  • urql:

    Urql, esneklik ve performans arıyorsanız tercih edilmelidir. Minimalist bir yapı sunar ve özelleştirilebilirliği ile dikkat çeker. Küçük ve orta ölçekli uygulamalar için uygundur.

  • apollo-client:

    Apollo Client, kapsamlı bir GraphQL istemcisi arıyorsanız ve önceden tanımlı bir yapı ile birlikte güçlü bir önbellekleme mekanizması istiyorsanız tercih edilmelidir. Büyük ölçekli uygulamalar için idealdir ve birçok özellik sunar.

  • react-apollo:

    React Apollo, React uygulamaları için özel olarak tasarlanmış bir GraphQL istemcisidir. Eğer React ile çalışıyorsanız ve bileşen tabanlı bir yaklaşım istiyorsanız bu kütüphaneyi seçebilirsiniz. React ile entegre bir deneyim sunar.

graphql-request için 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