Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

267
Vistas
How to implement only client to graphql subscriptions in a website with only front code?

I am coding a only front end site using Django. to query data to a DataBase I use AJAX to my Django and Django requests a third party GraphQL. so far all works perfect. But now I need to alert the users on updates to a table. the third party has setup subscriptions. I know is working because I made a view with the play ground, execute the subscription and on updates, the playground shows the update.

So how can I implemente those subscriptions to my site so on updates I can do console.log(subscriptionUpdateMsg) ? I have been looking for about 3 days and I have found many docs whith info, but they require node.js or other servers, the problem is that I already have all on Django server as I was required. and some other sites works with but I get error failed: Error during WebSocket handshake: Unexpected response code: 500

This is what the code creates, and is working: screenshot here

Here is the working code with the playgroun in my site:

<html>
    <head>
        <style>
            html,
            body {
                height: 100%;
                margin: 0;
                overflow: hidden;
                width: 100%;
            }
        </style>
        <link
            href="//cdn.jsdelivr.net/npm/graphiql@0.11.11/graphiql.css"
            rel="stylesheet"
        />
        <script src="//cdn.jsdelivr.net/react/15.4.2/react.min.js"></script>
        <script src="//cdn.jsdelivr.net/react/15.4.2/react-dom.min.js"></script>
        <script src="//cdn.jsdelivr.net/npm/graphiql@0.11.11/graphiql.min.js"></script>
        <script src="//cdn.jsdelivr.net/npm/graphql-transport-ws@0.8.3/browser/client.js"></script>
    </head>

    <body>
        <script>
            // Setup subscription client.
            const GRAPHQL_ENDPOINT =
                (location.protocol === "https" ? "wss" : "ws") +
                "://" +
                //location.host +
                "apiclients.develop.ThirdPartyWebSite.com:8009/graphql/"
            let subClient = new window.SubscriptionsTransportWs.SubscriptionClient(
                GRAPHQL_ENDPOINT,
                {reconnect: true},
            )
            subFetcher = subClient.request.bind(subClient)

            // Render <GraphiQL /> into the body.
            ReactDOM.render(
                React.createElement(GraphiQL, {
                    fetcher: subFetcher, //graphQLFetcher
                }),
                document.body,
            )
        </script>
    </body>
</html>
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Since I could not find any tutorials or full examples I made hours of test on the browser console and now I see that is easy:

1: add the javascript src="//cdn.jsdelivr.net/npm/graphql-transport-ws@0.8.3/browser/client.js

2: with only this javascript we are ready to subscribe

            const GRAPHQL_ENDPOINT =
                (location.protocol === "https" ? "wss" : "ws") +
                "://apiclients.develop.ThirdPartyWebSite.com:8009/graphql/"
            let subClient = new window.SubscriptionsTransportWs.SubscriptionClient(
                GRAPHQL_ENDPOINT,
                {reconnect: true},
            )

with the next line:

subClient.subscribe({query:'subscription{onNewReservation(group:"clients"){reservationId}}'}, function(error,data){console.log(data); })

☺

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda