Skip to content

Commit

Permalink
Remove @graphiql/create-fetcher package
Browse files Browse the repository at this point in the history
  • Loading branch information
harshithpabbati committed Feb 6, 2021
1 parent 3c4dd35 commit ed515c2
Show file tree
Hide file tree
Showing 11 changed files with 12 additions and 511 deletions.
5 changes: 5 additions & 0 deletions .changeset/good-experts-flash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphiql/toolkit': patch
---

Move @graphiql/create-fetcher to @graphiql/toolkit
19 changes: 0 additions & 19 deletions packages/graphiql-create-fetcher/CHANGELOG.md

This file was deleted.

146 changes: 4 additions & 142 deletions packages/graphiql-create-fetcher/README.md
Original file line number Diff line number Diff line change
@@ -1,147 +1,9 @@
## `@graphiql/create-fetcher`

a utility for generating a full-featured `fetcher` for GraphiQL including `@stream`, `@defer` `IncrementalDelivery`and `multipart`
This package is moved to `@graphiql-toolkit`.

under the hood, it uses [`graphql-ws`](https://www.npmjs.com/package/graphql-ws) 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
Documentation of create-fetcher is moved to [toolkit](https://github.com/graphql/graphiql/tree/main/packages/graphiql-toolkit/docs/create-fetcher.md).

### Setup
## Credits

[`graphiql`](https://npmjs.com/package/graphiql) and thus `react` and `react-dom` should already be installed.

you'll need to install `@graphiql/create-fetcher`

npm

```bash
npm install --save @graphiql/create-fetcher
```

yarn

```bash
yarn add @graphiql/create-fetcher
```

### 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.

#### HTTP/Multipart Usage

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

```ts
import * as React from 'react';
import ReactDOM from 'react-dom';
import { GraphiQL } from 'graphiql';
import { createGraphiQLFetcher } from '@graphiql/create-fetcher';

const url = 'https://myschema.com/graphql';

const fetcher = createGraphiQLFetcher({ url });

export const App = () => <GraphiQL fetcher={fetcher} />;

ReactDOM.render(document.getElementByID('graphiql'), <App />);
```

#### HTTP/Multipart & Websockets

Just by providing the `subscriptionUrl`, you can generate a `graphql-ws` client

```ts
import * as React from 'react';
import ReactDOM from 'react-dom';
import { GraphiQL } from 'graphiql';
import { createGraphiQLFetcher } from '@graphiql/create-fetcher';

const url = 'https://myschema.com/graphql';

const subscriptionUrl = 'wss://myschema.com/graphql';

const fetcher = createGraphiQLFetcher({
url,
subscriptionUrl,
});

export const App = () => <GraphiQL fetcher={fetcher} />;

ReactDOM.render(document.getElementByID('graphiql'), <App />);
```

You can further customize the `wsClient` implementation below

### Options

#### `url` (_required_)

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

#### `subscriptionUrl`

This generates a `graphql-ws` client.

#### `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.

#### `headers`

Pass headers to any and all requests

#### `fetch`

Pass a custom fetch implementation such as `isomorphic-feth`

### Customization Examples

#### Custom `wsClient` Example

Just by providing the `subscriptionUrl`

```ts
import * as React from 'react';
import ReactDOM from 'react-dom';
import { GraphiQL } from 'graphiql';
import { createClient } from 'graphql-ws';
import { createGraphiQLFetcher } from '@graphiql/create-fetcher';

const url = 'https://myschema.com/graphql';

const subscriptionUrl = 'wss://myschema.com/graphql';

const fetcher = createGraphiQLFetcher({
url,
wsClient: createClient({
url: subscriptionUrl,
keepAlive: 2000,
}),
});

export const App = () => <GraphiQL fetcher={fetcher} />;

ReactDOM.render(document.getElementByID('graphiql'), <App />);
```

#### Custom `fetcher` Example

For SSR, we might want to use something like `isomorphic-fetch`

```ts
import * as React from 'react';
import ReactDOM from 'react-dom';
import { GraphiQL } from 'graphiql';
import { fetch } from 'isomorphic-fetch';
import { createGraphiQLFetcher } from '@graphiql/create-fetcher';

const url = 'https://myschema.com/graphql';

const fetcher = createGraphiQLFetcher({
url,
fetch,
});

export const App = () => <GraphiQL fetcher={fetcher} />;

ReactDOM.render(document.getElementByID('graphiql'), <App />);
```
This is inspired from `graphql-subscriptions-fetcher` and thanks to @Urigo
5 changes: 0 additions & 5 deletions packages/graphiql-create-fetcher/jest.config.js

This file was deleted.

33 changes: 0 additions & 33 deletions packages/graphiql-create-fetcher/package.json

This file was deleted.

77 changes: 0 additions & 77 deletions packages/graphiql-create-fetcher/src/createFetcher.ts

This file was deleted.

2 changes: 0 additions & 2 deletions packages/graphiql-create-fetcher/src/index.ts

This file was deleted.

Loading

0 comments on commit ed515c2

Please sign in to comment.