Skip to content

Commit e32555a

Browse files
committed
chore: types, cleanup, rename it, end to end tests
1 parent ba7e7c0 commit e32555a

33 files changed

+178
-198
lines changed

.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
engine-strict=true
2+
access=public

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
"eslint": "eslint --ext=ts,js,jsx,tsx .",
5353
"lint": "yarn eslint && yarn lint-check && yarn pretty-check",
5454
"lint-fix": "yarn eslint --fix",
55-
"lint-check": "eslint-config-prettier .eslintrc.js",
55+
"lint-check": "eslint --print-config .eslintrc.js | eslint-config-prettier-check",
5656
"check": "flow check --show-all-errors && yarn tsc --dry",
5757
"pretty": "node resources/pretty.js",
5858
"pretty-check": "node resources/pretty.js --check",

packages/graphiql-build-fetcher/src/index.ts

Lines changed: 0 additions & 2 deletions
This file was deleted.

packages/graphiql-build-fetcher/test/server.ts

Lines changed: 0 additions & 90 deletions
This file was deleted.

packages/graphiql-build-fetcher/README.md renamed to packages/graphiql-create-fetcher/README.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## `@graphiql/build-fetcher`
1+
## `@graphiql/create-fetcher`
22

33
a utility for generating a full-featured fetcher for GraphiQL.
44

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

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

11-
you'll need to install `@graphiql/build-fetcher`
11+
you'll need to install `@graphiql/create-fetcher`
1212

1313
npm
1414

1515
```bash
16-
npm install --save @graphiql/build-fetcher
16+
npm install --save @graphiql/create-fetcher
1717
```
1818

1919
yarn
2020

2121
```bash
22-
yarn add @graphiql/build-fetcher
22+
yarn add @graphiql/create-fetcher
2323
```
2424

2525
### Getting Started
@@ -34,11 +34,11 @@ Here's a simple example. In this case, a websocket client isn't even initialized
3434
import * as React from 'react';
3535
import ReactDOM from 'react-dom';
3636
import { GraphiQL } from 'graphiql';
37-
import { buildGraphiQLFetcher } from '@graphiql/build-fetcher';
37+
import { createGraphiQLFetcher } from '@graphiql/create-fetcher';
3838

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

41-
const fetcher = buildGraphiQLFetcher({ url });
41+
const fetcher = createGraphiQLFetcher({ url });
4242

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

@@ -53,13 +53,13 @@ Just by providing the `subscriptionUrl`, you can generate a `graphql-ws` client
5353
import * as React from 'react';
5454
import ReactDOM from 'react-dom';
5555
import { GraphiQL } from 'graphiql';
56-
import { buildGraphiQLFetcher } from '@graphiql/build-fetcher';
56+
import { createGraphiQLFetcher } from '@graphiql/create-fetcher';
5757

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

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

