3

I am very new to GraphQL, so maybe I am just missing something here. i am currently creating an GraphQL endpoint of a Postgres SQL Database using the PostGraphile I am able to perform queries, but i just found out about GraphQL Subscriptions and apparently PostGraphile supports it as explained here. Here its what I doing.

Express Server

const express = require("express");
const { postgraphile, makePluginHook } = require("postgraphile");
const { default: PgPubsub } = require("@graphile/pg-pubsub");
const pluginHook = makePluginHook([PgPubsub]);


var cors = require('cors');
const app = express();
app.use(cors());
let url = "postgres://postgres:docker@localhost:5432/dvdrental";
app.use(postgraphile(url,"public", {
  graphiql:true,
  pluginHook,
  subscriptions: true,
  simpleSubscriptions: true,
}));
app.listen(3000);

Subscribing like

  subscription {
    listen(topic: "hello") {
      query {
        allPayments {
          nodes {
            customerId
            paymentDate
            nodeId
          }
        }
      }
    }
  }

Triggering like

postgres=# select pg_notify( 'postgraphile:hello', '{}' );

But I am not seeing anything on the graphiql response

WebSocket/Network

Here it is what I get at the WebSocket/Network panel @Benjie. The {type:"ka} actions appears to be fired in a random interval.

enter image description here

CESCO
  • 7,305
  • 8
  • 51
  • 83
  • I noticed you’ve enabled CORS, but that only works for regular connections, not the websockets; perhaps the websocket connection is not working. Try using the network debug tools to see what’s going on: https://www.graphile.org/postgraphile/debugging/#step-1-check-youre-requesting-what-you-think-youre-requesting – Benjie May 18 '19 at 20:02
  • @Benjie removed cors middleware but WS connection does not shows anything. – CESCO May 20 '19 at 14:05
  • @Benjie I have updated the question – CESCO May 20 '19 at 14:11
  • @CESCO did you find this working? if yes then can you please provide me an example so it can helpful for me. I'm working on the same thing. thanks. – Harsh Patel Aug 25 '20 at 12:57

0 Answers0