Integration tests for graphql subscriptions
Asked Answered
M

0

6

How can i go about testing the publishing/subscriptions of my graphql schema, without using apollo?

Is it possible to just do it with subscriptions-transport-ws ? My SubscriptionServer is setup with default settings, i'm able to see the publish happen by just calling a mutation query with graphql. I've setup a websocket connection using my express server

const WebSocket = require('ws');
const myServer = require('../../bin/www');
const wsServer = new WebSocket.Server({
  server: myServer
});

const client = new SubscriptionClient(`ws://localhost:3000/subscriptions`, {}, WebSocket);

client.subscribe(
  {
    query: `subscription roomSubscription(placeId: "someid") {
        user {
            id,
            name
        }
    }`,
  },
  (error, result) => {
      console.log({error, result});
  }
);


const query = `
    mutation { 
        roomAddOrUpdate(placeId: "some id") {
            user {
                name
            }
        }
    }`;
   const result = await graphql(schema, query, {}, req); 

nothing seems to console out in client.subscribe function, not sure if i'm going at this the right way. You can see my setup here https://github.com/farzd/firstsight/blob/master/bin/www

Mysticism answered 3/8, 2017 at 15:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.