62-
const fetcher = buildGraphiQLFetcher({
62+
const fetcher = createGraphiQLFetcher({
6363
url,
6464
subscriptionUrl,
6565
});
@@ -104,13 +104,13 @@ import * as React from 'react';
104104
import ReactDOM from 'react-dom';
105105
import { GraphiQL } from 'graphiql';
106106
import { createClient } from 'graphql-ws';
107-
import { buildGraphiQLFetcher } from '@graphiql/build-fetcher';
107+
import { createGraphiQLFetcher } from '@graphiql/create-fetcher';
108108

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

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

113-
const fetcher = buildGraphiQLFetcher({
113+
const fetcher = createGraphiQLFetcher({
114114
url,
115115
wsClient: createClient({
116116
url: subscriptionUrl,
@@ -132,11 +132,11 @@ import * as React from 'react';
132132
import ReactDOM from 'react-dom';
133133
import { GraphiQL } from 'graphiql';
134134
import { fetch } from 'isomorphic-fetch';
135-
import { buildGraphiQLFetcher } from '@graphiql/build-fetcher';
135+
import { createGraphiQLFetcher } from '@graphiql/create-fetcher';
136136

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

139-
const fetcher = buildGraphiQLFetcher({
139+
const fetcher = createGraphiQLFetcher({
140140
url,
141141
fetch,
142142
});
Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "@graphiql/build-fetcher",
2+
"name": "@graphiql/create-fetcher",
33
"version": "0.0.1",
44
"description": "Utility to build a fetcher for GraphiQL",
55
"contributors": [
@@ -13,14 +13,8 @@
1313
"license": "MIT",
1414
"main": "dist/index.js",
1515
"module": "esm/index.js",
16-
"scripts": {
17-
"server": "ts-node test/server.ts"
18-
},
19-
"workspaces": {
20-
"nohoist": [
21-
"graphql"
22-
]
23-
},
16+
"types": "dist/index.d.ts",
17+
"scripts": {},
2418
"dependencies": {
2519
"graphql-ws": "^4.1.0",
2620
"subscriptions-transport-ws": "^0.9.18",
@@ -30,13 +24,6 @@
3024
},
3125
"devDependencies": {
3226
"isomorphic-fetch": "^3.0.0",
33-
"express": "^4.17.1",
34-
"express-graphql": "experimental-stream-defer",
35-
"ws": "^7.4.2",
36-
"ts-node": "^9.1.1",
37-
"graphql": "experimental-stream-defer"
38-
},
39-
"resolutions": {
4027
"graphql": "experimental-stream-defer"
4128
}
4229
}

packages/graphiql-build-fetcher/src/__tests__/buildFetcher.spec.ts renamed to packages/graphiql-create-fetcher/src/__tests__/buildFetcher.spec.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { parse, getIntrospectionQuery } from 'graphql';
2-
import { buildGraphiQLFetcher } from '../buildFetcher';
2+
import { createGraphiQLFetcher } from '../createFetcher';
33

44
import 'isomorphic-fetch';
55

@@ -32,13 +32,13 @@ const wssURL = 'ws://localhost:3000/graphql';
3232

3333
const exampleIntrospectionDocument = parse(getIntrospectionQuery());
3434

35-
describe('buildGraphiQLFetcher', () => {
35+
describe('createGraphiQLFetcher', () => {
3636
afterEach(() => {
3737
jest.resetAllMocks();
3838
});
3939
it('returns fetcher without websocket client by default', async () => {
4040
createWebsocketsFetcherFromUrl.mockReturnValue(true);
41-
const fetcher = buildGraphiQLFetcher({ url: serverURL });
41+
const fetcher = createGraphiQLFetcher({ url: serverURL });
4242
expect(createWebsocketsFetcherFromUrl.mock.calls).toEqual([]);
4343
expect(createMultipartFetcher.mock.calls).toEqual([
4444
[{ enableIncrementalDelivery: true, url: serverURL }],
@@ -47,7 +47,7 @@ describe('buildGraphiQLFetcher', () => {
4747

4848
it('returns simple fetcher for introspection', async () => {
4949
createSimpleFetcher.mockReturnValue(async () => 'hey!');
50-
const fetcher = buildGraphiQLFetcher({ url: serverURL });
50+
const fetcher = createGraphiQLFetcher({ url: serverURL });
5151
expect(createWebsocketsFetcherFromUrl.mock.calls).toEqual([]);
5252
expect(createMultipartFetcher.mock.calls).toEqual([
5353
[{ enableIncrementalDelivery: true, url: serverURL }],
@@ -66,7 +66,7 @@ describe('buildGraphiQLFetcher', () => {
6666
});
6767
it('returns fetcher without websocket client or multipart', () => {
6868
createWebsocketsFetcherFromUrl.mockReturnValue(true);
69-
buildGraphiQLFetcher({ url: serverURL, enableIncrementalDelivery: false });
69+
createGraphiQLFetcher({ url: serverURL, enableIncrementalDelivery: false });
7070
expect(createWebsocketsFetcherFromUrl.mock.calls).toEqual([]);
7171
expect(createMultipartFetcher.mock.calls).toEqual([]);
7272
expect(createSimpleFetcher.mock.calls).toEqual([
@@ -82,7 +82,7 @@ describe('buildGraphiQLFetcher', () => {
8282
enableIncrementalDelivery: true,
8383
};
8484

85-
buildGraphiQLFetcher(args);
85+
createGraphiQLFetcher(args);
8686

8787
expect(createMultipartFetcher.mock.calls).toEqual([[args]]);
8888
expect(createWebsocketsFetcherFromUrl.mock.calls).toEqual([
@@ -101,7 +101,7 @@ describe('buildGraphiQLFetcher', () => {
101101
enableIncrementalDelivery: true,
102102
};
103103

104-
buildGraphiQLFetcher(args);
104+
createGraphiQLFetcher(args);
105105

106106
expect(createMultipartFetcher.mock.calls).toEqual([[args]]);
107107
expect(createWebsocketsFetcherFromUrl.mock.calls).toEqual([]);

packages/graphiql-build-fetcher/src/__tests__/lib.spec.ts renamed to packages/graphiql-create-fetcher/src/__tests__/lib.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { parse } from 'graphql';
2-
import { isSubcriptionWithName, createWebsocketsFetcherFromUrl } from '../lib';
2+
import { isSubscriptionWithName, createWebsocketsFetcherFromUrl } from '../lib';
33

44
import 'isomorphic-fetch';
55

@@ -23,17 +23,17 @@ const exampleWithSubscripton = /* GraphQL */ parse(`
2323
describe('isSubcriptionWithName', () => {
2424
it('detects when the subscription is present', () => {
2525
expect(
26-
isSubcriptionWithName(exampleWithSubscripton, 'Example'),
26+
isSubscriptionWithName(exampleWithSubscripton, 'Example'),
2727
).toBeTruthy();
2828
});
2929
it('detects when the specified operation is not a subscription', () => {
3030
expect(
31-
isSubcriptionWithName(exampleWithSubscripton, 'SomethingElse'),
31+
isSubscriptionWithName(exampleWithSubscripton, 'SomethingElse'),
3232
).toBeFalsy();
3333
});
3434
it('detects when the operation is not present', () => {
3535
expect(
36-
isSubcriptionWithName(exampleWithSubscripton, 'NotPresent'),
36+
isSubscriptionWithName(exampleWithSubscripton, 'NotPresent'),
3737
).toBeFalsy();
3838
});
3939
});

packages/graphiql-build-fetcher/src/buildFetcher.ts renamed to packages/graphiql-create-fetcher/src/createFetcher.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import type { Fetcher } from '@graphiql/toolkit';
2-
import type { BuildFetcherOptions } from './types';
2+
import type { CreateFetcherOptions } from './types';
33

44
import {
55
createMultipartFetcher,
66
createSimpleFetcher,
7-
isSubcriptionWithName,
7+
isSubscriptionWithName,
88
createWebsocketsFetcherFromUrl,
99
createWebsocketsFetcherFromClient,
1010
} from './lib';
@@ -14,10 +14,10 @@ import {
1414
* - backwards compatible
1515
* - optionally supports graphql-ws or `
1616
*
17-
* @param options {BuildFetcherOptions}
17+
* @param options {CreateFetcherOptions}
1818
* @returns {Fetcher}
1919
*/
20-
export function buildGraphiQLFetcher(options: BuildFetcherOptions): Fetcher {
20+
export function createGraphiQLFetcher(options: CreateFetcherOptions): Fetcher {
2121
let httpFetch;
2222
let wsFetcher: null | Fetcher | void = null;
2323
if (typeof window !== null && window?.fetch) {
@@ -53,14 +53,14 @@ export function buildGraphiQLFetcher(options: BuildFetcherOptions): Fetcher {
5353
if (graphQLParams.operationName === 'IntrospectionQuery') {
5454
return simpleFetcher(graphQLParams, opts);
5555
}
56-
const isSubscription = isSubcriptionWithName(
56+
const isSubscription = isSubscriptionWithName(
5757
opts?.documentAST!,
5858
graphQLParams.operationName,
5959
);
6060
if (isSubscription) {
6161
if (!wsFetcher) {
6262
throw Error(
63-
`Your GraphiQL buildFetcher is not properly configured for websocket subscriptions yet. ${
63+
`Your GraphiQL createFetcher is not properly configured for websocket subscriptions yet. ${
6464
options.subscriptionUrl
6565
? `Provided URL ${options.subscriptionUrl} failed`
6666
: `Try providing options.subscriptionUrl or options.wsClient first.`
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export type { CreateFetcherOptions } from './types';
2+
export { createGraphiQLFetcher } from './createFetcher';

0 commit comments

Comments
 (0)