Skip to content

Commit a1e733e

Browse files
committed
chore: format/eslint fixes
1 parent c9dab6a commit a1e733e

File tree

23 files changed

+598
-208
lines changed

23 files changed

+598
-208
lines changed

.eslintrc.js

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ module.exports = {
3030
node: true,
3131
browser: true,
3232
jest: true,
33+
'jest/globals': true,
3334
},
3435

3536
extends: [
@@ -294,6 +295,9 @@ module.exports = {
294295
'react/prefer-stateless-function': 'error',
295296
'react/react-in-jsx-scope': 'error',
296297
'react/self-closing-comp': 'error',
298+
'react/display-name': 'warn',
299+
// Jest rules
300+
'jest/no-conditional-expect': 0,
297301
},
298302

299303
plugins: ['import', 'prefer-object-spread', '@typescript-eslint'],
@@ -310,14 +314,18 @@ module.exports = {
310314
},
311315
},
312316
{
317+
excludedFiles: ['**/cypress/**/*.{js,ts}'],
313318
files: [
314-
'packages/{*graphql-*,graphiql}/src/**',
315319
'**/__{tests,mocks}__/*.{js,jsx,ts,tsx}',
320+
'**/*.spec.{ts,js.jsx.tsx}',
316321
],
317322
extends: ['plugin:jest/recommended'],
318323
env: {
319324
'jest/globals': true,
320325
},
326+
rules: {
327+
'jest/no-conditional-expect': 0,
328+
},
321329
},
322330
// Rules for TypeScript only
323331
{
@@ -326,28 +334,6 @@ module.exports = {
326334
'no-unused-vars': 'off',
327335
},
328336
},
329-
// Rules for Babel & Flow only
330-
{
331-
files: ['packages/codemirror-graphql/src/**/*.js'],
332-
parser: 'babel-eslint',
333-
plugins: ['flowtype', 'babel'],
334-
rules: {
335-
// flowtype (https://github.com/gajus/eslint-plugin-flowtype)
336-
'flowtype/boolean-style': 1,
337-
'flowtype/define-flow-type': 1,
338-
'flowtype/no-dupe-keys': 0,
339-
'flowtype/no-primitive-constructor-types': 1,
340-
'flowtype/no-weak-types': 0,
341-
'flowtype/require-parameter-type': 0,
342-
'flowtype/require-return-type': 0,
343-
'flowtype/require-valid-file-annotation': 0,
344-
'flowtype/require-variable-type': 0,
345-
'flowtype/sort-keys': 0,
346-
'flowtype/type-id-match': 0,
347-
'flowtype/use-flow-type': 1,
348-
'flowtype/valid-syntax': 0,
349-
},
350-
},
351337
{
352338
// Converted from 'dependencies' options in ancient config
353339
files: ['**/spec/**', '**/sample-*/**'],

package.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
"eslint": "eslint --ext=ts,js,jsx,tsx .",
5151
"lint": "yarn eslint && yarn lint-check && yarn pretty-check",
5252
"lint-fix": "yarn eslint --fix",
53-
"lint-check": "eslint --print-config .eslintrc.js | eslint-config-prettier-check",
53+
"lint-check": "eslint-config-prettier .eslintrc.js",
5454
"check": "flow check --show-all-errors && yarn tsc --dry",
5555
"pretty": "node resources/pretty.js",
5656
"pretty-check": "node resources/pretty.js --check",
@@ -88,24 +88,24 @@
8888
"@types/prettier": "^2.0.0",
8989
"@types/theme-ui": "^0.3.1",
9090
"@types/ws": "^7.4.0",
91-
"@typescript-eslint/eslint-plugin": "^2.27.0",
92-
"@typescript-eslint/parser": "^2.27.0",
91+
"@typescript-eslint/eslint-plugin": "^4.14.0",
92+
"@typescript-eslint/parser": "^4.14.0",
9393
"babel-eslint": "^10.1.0",
9494
"babel-jest": "^25.3.0",
9595
"conventional-changelog-conventionalcommits": "^4.2.3",
9696
"copy": "^0.3.2",
9797
"cross-env": "^7.0.2",
9898
"cypress": "^4.7.0",
99-
"eslint": "^6.8.0",
100-
"eslint-config-prettier": "^6.10.1",
99+
"eslint": "^7.18.0",
100+
"eslint-config-prettier": "^7.2.0",
101101
"eslint-plugin-babel": "^5.3.0",
102102
"eslint-plugin-cypress": "^2.10.3",
103103
"eslint-plugin-flowtype": "4.7.0",
104104
"eslint-plugin-import": "^2.20.2",
105-
"eslint-plugin-jest": "^23.8.2",
106-
"eslint-plugin-prefer-object-spread": "1.2.1",
107-
"eslint-plugin-react": "7.19.0",
108-
"eslint-plugin-react-hooks": "^3.0.0",
105+
"eslint-plugin-jest": "^24.1.3",
106+
"eslint-plugin-prefer-object-spread": "^1.2.1",
107+
"eslint-plugin-react": "^7.22.0",
108+
"eslint-plugin-react-hooks": "^4.2.0",
109109
"fetch-mock": "6.5.2",
110110
"flow-bin": "^0.119.1",
111111
"graphql": "^15.4.0",

packages/graphiql-2-rfc-context/src/components/__tests__/GraphiQL.spec.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ describe('GraphiQL', () => {
251251
expect(container.querySelectorAll('.history-label')).toHaveLength(2);
252252
});
253253

254-
it('will save query if variables are different ', () => {
254+
it('will save query if variables are different', () => {
255255
const { getByTitle, container } = render(
256256
<GraphiQL
257257
fetcher={noOpFetcher}
@@ -276,7 +276,7 @@ describe('GraphiQL', () => {
276276
expect(container.querySelectorAll('.history-label')).toHaveLength(2);
277277
});
278278

279-
it('will save query if headers are different ', () => {
279+
it('will save query if headers are different', () => {
280280
const { getByTitle, getByText, container } = render(
281281
<GraphiQL
282282
fetcher={noOpFetcher}
@@ -308,9 +308,6 @@ describe('GraphiQL', () => {
308308
const MyFunctionalComponent = () => {
309309
return null;
310310
};
311-
const wrap = component => () => (
312-
<div className="test-wrapper">{component}</div>
313-
);
314311

315312
it('properly ignores fragments', () => {
316313
const myFragment = (

packages/graphiql-2-rfc-context/src/utility/__tests__/mergeAst.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const schema = new GraphQLSchema({
3030

3131
describe('MergeAst', () => {
3232
fixtures.forEach(fixture => {
33-
it(fixture.desc, () => {
33+
it(`${fixture.desc}`, () => {
3434
const result = print(mergeAst(parse(fixture.query))).replace(/\s/g, '');
3535
const result2 = print(mergeAst(parse(fixture.query), schema)).replace(
3636
/\s/g,

packages/graphiql-build-fetcher/README.md

Lines changed: 52 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -6,71 +6,74 @@ under the hood, it uses [`graphql-ws`](https://www.npmjs.com/package/graphql-ws)
66

77
### Setup
88

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

1111
you'll need to install `@graphiql/build-fetcher`
1212

1313
npm
14+
1415
```bash
1516
npm install --save @graphiql/build-fetcher
1617
```
1718

1819
yarn
20+
1921
```bash
2022
yarn add @graphiql/build-fetcher
2123
```
2224

2325
### Getting Started
2426

25-
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.
27+
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.
2628

2729
#### HTTP/Multipart Usage
2830

2931
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!).
3032

3133
```ts
32-
import * as React from "react"
33-
import ReactDOM from "react-dom"
34-
import { GraphiQL } from "graphiql"
35-
import { buildGraphiQLFetcher } from "@graphiql/build-fetcher"
34+
import * as React from 'react';
35+
import ReactDOM from 'react-dom';
36+
import { GraphiQL } from 'graphiql';
37+
import { buildGraphiQLFetcher } from '@graphiql/build-fetcher';
3638

37-
const url = 'https://myschema.com/graphql'
39+
const url = 'https://myschema.com/graphql';
3840

3941
const fetcher = buildGraphiQLFetcher({ url });
4042

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

43-
ReactDOM.render(document.getElementByID('graphiql'), <App />)
45+
ReactDOM.render(document.getElementByID('graphiql'), <App />);
4446
```
45-
#### HTTP/Multipart & Websockets
47+
48+
#### HTTP/Multipart & Websockets
4649

4750
Just by providing the `subscriptionsUrl`, you can generate a `graphql-ws` client
4851

4952
```ts
50-
import * as React from "react"
51-
import ReactDOM from "react-dom"
52-
import { GraphiQL } from "graphiql"
53-
import { buildGraphiQLFetcher } from "@graphiql/build-fetcher"
53+
import * as React from 'react';
54+
import ReactDOM from 'react-dom';
55+
import { GraphiQL } from 'graphiql';
56+
import { buildGraphiQLFetcher } from '@graphiql/build-fetcher';
5457

55-
const url = 'https://myschema.com/graphql'
58+
const url = 'https://myschema.com/graphql';
5659

57-
const subscriptionsUrl = "wss://myschema.com/graphql"
60+
const subscriptionsUrl = 'wss://myschema.com/graphql';
5861

59-
const fetcher = buildGraphiQLFetcher({
60-
url,
61-
subscriptionsUrl
62+
const fetcher = buildGraphiQLFetcher({
63+
url,
64+
subscriptionsUrl,
6265
});
6366

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

66-
ReactDOM.render(document.getElementByID('graphiql'), <App />)
69+
ReactDOM.render(document.getElementByID('graphiql'), <App />);
6770
```
6871

6972
You can further customize the `wsClient` implementation below
7073

7174
### Options
7275

73-
#### `url` (*required*)
76+
#### `url` (_required_)
7477

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

@@ -92,55 +95,53 @@ Pass a custom fetch implementation such as `isomorphic-feth`
9295

9396
### Customization Examples
9497

95-
96-
9798
#### Custom `wsClient` Example
99+
98100
Just by providing the `subscriptionsUrl`
99101

100102
```ts
101-
import * as React from "react"
102-
import ReactDOM from "react-dom"
103-
import { GraphiQL } from "graphiql"
104-
import { createClient } from "graphql-ws"
105-
import { buildGraphiQLFetcher } from "@graphiql/build-fetcher"
106-
107-
const url = 'https://myschema.com/graphql'
108-
109-
const subscriptionsUrl = "wss://myschema.com/graphql"
110-
111-
const fetcher = buildGraphiQLFetcher({
112-
url,
113-
wsClient: createClient({
114-
url: subscriptionsUrl ,
115-
keepAlive: 2000
116-
})
103+
import * as React from 'react';
104+
import ReactDOM from 'react-dom';
105+
import { GraphiQL } from 'graphiql';
106+
import { createClient } from 'graphql-ws';
107+
import { buildGraphiQLFetcher } from '@graphiql/build-fetcher';
108+
109+
const url = 'https://myschema.com/graphql';
110+
111+
const subscriptionsUrl = 'wss://myschema.com/graphql';
112+
113+
const fetcher = buildGraphiQLFetcher({
114+
url,
115+
wsClient: createClient({
116+
url: subscriptionsUrl,
117+
keepAlive: 2000,
118+
}),
117119
});
118120

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

121-
ReactDOM.render(document.getElementByID('graphiql'), <App />)
123+
ReactDOM.render(document.getElementByID('graphiql'), <App />);
122124
```
123125

124-
125126
#### Custom `fetcher` Example
127+
126128
For SSR, we might want to use something like `isomorphic-fetch`
127129

128130
```ts
129-
import * as React from "react"
130-
import ReactDOM from "react-dom"
131-
import { GraphiQL } from "graphiql"
132-
import { fetch } from "isomorphic-fetch"
133-
import { buildGraphiQLFetcher } from "@graphiql/build-fetcher"
134-
135-
const url = 'https://myschema.com/graphql'
131+
import * as React from 'react';
132+
import ReactDOM from 'react-dom';
133+
import { GraphiQL } from 'graphiql';
134+
import { fetch } from 'isomorphic-fetch';
135+
import { buildGraphiQLFetcher } from '@graphiql/build-fetcher';
136136

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

138-
const fetcher = buildGraphiQLFetcher({
139-
url,
140-
fetch
139+
const fetcher = buildGraphiQLFetcher({
140+
url,
141+
fetch,
141142
});
142143

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

145-
ReactDOM.render(document.getElementByID('graphiql'), <App />)
146+
ReactDOM.render(document.getElementByID('graphiql'), <App />);
146147
```

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ import {
1717
} from '../lib';
1818
import { createClient } from 'graphql-ws';
1919

20-
const exampleWithSubscripton = /* GraphQL */ `
21-
subscription Example {
22-
example
23-
}
24-
query SomethingElse {
25-
example
26-
}
20+
const exampleWithSubscripton = /* GraphQL */ `
21+
subscription Example {
22+
example
23+
}
24+
query SomethingElse {
25+
example
26+
}
2727
`;
2828

2929
const exampleWithSubscriptonNode = parse(exampleWithSubscripton);
@@ -44,7 +44,6 @@ describe('buildGraphiQLFetcher', () => {
4444
expect(createMultipartFetcher.mock.calls).toEqual([
4545
[{ enableMultipart: true, url: serverURL }],
4646
]);
47-
4847
});
4948
it('returns fetcher without websocket client or multipart', () => {
5049
createWebsocketsClient.mockReturnValue(true);

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

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
11
import { parse } from 'graphql';
22
import { isSubcriptionWithName, createWebsocketsClient } from '../lib';
33

4-
import "isomorphic-fetch"
4+
import 'isomorphic-fetch';
55

6+
jest.mock('graphql-ws');
67

7-
jest.mock('graphql-ws')
8+
jest.mock('graphql-transport-ws');
89

9-
jest.mock("graphql-transport-ws")
10+
import { createClient } from 'graphql-ws';
1011

11-
12-
13-
import { createClient } from "graphql-ws"
14-
15-
import { createClient as createLegacyClient } from "graphql-transport-ws"
12+
import { createClient as createLegacyClient } from 'graphql-transport-ws';
1613

1714
const exampleWithSubscripton = /* GraphQL */ parse(`
1815
subscription Example {
@@ -44,14 +41,14 @@ describe('isSubcriptionWithName', () => {
4441
describe('createWebsocketsClient', () => {
4542
afterEach(() => {
4643
// @ts-ignore
47-
createClient.mockRestore()
48-
})
44+
createClient.mockRestore();
45+
});
4946
it('creates a websockets client using provided url', () => {
5047
createWebsocketsClient({
5148
url: 'https://example.com',
5249
subscriptionsUrl: 'wss://example.com',
5350
});
5451
// @ts-ignore
55-
expect(createClient.mock.calls[0][0]).toEqual({"url": "wss://example.com"})
52+
expect(createClient.mock.calls[0][0]).toEqual({ url: 'wss://example.com' });
5653
});
5754
});

0 commit comments

Comments
 (0)