You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

graphql-http-ws-client

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

graphql-http-ws-client

### Node.js with HTTP and WS links

0.2.2
Source
npmnpm
Version published
Weekly downloads
17
-41.38%
Maintainers
1
Weekly downloads
 
Created
Source

GraphQL client over HTTP/WS

import {createGraphQLClient, gql} from "graphql-http-ws-client";
import WebSocket from "ws";
import fetch from "node-fetch";

const { client } = createGraphQLClient("MY_GRAPHQL_URL", {
	websocket: WebSocket,
	httpLinkOptions: {
        fetch: fetch
    }
});
import {createGraphQLClient, gql} from "graphql-http-ws-client";
import fetch from "node-fetch";

const { client } = createGraphQLClient("MY_GRAPHQL_URL", {
	httpLinkOptions: {
	    fetch: fetch
	},
	createWSLink: false
});
import {createGraphQLClient, gql} from "graphql-http-ws-client";
import WebSocket from "ws";
import fetch from "node-fetch";

const { client } = createGraphQLClient("MY_GRAPHQL_URL", {
	websocket: WebSocket,
	createHTTPLink: false
});
import WebSocket from "ws";
import fetch from "node-fetch";
import {createGraphQLClient, gql} from "graphql-http-ws-client";
import { persistCache } from "apollo-cache-persist";
const { client, cache } = createGraphQLClient("MY_GRAPHQL_URL");

const waitOnCache = persistCache({
	cache: cache,
	storage: window.localStorage
});

waitOnCache.then(() => {
	ReactDOM.render(
		<ApolloProvider client={client}>
			<Router>
				<App/>
			</Router>
		</ApolloProvider>,
		document.getElementById('root')
	)
});

Simple Queries

Using the server example from graphql-http-ws-server

client.query({
    query: gql(`query {
        hello
    }`)
}).then(({data}) => {
    console.log("DATA", data);
});

Simple Subscriptions

Using the server example from graphql-http-ws-server

client.subscribe({
    query: gql(`subscription {
        time
    }`)
}).subscribe({
    next({data}) {
        console.log(data);
    }
});

Changes

v0.2

  • Module now requires graphql and subscriptions-transport-ws as peer dependencies
  • Module now exports gql and all exports from @apollo/client/core
  • Renamed createWebsocketLink to createWSLink and websocket option to ws for consistency with options
  • New httpLinkOptions and wsLinkOptions parameters
    • fetch option moves to httpLinkOptions option
    • all ws link options move to wsLinkOptions option

FAQs

Package last updated on 28 Aug 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts