3 Şubat 2022 Perşembe

GraphQL Subscriptions

Giriş
Açıklaması şöyle
Subscription enables the client to fetch real-time updates from the server. You can think of subscriptions as analogous to continuous polling mechanisms. It makes it possible for the server to stream data to all the clients that are listening or 'subscribed' to it. Just like queries, subscriptions allow you to read data. Unlike queries, subscriptions maintain an active connection to your GraphQL server, most commonly via WebSocket. This enables your server to push updates to the client over time. Executing a subscription creates a persistent function on the server that maps an underlying Source Stream to a returned Response Stream. You can define available subscriptions in your GraphQL schema as fields of the Subscription type.
Örnek
Şöyle yaparız
subscription {
  newAuthor {
    name
    country
  }
}
Eğer yeni bir yazar yaratılırsa sunucu bize şunu gönderir.
{
  "newAuthor": {
    "name": "Robert Jordan",
    "country": "USA"
  }
}


Hiç yorum yok:

Yorum Gönder