Skip to content

Commit bfa90f2

Browse files
make graphql-ws an optional peer dependency (#2753)
* make `graphql-ws` an optional peer dependency * readme and docs editorials
1 parent 8ab5fcd commit bfa90f2

4 files changed

Lines changed: 43 additions & 58 deletions

File tree

.changeset/dull-bulldogs-bow.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@graphiql/toolkit': patch
3+
---
4+
5+
Mark the `graphql-ws` peer dependency as optional (as it's only needed when the fetcher needs to support subscriptions)

packages/graphiql-toolkit/README.md

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,9 @@
22

33
# `@graphiql/toolkit`
44

5-
General purpose library as a dependency of GraphiQL.
6-
7-
A core dependency of the GraphiQL 2.0.0 initiative.
5+
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.
86

97
## Docs
108

119
- **[`createFetcher`](./docs/create-fetcher.md)** : a utility for creating a `fetcher` prop implementation for HTTP GET, POST including multipart, websockets fetcher
1210
- more to come!
13-
14-
## Todo
15-
16-
- [x] Begin porting common type definitions used by GraphiQL and it's dependencies
17-
- [x] `createGraphiQLFetcher` utility for an easier `fetcher`
18-
- [ ] Migrate over general purpose `graphiql/src/utilities`
19-
- [ ] Utility to generate json schema spec from `getQueryFacts` for monaco, vscode, etc

packages/graphiql-toolkit/docs/create-fetcher.md

Lines changed: 32 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,22 @@
1-
## Create Fetcher
1+
# `createGraphiQLFetcher`
22

3-
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
3+
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.
44

5-
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
5+
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.
66

7-
### Setup
7+
## Setup
88

9-
[`graphiql`](https://npmjs.com/package/graphiql) and thus `react` and `react-dom` should already be installed.
10-
11-
you'll need to install `@graphiql/toolkit`
9+
You can install `@graphiql/toolkit` using your favorite package manager:
1210

1311
```bash
1412
npm install --save @graphiql/toolkit
1513
```
1614

17-
```bash
18-
yarn add @graphiql/toolkit
19-
```
20-
21-
### Getting Started
15+
## Getting Started
2216

2317
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.
2418

25-
#### Default HTTP/Multipart IncrementalDelivery Usage
19+
### Default HTTP/Multipart IncrementalDelivery Usage
2620

2721
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!).
2822

@@ -41,19 +35,15 @@ export const App = () => <GraphiQL fetcher={fetcher} />;
4135
ReactDOM.render(document.getElementByID('graphiql'), <App />);
4236
```
4337

44-
#### Adding `graphql-ws` websockets subscriptions
38+
### Adding `graphql-ws` websockets subscriptions
4539

46-
first you'll need to install `graphql-ws` as a peer dependency:
40+
First you'll need to install `graphql-ws` as a peer dependency:
4741

4842
```bash
4943
npm install --save graphql-ws
5044
```
5145

52-
```bash
53-
yarn add graphql-ws
54-
```
55-
56-
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
46+
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.
5747

5848
```ts
5949
import * as React from 'react';
@@ -75,25 +65,25 @@ export const App = () => <GraphiQL fetcher={fetcher} />;
7565
ReactDOM.render(document.getElementByID('graphiql'), <App />);
7666
```
7767

78-
You can further customize the `graphql-ws` implementation by creating a custom client instance and providing it as the `wsClient` parameter
68+
You can further customize the `graphql-ws` implementation by creating a custom client instance and providing it as the `wsClient` parameter.
7969

80-
### Options
70+
## Options
8171

82-
#### `url` (_required_)
72+
### `url` (_required_)
8373

8474
This is url used for all `HTTP` requests, and for schema introspection.
8575

86-
#### `subscriptionUrl`
76+
### `subscriptionUrl`
8777

8878
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.
8979

90-
#### `wsClient`
80+
### `wsClient`
9181

92-
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.
82+
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.
9383

94-
### `wsConnectionParams`
84+
## `wsConnectionParams`
9585

96-
provide your initial connection params.
86+
Provide your initial connection params.
9787

9888
```ts
9989

@@ -108,23 +98,23 @@ const App () {
10898
}
10999
```
110100

111-
#### `legacyWsClient` or `legacyClient`
101+
### `legacyWsClient` or `legacyClient`
112102

113-
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.
103+
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.
114104

115-
#### `headers`
105+
### `headers`
116106

117-
Pass headers to any and all requests
107+
Specify headers that will be passed to all requests.
118108

119-
#### `fetch`
109+
### `fetch`
120110

121-
Pass a custom fetch implementation such as `isomorphic-fetch`
111+
Pass a custom fetch implementation such as `isomorphic-fetch`.
122112

123-
### Customization Examples
113+
## Customization Examples
124114

125-
#### Custom `wsClient` Example using `graphql-ws`
115+
### Custom `wsClient` Example using `graphql-ws`
126116

127-
Just by providing the `wsClient`
117+
This example passes a `graphql-ws` client to the `wsClient` option:
128118

129119
```ts
130120
import * as React from 'react';
@@ -150,11 +140,11 @@ export const App = () => <GraphiQL fetcher={fetcher} />;
150140
ReactDOM.render(document.getElementByID('graphiql'), <App />);
151141
```
152142

153-
#### Custom `legacyClient` Example
143+
### Custom `legacyClient` Example
154144

155145
(not recommended)
156146

157-
By providing the `legacyClient` you can support a `subscriptions-transport-ws` client implementation, or equivalent
147+
By providing the `legacyClient` you can support a `subscriptions-transport-ws` client implementation, or equivalent:
158148

159149
```ts
160150
import * as React from 'react';
@@ -177,21 +167,15 @@ export const App = () => <GraphiQL fetcher={fetcher} />;
177167
ReactDOM.render(document.getElementByID('graphiql'), <App />);
178168
```
179169

180-
you will need to install the client separately:
181-
182-
```bash
183-
yarn add subscriptions-transport-ws
184-
```
170+
Note that you will need to install the client separately:
185171

186172
```bash
187173
npm install --save subscriptions-transport-ws
188174
```
189175

190-
and instantiate a client instance following their readme, and pass it as `legacyWsClient`.
191-
192-
#### Custom `fetcher` Example
176+
### Custom `fetcher` Example
193177

194-
For SSR, we might want to use something like `isomorphic-fetch`
178+
For SSR, we might want to use something like `isomorphic-fetch`:
195179

196180
```ts
197181
import * as React from 'react';

packages/graphiql-toolkit/package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@
3333
"graphql": "^15.5.0 || ^16.0.0",
3434
"graphql-ws": ">= 4.5.0"
3535
},
36+
"peerDependenciesMeta": {
37+
"graphql-ws": {
38+
"optional": true
39+
}
40+
},
3641
"keywords": [
3742
"graphql",
3843
"graphiql"

0 commit comments

Comments
 (0)