Mirror: The highly customizable and versatile GraphQL client with which you add on features like normalized caching as you grow.

Fix global eslint runner

+3
CONTRIBUTING.md
···
# Jest Tests for the current package:
yarn run test
+
# Linting (prettier & eslint):
+
yarn run lint
+
# Builds for the current package:
yarn run build
+1
exchanges/graphcache/package.json
···
"test": "jest",
"clean": "rimraf dist extras",
"check": "tsc --noEmit",
+
"lint": "eslint --ext=js,jsx,ts,tsx .",
"build": "rollup -c ../../scripts/rollup/config.js",
"prepare": "../../scripts/prepare/index.js",
"prepublishOnly": "run-s clean test build"
+1 -1
exchanges/graphcache/src/cacheExchange.ts
···
const cacheOps$ = pipe(
cache$,
filter(res => res.outcome === 'miss'),
-
map(res => addCacheOutcome(res.operation, res.outcome)),
+
map(res => addCacheOutcome(res.operation, res.outcome))
);
// Resolve OperationResults that the cache was able to assemble completely and trigger
+1
exchanges/suspense/package.json
···
"test": "jest",
"clean": "rimraf dist",
"check": "tsc --noEmit",
+
"lint": "eslint --ext=js,jsx,ts,tsx .",
"build": "rollup -c ../../scripts/rollup/config.js",
"prepare": "../../scripts/prepare/index.js",
"prepublishOnly": "run-s clean test build"
+5 -12
exchanges/suspense/src/suspenseExchange.test.ts
···
});
it('logs a warning if suspense mode is not activated', () => {
-
const warn = jest.spyOn(console, 'warn').mockImplementation(() => { /* noop */ });
+
const warn = jest.spyOn(console, 'warn').mockImplementation(() => {
+
/* noop */
+
});
const client = createClient({ url: 'https://example.com', suspense: false });
const forward = jest.fn(() => fromArray([]));
const ops = fromArray([]);
···
const resolveResult = jest.fn(
operation => ({ operation } as OperationResult)
);
-
const forward = ops =>
-
pipe(
-
ops,
-
map(resolveResult)
-
);
+
const forward = ops => pipe(ops, map(resolveResult));
const { source: ops, next: dispatch } = makeSubject<Operation>();
pipe(
···
const resolveResult = jest.fn(
operation => ({ operation } as OperationResult)
);
-
const forward = ops =>
-
pipe(
-
ops,
-
delay(1),
-
map(resolveResult)
-
);
+
const forward = ops => pipe(ops, delay(1), map(resolveResult));
const { source: ops, next: dispatch } = makeSubject<Operation>();
pipe(
+1 -1
package.json
···
"scripts": {
"test": "jest",
"check": "tsc",
-
"lint": "eslint .",
+
"lint": "eslint --ext=js,jsx,ts,tsx .",
"build": "./scripts/rollup/build.js"
},
"jest": {
+1
packages/core/package.json
···
"test": "jest",
"clean": "rimraf dist",
"check": "tsc --noEmit",
+
"lint": "eslint --ext=js,jsx,ts,tsx .",
"build": "rollup -c ../../scripts/rollup/config.js",
"prepare": "../../scripts/prepare/index.js",
"prepublishOnly": "run-s clean test build"
+8 -2
packages/core/src/client.ts
···
PromisifiedSource,
} from './types';
-
import { createRequest, toSuspenseSource, withPromise, maskTypename } from './utils';
+
import {
+
createRequest,
+
toSuspenseSource,
+
withPromise,
+
maskTypename,
+
} from './utils';
+
import { DocumentNode } from 'graphql';
/** Options for configuring the URQL [client]{@link Client}. */
···
map(res => {
res.data = maskTypename(res.data);
return res;
-
}),
+
})
);
}
+5 -1
packages/core/src/exchanges/cache.ts
···
),
]),
map(op => addMetadata(op, { cacheOutcome: 'miss' })),
-
filter(op => op.operationName !== 'query' || op.context.requestPolicy !== 'cache-only'),
+
filter(
+
op =>
+
op.operationName !== 'query' ||
+
op.context.requestPolicy !== 'cache-only'
+
),
forward,
tap(response => {
if (
+5 -3
packages/core/src/exchanges/subscription.ts
···
complete();
}
},
-
})
+
});
});
return () => {
···
const isSubscriptionOperation = (operation: Operation): boolean => {
const { operationName } = operation;
-
return operationName === 'subscription' ||
+
return (
+
operationName === 'subscription' ||
(!!enableAllOperations &&
-
(operationName === 'query' || operationName === 'mutation'));
+
(operationName === 'query' || operationName === 'mutation'))
+
);
};
return ops$ => {
+16 -17
packages/core/src/utils/maskTypename.test.ts
···
import { maskTypename } from './maskTypename';
it('strips typename from flat objects', () => {
-
expect(
-
maskTypename({ __typename: 'Todo', id: 1 })
-
).toEqual({ id: 1 });
+
expect(maskTypename({ __typename: 'Todo', id: 1 })).toEqual({ id: 1 });
});
it('strips typename from flat objects containing dates', () => {
const date = new Date();
-
expect(
-
maskTypename({ __typename: 'Todo', id: 1, date })
-
).toEqual({ id: 1, date });
+
expect(maskTypename({ __typename: 'Todo', id: 1, date })).toEqual({
+
id: 1,
+
date,
+
});
});
it('strips typename from nested objects', () => {
···
id: 1,
author: {
id: 2,
-
__typename: 'Author'
-
}
+
__typename: 'Author',
+
},
})
).toEqual({ id: 1, author: { id: 2 } });
});
···
id: 2,
__typename: 'Author',
books: [
-
{ id: 3, __typename: 'Book', review: { id: 8, __typename: 'Review' } },
+
{
+
id: 3,
+
__typename: 'Book',
+
review: { id: 8, __typename: 'Review' },
+
},
{ id: 4, __typename: 'Book' },
{ id: 5, __typename: 'Book' },
-
]
-
}
+
],
+
},
})
).toEqual({
id: 1,
author: {
id: 2,
-
books: [
-
{ id: 3, review: { id: 8 } },
-
{ id: 4 },
-
{ id: 5 },
-
]
-
}
+
books: [{ id: 3, review: { id: 8 } }, { id: 4 }, { id: 5 }],
+
},
});
});
+1 -1
packages/core/src/utils/maskTypename.ts
···
return acc;
}, {});
-
}
+
};
+1 -1
packages/core/src/utils/stringifyVariables.test.ts
···
});
it('stringifies date correctly', () => {
-
const date =new Date('2019-12-11T04:20:00');
+
const date = new Date('2019-12-11T04:20:00');
expect(stringifyVariables(date)).toBe(date.toJSON());
});
+1 -5
packages/core/src/utils/withPromise.ts
···
export function withPromise<T>(source$: Source<T>): PromisifiedSource<T> {
(source$ as PromisifiedSource<T>).toPromise = () =>
-
pipe(
-
source$,
-
take(1),
-
toPromise
-
);
+
pipe(source$, take(1), toPromise);
return source$ as PromisifiedSource<T>;
}
+1
packages/preact-urql/package.json
···
"test": "jest",
"clean": "rimraf dist",
"check": "tsc --noEmit",
+
"lint": "eslint --ext=js,jsx,ts,tsx .",
"build": "rollup -c ../../scripts/rollup/config.js",
"prepare": "../../scripts/prepare/index.js",
"prepublishOnly": "run-s clean test build"
+2
packages/preact-urql/src/hooks/useImmediateEffect.ts
···
+
/* eslint-disable react-hooks/exhaustive-deps */
+
import { useRef, useEffect, EffectCallback } from 'preact/hooks';
import { noop } from './useQuery';
+3 -1
packages/preact-urql/src/hooks/useImmediateState.ts
···
+
/* eslint-disable react-hooks/exhaustive-deps */
+
import {
useRef,
useState,
···
setState(action);
}
},
-
[]
+
[state]
);
useIsomorphicLayoutEffect(() => {
+1 -1
packages/preact-urql/src/hooks/useMutation.ts
···
return pipe(
client.executeMutation(
createRequest(query, variables as any),
-
context || {},
+
context || {}
),
toPromise
).then(result => {
+8 -1
packages/preact-urql/src/hooks/useQuery.ts
···
);
unsubscribe.current = result.unsubscribe;
},
-
[setState, client, request, args.requestPolicy, args.pollInterval, args.context]
+
[
+
setState,
+
client,
+
request,
+
args.requestPolicy,
+
args.pollInterval,
+
args.context,
+
]
);
useImmediateEffect(() => {
+1
packages/react-urql/package.json
···
"test": "jest",
"clean": "rimraf dist",
"check": "tsc --noEmit",
+
"lint": "eslint --ext=js,jsx,ts,tsx .",
"build": "rollup -c ../../scripts/rollup/config.js",
"prepare": "../../scripts/prepare/index.js",
"prepublishOnly": "run-s clean test build"
+2
packages/react-urql/src/components/Mutation.test.tsx
···
+
/* eslint-disable react-hooks/rules-of-hooks */
+
jest.mock('../context', () => {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { delay, fromValue, pipe } = require('wonka');
+3 -4
packages/react-urql/src/hooks/useMutation.test.tsx
···
+
/* eslint-disable react-hooks/rules-of-hooks */
+
// Note: Testing for hooks is not yet supported in Enzyme - https://github.com/airbnb/enzyme/issues/2011
jest.mock('../context', () => {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { delay, fromValue, pipe } = require('wonka');
const mock = {
executeMutation: jest.fn(() =>
-
pipe(
-
fromValue({ data: 1, error: 2, extensions: { i: 1 } }),
-
delay(200)
-
)
+
pipe(fromValue({ data: 1, error: 2, extensions: { i: 1 } }), delay(200))
),
};
+1 -1
packages/react-urql/src/hooks/useMutation.ts
···
return pipe(
client.executeMutation(
createRequest(query, variables as any),
-
context || {},
+
context || {}
),
toPromise
).then(result => {
+3 -1
packages/react-urql/src/hooks/useQuery.spec.ts
···
+
/* eslint-disable react-hooks/rules-of-hooks */
+
import { renderHook, act } from '@testing-library/react-hooks';
import { interval, map, pipe } from 'wonka';
import { RequestPolicy } from '@urql/core';
···
};
return {
-
useClient: () => mock
+
useClient: () => mock,
};
});
+2
packages/react-urql/src/hooks/useQuery.test.tsx
···
+
/* eslint-disable react-hooks/rules-of-hooks */
+
// Note: Testing for hooks is not yet supported in Enzyme - https://github.com/airbnb/enzyme/issues/2011
jest.mock('../context', () => {
// eslint-disable-next-line @typescript-eslint/no-var-requires
+2
packages/react-urql/src/hooks/useSubscription.test.tsx
···
+
/* eslint-disable react-hooks/rules-of-hooks */
+
// Note: Testing for hooks is not yet supported in Enzyme - https://github.com/airbnb/enzyme/issues/2011
jest.mock('../context', () => {
const d = { data: 1234, error: 5678 };
+3 -9
packages/react-urql/src/test-utils/ssr.test.tsx
···
OperationContext,
GraphQLRequest,
Operation,
-
OperationResult
+
OperationResult,
} from '@urql/core';
import { Provider } from '../context';
···
let promise;
try {
-
pipe(
-
client.executeRequestOperation(queryOperation),
-
publish
-
);
+
pipe(client.executeRequestOperation(queryOperation), publish);
} catch (error) {
promise = error;
}
···
ssr.restoreData({ [queryOperation.key]: queryResponse });
expect(() => {
-
pipe(
-
client.executeRequestOperation(queryOperation),
-
publish
-
);
+
pipe(client.executeRequestOperation(queryOperation), publish);
}).not.toThrow();
const data = ssr.extractData();
+1
packages/site/package.json
···
"scripts": {
"start": "react-static start",
"build": "react-static build",
+
"lint": "eslint --ext=js,jsx .",
"clean": "rimraf dist",
"prepublishOnly": "run-s clean build"
},
+1
packages/svelte-urql/package.json
···
"test": "jest",
"clean": "rimraf dist",
"check": "tsc --noEmit",
+
"lint": "eslint --ext=js,jsx,ts,tsx .",
"build": "rollup -c ../../scripts/rollup/config.js",
"prepare": "../../scripts/prepare/index.js",
"prepublishOnly": "run-s clean test build"
+3 -3
packages/svelte-urql/src/createClient.ts
···
-
import { createClient, ClientOptions, Client } from '@urql/core';
+
import { createClient, ClientOptions, Client } from '@urql/core';
import { setClient } from './context/setClient';
export const createSvelteClient = (args: ClientOptions): Client => {
-
const client = createClient(args)
+
const client = createClient(args);
setClient(client);
return client;
-
}
+
};
+1
scripts/eslint/preset.js
···
'@typescript-eslint/no-object-literal-type-assertion': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/interface-name-prefix': 'off',
+
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/array-type': 'off',
'react-hooks/rules-of-hooks': 'error',