-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove @graphiql/create-fetcher package
- Loading branch information
1 parent
3c4dd35
commit ed515c2
Showing
11 changed files
with
12 additions
and
511 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@graphiql/toolkit': patch | ||
--- | ||
|
||
Move @graphiql/create-fetcher to @graphiql/toolkit |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.