Documentation Improvement by adding an example and description for initialEvent for custom subscriptions

Ouverte
#401 1 commentaire 1 réaction 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

Évaluation

Difficulté
2/5
Temps estimé
1-3 heures
Accessibilité débutants
38/100
Type d'issue
Documentation
Clarté
Plutôt claire
Activité
À l'abandon
Stack technique
graphql, javascript
Domaine
api, documentation

Piste de recherche

Commencez par localiser la documentation sur les subscriptions personnalisées ainsi que les exemples existants de @pgSubscription et currentUserTopicFromContext. Documentez initialEvent, notamment sa signature de fonction et l’exemple montré d’établissement de la connexion ; le travail est terminé lorsque les lecteurs peuvent comprendre comment le fournir et ce que contrôle l’objet renvoyé.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

help wanted quick

Over the last few days I've been trying to create a custom subscription that sends the data directly after connecting. However, there is no example in the documentation of an initial event or any evidence that there is an interface for it. The default behavior of an custom subscription is that it only fetches the previous data and the new data (on insert) after an event was been triggered on the database side.

I only got the information about the initialEvent from the discord server:

  • By providing the initialEvent argument to @pgSubscription(...) in typeDefs you can pass to it the function which you want to be executed on connection establishment the same way as currentUserTopicFromContext from the docs to topic:
currentUserUpdated: UserSubscriptionPayload @pgSubscription(topic: ${embed(
   currentUserTopicFromContext,
)})

with initialEvent:

currentUserUpdated: UserSubscriptionPayload @pgSubscription(topic: ${embed(
   currentUserTopicFromContext,
)}, initialEvent: ${embed(
   onInitialEvent, //the function that you want to be executed
)})

The function that you want to be executed in initialEvent has the same structure as currentUserTopicFromContext:

const onInitialEvent = async (_args, context, _resolveInfo) => {
   // do something
  return {}; // return an object 
}

Now because returning an empty object was the solution for my problem (get already existing data on connection establishment), I didn't dig any deeper on what arguments I can give to the object to control the behavior and what operations can be done in the initialEvent function. This can be added additionally to the documentation.

Adding description for initialEvent and examples for it to the documentation to make it clear that something like that exists would help allot.

Langage dominant
SCSS
Étoiles
27
Forks
124
Métriques de merge des PR
Aucune PR mergée en 30 j

Préparer son environnement

  • Aucun Dockerfile ni fichier Docker Compose
  • Propose un modèle de pull request
  • Aucun guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de graphile/graphile.github.io

Toutes les issues de graphile/graphile.github.io

Issues similaires

Plus d'issues Backend & API Design

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.