Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move @graphiql/create-fetcher to @graphiql/toolkit #1788

Merged
merged 6 commits into from
Feb 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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` because it doesn't need to be it's own package as @imolorhe pointed out
13 changes: 2 additions & 11 deletions packages/codemirror-graphql/tsconfig.esm.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,10 @@
],
"references": [
{
"path": "../graphiql-toolkit/tsconfig.esm.json"
"path": "../graphql-language-service-interface"
},
{
"path": "../graphql-language-service/tsconfig.esm.json"
},
{
"path": "../graphql-language-service-interface/tsconfig.esm.json"
},
{
"path": "../graphql-language-service-parser/tsconfig.esm.json"
},
{
"path": "../graphql-language-service-utils/tsconfig.esm.json"
"path": "../graphql-language-service-parser"
}
]
}
6 changes: 0 additions & 6 deletions packages/codemirror-graphql/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,6 @@
],

"references": [
{
"path": "../graphql-language-service"
},
{
"path": "../graphql-language-service-utils"
},
{
"path": "../graphql-language-service-parser"
},
Expand Down
4 changes: 2 additions & 2 deletions packages/graphiql-2-rfc-context/tsconfig.esm.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
],
"references": [
{
"path": "../monaco-graphql/tsconfig.esm.json"
"path": "../monaco-graphql"
},
{
"path": "../graphql-language-service/tsconfig.esm.json"
"path": "../graphql-language-service"
}
]
}
19 changes: 0 additions & 19 deletions packages/graphiql-create-fetcher/CHANGELOG.md

This file was deleted.

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

This file was deleted.

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

This file was deleted.

51 changes: 0 additions & 51 deletions packages/graphiql-create-fetcher/src/types.ts

This file was deleted.

27 changes: 0 additions & 27 deletions packages/graphiql-create-fetcher/tsconfig.esm.json

This file was deleted.

28 changes: 0 additions & 28 deletions packages/graphiql-create-fetcher/tsconfig.json

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## `@graphiql/create-fetcher`
## Create Fetcher

a utility for generating a full-featured `fetcher` for GraphiQL including `@stream`, `@defer` `IncrementalDelivery`and `multipart`

Expand All @@ -8,18 +8,18 @@ under the hood, it uses [`graphql-ws`](https://www.npmjs.com/package/graphql-ws)

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

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

npm

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

yarn

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

### Getting Started
Expand All @@ -34,7 +34,7 @@ Here's a simple example. In this case, a websocket client isn't even initialized
import * as React from 'react';
import ReactDOM from 'react-dom';
import { GraphiQL } from 'graphiql';
import { createGraphiQLFetcher } from '@graphiql/create-fetcher';
import { createGraphiQLFetcher } from '@graphiql/toolkit';

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

Expand All @@ -53,7 +53,7 @@ Just by providing the `subscriptionUrl`, you can generate a `graphql-ws` client
import * as React from 'react';
import ReactDOM from 'react-dom';
import { GraphiQL } from 'graphiql';
import { createGraphiQLFetcher } from '@graphiql/create-fetcher';
import { createGraphiQLFetcher } from '@graphiql/toolkit';

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

Expand Down Expand Up @@ -104,7 +104,7 @@ 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';
import { createGraphiQLFetcher } from '@graphiql/toolkit';

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

Expand Down Expand Up @@ -132,7 +132,7 @@ 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';
import { createGraphiQLFetcher } from '@graphiql/toolkit';

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

Expand All @@ -145,3 +145,7 @@ export const App = () => <GraphiQL fetcher={fetcher} />;

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

## Credits

This is inspired from `graphql-subscriptions-fetcher` and thanks to @Urigo
10 changes: 10 additions & 0 deletions packages/graphiql-toolkit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@
"module": "esm/index.js",
"types": "dist/index.d.ts",
"scripts": {},
"dependencies": {
"graphql-ws": "^4.1.0",
"subscriptions-transport-ws": "^0.9.18",
"meros": "^1.1.0-beta.2",
"@n1ru4l/push-pull-async-iterable-iterator": "^2.0.1"
},
"devDependencies": {
"isomorphic-fetch": "^3.0.0",
"graphql": "experimental-stream-defer"
},
"keywords": [
"graphql",
"graphiql"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { Fetcher } from '@graphiql/toolkit';
import type { CreateFetcherOptions } from './types';
import type { Fetcher, CreateFetcherOptions } from './types';

import {
createMultipartFetcher,
Expand Down
1 change: 1 addition & 0 deletions packages/graphiql-toolkit/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './types';
export { createGraphiQLFetcher } from './createFetcher';

// TODO: move the most useful utilities from graphiql to here
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import type {
FetcherParams,
FetcherOpts,
FetcherResultPayload,
} from '@graphiql/toolkit';
import type { CreateFetcherOptions } from './types';
CreateFetcherOptions,
} from './types';

/**
* Returns true if the name matches a subscription in the AST
Expand Down
50 changes: 50 additions & 0 deletions packages/graphiql-toolkit/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import type { DocumentNode, IntrospectionQuery } from 'graphql';
import type { Client, ClientOptions } from 'graphql-ws';
import type { SubscriptionClient } from 'subscriptions-transport-ws';

export type Observable<T> = {
subscribe(opts: {
Expand Down Expand Up @@ -67,3 +69,51 @@ export type Fetcher = (
graphQLParams: FetcherParams,
opts?: FetcherOpts,
) => FetcherReturnType;

export type WebsocketsClient = Client | SubscriptionClient;

/**
* Options for creating a simple, spec-compliant GraphiQL fetcher
*/
export interface CreateFetcherOptions {
/**
* url for HTTP(S) requests. required!
*/
url: string;
/**
* url for websocket subscription requests
*/
subscriptionUrl?: string;
/**
* `wsClient` implementation that matches `ws-graphql` signature,
* whether via `createClient()` itself or another client.
*/
wsClient?: Client;
/**
* Headers you can provide statically.
*
* If you enable the headers editor and the user provides
* A header you set statically here, it will be overriden by their value.
*/
headers?: Record<string, string>;
/**
* Websockets connection params used when you provide subscriptionUrl. graphql-ws `ClientOptions.connectionParams`
*/
wsConnectionParams?: ClientOptions['connectionParams'];
/**
* You can disable the usage of the `fetch-multipart-graphql` library
* entirely, defaulting to a simple fetch POST implementation.
*/
enableIncrementalDelivery?: boolean;
/**
* The fetch implementation, in case the user needs to override this for SSR
* or other purposes. this does not override the `fetch-multipart-graphql`
* default fetch behavior yet.
*/
fetch?: typeof fetch;
/**
* An optional custom fetcher specifically for your schema. For most cases
* the `url` and `headers` property should have you covered.
*/
schemaFetcher?: Fetcher;
}
Loading