Im currently using graphql to fetch data using simple queries, but now I would like to subscribe to some data.
I’ve saw this article on messari about using thegraph subscriptions, but when I try it in my nodejs script I get:
Only HTTP(S) protocols are supported
So my question is, does thegraph support graphql subscriptions?
This is my code:
require('cross-fetch/polyfill');
const ApolloClient = require('@apollo/client').ApolloClient;
const InMemoryCache = require('@apollo/client').InMemoryCache;
const gql = require("graphql-tag");
const WSURL = "wss://api.thegraph.com/subgraphs/name/uniswap/uniswap-v3";
const subscription = `
subscription swaps{
swaps {
id
timestamp
}
}`;
const client = new ApolloClient({
uri: WSURL,
options: {
reconnect: true
},
cache: new InMemoryCache()
});
client.subscribe({
query: gql(subscription),
}).subscribe({
next(data) {
console.log(data);
},
error(err) { console.error('err', err); },
});