graphile / graphile/graphile.github.io
Documentation Improvement by adding an example and description for initialEvent for custom subscriptions
- Lenguaje dominante
- SCSS
- Estrellas
- 27
- Forks
- 126
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Descripción
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:
```js
currentUserUpdated: UserSubscriptionPayload @pgSubscription(topic: ${embed(
currentUserTopicFromContext,
)})
```
with `initialEvent`:
```js
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`:
```js
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.
Guía de contribución
No hay ninguna guía de contribución indexada para este repositorio
Línea de trabajo
Comienza localizando la documentación sobre suscripciones personalizadas y los ejemplos existentes de `@pgSubscription` y `currentUserTopicFromContext`. Documenta `initialEvent`, incluida su firma de función y el ejemplo mostrado de establecimiento de la conexión; se considerará completado cuando los lectores puedan entender cómo proporcionarlo y qué controla el objeto devuelto.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- graphql, javascript
- Área
- api, documentation
- Tipo de issue
- Documentación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 38/100