Skip to content

About

Prueba para comparar 2 tecnologías para hacer update en tiempo real

Resources

Stars

0 stars

Watchers

1 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

GraphQL & SSE Real-time Events Demo

Este proyecto demuestra el uso de GraphQL con suscripciones en tiempo real (WebSocket) y Server-Sent Events (SSE) para crear una aplicación de eventos en tiempo real, mostrando ambos enfoques en paralelo.

Requisitos Previos

  • Node.js (versión 14 o superior)
  • npm (incluido con Node.js)

Instalación

  1. Clona el repositorio o descarga los archivos
  2. Instala las dependencias del servidor:
npm install

Ejecución

  1. Inicia el servidor:
npm start
  1. Abre el navegador en http://localhost:3000 para ver la interfaz de usuario

Probando la Aplicación

1. Interfaz Web

  • Abre http://localhost:3000 en tu navegador
  • Verás dos tablas: una para eventos GraphQL y otra para eventos SSE
  • Cada tabla tiene un botón para enviar un evento de prueba
  • El estado de la conexión WebSocket se muestra en la parte superior

2. Endpoints Disponibles

  • GraphQL (WebSocket y HTTP):
    • http://localhost:3000/graphql
  • SSE (recibir eventos):
    • GET http://localhost:3000/events-sse
  • Crear evento SSE:
    • POST http://localhost:3000/create-sse-event
      • Body JSON: { "message": "Texto del evento" }
  • Obtener historial de eventos SSE:
    • GET http://localhost:3000/sse-events

3. GraphQL Playground

  • Abre http://localhost:3000/graphql en tu navegador
  • Puedes probar consultas, mutaciones y suscripciones

Suscripción:

subscription {
  eventCreated {
    id
    time
    message
  }
}

Mutación:

mutation {
  createEvent(message: "¡Hola desde GraphQL!") {
    id
    time
    message
  }
}

4. Probar SSE manualmente

Usando curl para crear un evento SSE:

curl -X POST -H "Content-Type: application/json" -d '{"message": "¡Hola desde SSE!"}' http://localhost:3000/create-sse-event

Usando Postman

  • Método: POST
  • URL: http://localhost:3000/create-sse-event
  • Body: raw, JSON
{
  "message": "Esto es un evento SSE desde Postman"
}

Estructura del Proyecto

.
├── public/
│   ├── index.html    # Interfaz de usuario
│   ├── app.js        # Código del cliente
│   └── styles.css    # Estilos
├── server.js         # Servidor principal (GraphQL + SSE)
├── schema.js         # Esquema GraphQL
└── package.json      # Dependencias

Tecnologías Utilizadas

  • Backend:

    • Node.js
    • Express
    • Apollo Server
    • GraphQL
    • WebSocket
    • Server-Sent Events (SSE)
  • Frontend:

    • Apollo Client
    • GraphQL Subscriptions
    • ES Modules

Características

  • Suscripciones en tiempo real usando WebSocket (GraphQL)
  • Eventos en tiempo real usando SSE
  • Interfaz de usuario con dos tablas independientes
  • Botones de prueba para ambos métodos
  • Reconexión automática para SSE
  • Manejo de errores

Notas Adicionales

  • Puedes comparar fácilmente la experiencia y latencia entre GraphQL (WebSocket) y SSE
  • Cada tabla solo muestra los eventos de su propio canal
  • El sistema maneja automáticamente la reconexión si se pierde la conexión SSE

About

Prueba para comparar 2 tecnologías para hacer update en tiempo real

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages