Socket
Socket
Sign inDemoInstall

@graphiql/toolkit

Package Overview
Dependencies
Maintainers
2
Versions
90
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@graphiql/toolkit - npm Package Compare versions

Comparing version 0.7.1 to 0.7.2-canary-b42baca4.0

6

CHANGELOG.md
# @graphiql/toolkit
## 0.7.2-canary-b42baca4.0
### Patch Changes
- [#2753](https://github.com/graphql/graphiql/pull/2753) [`7080b9de`](https://github.com/graphql/graphiql/commit/7080b9de9497402540de62cb113f99c22f611b03) Thanks [@thomasheyenbrock](https://github.com/thomasheyenbrock)! - Mark the `graphql-ws` peer dependency as optional (as it's only needed when the fetcher needs to support subscriptions)
## 0.7.1

@@ -4,0 +10,0 @@

5

dist/async-helpers/index.js

@@ -5,3 +5,5 @@ "use strict";

function isPromise(value) {
return typeof value === 'object' && typeof value.then === 'function';
return (typeof value === 'object' &&
value !== null &&
typeof value.then === 'function');
}

@@ -25,2 +27,3 @@ exports.isPromise = isPromise;

return (typeof value === 'object' &&
value !== null &&
'subscribe' in value &&

@@ -27,0 +30,0 @@ typeof value.subscribe === 'function');

@@ -1,13 +0,11 @@

## Create Fetcher
# `createGraphiQLFetcher`
a utility for generating a full-featured `fetcher` for GraphiQL including `@stream`, `@defer` `IncrementalDelivery`and `multipart` and subscriptions using `graphql-ws` or the legacy websockets protocol
A utility for generating a full-featured `fetcher` for GraphiQL including `@stream`, `@defer` `IncrementalDelivery`and `multipart` and subscriptions using `graphql-ws` or the legacy websockets protocol.
under the hood, it uses [`graphql-ws`](https://www.npmjs.com/package/graphql-ws) client and [`meros`](https://www.npmjs.com/package/meros) which act as client reference implementations of the [GraphQL over HTTP Working Group Spec](https://github.com/graphql/graphql-over-http) specification, and the most popular transport spec proposals
Under the hood, it uses [`graphql-ws`](https://www.npmjs.com/package/graphql-ws) client and [`meros`](https://www.npmjs.com/package/meros) which act as client reference implementations of the [GraphQL over HTTP Working Group Spec](https://github.com/graphql/graphql-over-http) specification, and the most popular transport spec proposals.
### Setup
## Setup
[`graphiql`](https://npmjs.com/package/graphiql) and thus `react` and `react-dom` should already be installed.
You can install `@graphiql/toolkit` using your favorite package manager:
you'll need to install `@graphiql/toolkit`
```bash

@@ -17,11 +15,7 @@ npm install --save @graphiql/toolkit

```bash
yarn add @graphiql/toolkit
```
## Getting Started
### Getting Started
We have a few flexible options to get you started with the client. It's meant to cover the majority of common use cases with a simple encapsulation.
#### Default HTTP/Multipart IncrementalDelivery Usage
### Default HTTP/Multipart IncrementalDelivery Usage

@@ -45,5 +39,5 @@ Here's a simple example. In this case, a websocket client isn't even initialized, only http (with multipart `@stream` and `@defer` Incremental Delivery support of course!).

#### Adding `graphql-ws` websockets subscriptions
### Adding `graphql-ws` websockets subscriptions
first you'll need to install `graphql-ws` as a peer dependency:
First you'll need to install `graphql-ws` as a peer dependency:

@@ -54,8 +48,4 @@ ```bash

```bash
yarn add graphql-ws
```
Just by providing the `subscriptionUrl`, you can also generate a `graphql-ws` client. This client now supports both HTTP/Multipart Incremental Delivery for `@defer` and `@stream`, _and_ websockets subscriptions.
Just by providing the `subscriptionUrl`, you can also generate a `graphql-ws` client. This client now supports both HTTP/Multipart Incremental Delivery for `@defer` and `@stream`, _and_ websockets subscriptions
```ts

@@ -81,21 +71,21 @@ import * as React from 'react';

You can further customize the `graphql-ws` implementation by creating a custom client instance and providing it as the `wsClient` parameter
You can further customize the `graphql-ws` implementation by creating a custom client instance and providing it as the `wsClient` parameter.
### Options
## Options
#### `url` (_required_)
### `url` (_required_)
This is url used for all `HTTP` requests, and for schema introspection.
#### `subscriptionUrl`
### `subscriptionUrl`
This generates a `graphql-ws` client using the provided url. Note that a server must be compatible with the new `graphql-ws` subscriptions spec for this to work.
#### `wsClient`
### `wsClient`
provide your own subscriptions client. bypasses `subscriptionUrl`. In theory, this could be any client using any transport, as long as it matches `graphql-ws` `Client` signature.
Provide your own subscriptions client. Using this option bypasses `subscriptionUrl`. In theory, this could be any client using any transport, as long as it matches `graphql-ws` `Client` signature.
### `wsConnectionParams`
## `wsConnectionParams`
provide your initial connection params.
Provide your initial connection params.

@@ -115,19 +105,19 @@ ```ts

#### `legacyWsClient` or `legacyClient`
### `legacyWsClient` or `legacyClient`
provide a legacy subscriptions client using `subscriptions-transport-ws` protocol. bypasses `subscriptionUrl`. In theory, this could be any client using any transport, as long as it matches `subscriptions-transport-ws` `Client` signature.
Provide a legacy subscriptions client using `subscriptions-transport-ws` protocol. Using this option bypasses `subscriptionUrl`. In theory, this could be any client using any transport, as long as it matches `subscriptions-transport-ws` `Client` signature.
#### `headers`
### `headers`
Pass headers to any and all requests
Specify headers that will be passed to all requests.
#### `fetch`
### `fetch`
Pass a custom fetch implementation such as `isomorphic-fetch`
Pass a custom fetch implementation such as `isomorphic-fetch`.
### Customization Examples
## Customization Examples
#### Custom `wsClient` Example using `graphql-ws`
### Custom `wsClient` Example using `graphql-ws`
Just by providing the `wsClient`
This example passes a `graphql-ws` client to the `wsClient` option:

@@ -158,7 +148,7 @@ ```ts

#### Custom `legacyClient` Example
### Custom `legacyClient` Example
(not recommended)
By providing the `legacyClient` you can support a `subscriptions-transport-ws` client implementation, or equivalent
By providing the `legacyClient` you can support a `subscriptions-transport-ws` client implementation, or equivalent:

@@ -186,18 +176,12 @@ ```ts

you will need to install the client separately:
Note that you will need to install the client separately:
```bash
yarn add subscriptions-transport-ws
```
```bash
npm install --save subscriptions-transport-ws
```
and instantiate a client instance following their readme, and pass it as `legacyWsClient`.
### Custom `fetcher` Example
#### Custom `fetcher` Example
For SSR, we might want to use something like `isomorphic-fetch`:
For SSR, we might want to use something like `isomorphic-fetch`
```ts

@@ -204,0 +188,0 @@ import * as React from 'react';

export function isPromise(value) {
return typeof value === 'object' && typeof value.then === 'function';
return (typeof value === 'object' &&
value !== null &&
typeof value.then === 'function');
}

@@ -20,2 +22,3 @@ function observableToPromise(observable) {

return (typeof value === 'object' &&
value !== null &&
'subscribe' in value &&

@@ -22,0 +25,0 @@ typeof value.subscribe === 'function');

7

package.json
{
"name": "@graphiql/toolkit",
"version": "0.7.1",
"version": "0.7.2-canary-b42baca4.0",
"description": "Utility to build a fetcher for GraphiQL",

@@ -36,2 +36,7 @@ "contributors": [

},
"peerDependenciesMeta": {
"graphql-ws": {
"optional": true
}
},
"keywords": [

@@ -38,0 +43,0 @@ "graphql",

@@ -5,6 +5,4 @@ [Changelog](https://github.com/graphql/graphiql/blob/main/packages/graphql-toolkit/CHANGELOG.md) | [API Docs](https://graphiql-test.netlify.app/typedoc/modules/graphiql_toolkit.html) | [NPM](https://www.npmjs.com/package/@graphiql/toolkit) | [Discord](https://discord.gg/NP5vbPeUFp)

General purpose library as a dependency of GraphiQL.
This is a general purpose library for building GraphQL IDEs. It's being used by other packages like `graphiql` and `@graphiql/react` and also provides utilities that are useful when working with these packages.
A core dependency of the GraphiQL 2.0.0 initiative.
## Docs

@@ -14,8 +12,1 @@

- more to come!
## Todo
- [x] Begin porting common type definitions used by GraphiQL and it's dependencies
- [x] `createGraphiQLFetcher` utility for an easier `fetcher`
- [ ] Migrate over general purpose `graphiql/src/utilities`
- [ ] Utility to generate json schema spec from `getQueryFacts` for monaco, vscode, etc

@@ -9,3 +9,7 @@ import {

export function isPromise<T>(value: Promise<T> | any): value is Promise<T> {
return typeof value === 'object' && typeof value.then === 'function';
return (
typeof value === 'object' &&
value !== null &&
typeof value.then === 'function'
);
}

@@ -33,2 +37,3 @@

typeof value === 'object' &&
value !== null &&
'subscribe' in value &&

@@ -35,0 +40,0 @@ typeof value.subscribe === 'function'

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc