diff --git a/packages/dataloader/src/__tests__/MultiKeyMap.test.ts b/packages/dataloader/src/__tests__/MultiKeyMap.test.ts index 1224d892..c3b7886d 100644 --- a/packages/dataloader/src/__tests__/MultiKeyMap.test.ts +++ b/packages/dataloader/src/__tests__/MultiKeyMap.test.ts @@ -32,7 +32,6 @@ test('twoLevels', () => { expect(cache.get([1, 3])).toBe(undefined); expect(cache.get([3, 1])).toBe(undefined); - debugger; cache.delete([1, 1]); expect(cache.size).toBe(3); expect(cache.get([1, 1])).toBe(undefined); diff --git a/packages/dataloader/src/__tests__/dedupeAsync.test.ts b/packages/dataloader/src/__tests__/dedupeAsync.test.ts index ba2a4952..b32cfacb 100644 --- a/packages/dataloader/src/__tests__/dedupeAsync.test.ts +++ b/packages/dataloader/src/__tests__/dedupeAsync.test.ts @@ -42,8 +42,8 @@ test('dedupeAsync', async () => { ).toEqual([{source: 'hello'}, {source: 'world'}, 'Errored', undefined]); }); - expect(load.cache.get('hello')).resolves.toEqual({source: 'hello'}); - expect(load.cache.get('world')).resolves.toEqual({source: 'world'}); + await expect(load.cache.get('hello')).resolves.toEqual({source: 'hello'}); + await expect(load.cache.get('world')).resolves.toEqual({source: 'world'}); load.cache.delete('hello'); load.cache.set('world', {source: 'from set'}); @@ -107,8 +107,12 @@ test('dedupeAsync - mapKey', async () => { ).toEqual([{source: 'hello'}, {source: 'world'}, 'Errored']); }); - expect(load.cache.get({id: 'hello'})).resolves.toEqual({source: 'hello'}); - expect(load.cache.get({id: 'world'})).resolves.toEqual({source: 'world'}); + await expect(load.cache.get({id: 'hello'})).resolves.toEqual({ + source: 'hello', + }); + await expect(load.cache.get({id: 'world'})).resolves.toEqual({ + source: 'world', + }); load.cache.delete({id: 'hello'}); load.cache.set({id: 'world'}, {source: 'from set'}); @@ -219,8 +223,12 @@ test('dedupeAsync - WeakMap', async () => { ).toEqual([{source: 'hello'}, {source: 'world'}, 'Errored']); }); - expect(load.cache.get(HELLO_REQUEST)).resolves.toEqual({source: 'hello'}); - expect(load.cache.get(WORLD_REQUEST)).resolves.toEqual({source: 'world'}); + await expect(load.cache.get(HELLO_REQUEST)).resolves.toEqual({ + source: 'hello', + }); + await expect(load.cache.get(WORLD_REQUEST)).resolves.toEqual({ + source: 'world', + }); load.cache.delete(HELLO_REQUEST); load.cache.set(WORLD_REQUEST, {source: 'from set'}); diff --git a/packages/dataloader/src/__tests__/groupToMap.test.ts b/packages/dataloader/src/__tests__/groupToMap.test.ts index af603744..48bf309e 100644 --- a/packages/dataloader/src/__tests__/groupToMap.test.ts +++ b/packages/dataloader/src/__tests__/groupToMap.test.ts @@ -26,6 +26,7 @@ test('groupToMap', () => { }); test('groupToMap - sparse array', () => { + /* tslint:disable:no-sparse-arrays*/ const result = groupBy([1, , 3], (x) => x); expect(result(undefined)).toEqual([undefined]); expect(result(1)).toEqual([1]); diff --git a/packages/dataloader/src/__tests__/requestsTester.ts b/packages/dataloader/src/__tests__/requestsTester.ts index 1961a7d5..3aef8648 100644 --- a/packages/dataloader/src/__tests__/requestsTester.ts +++ b/packages/dataloader/src/__tests__/requestsTester.ts @@ -37,6 +37,7 @@ export default function requestsTester(): RequestsTester { requests = null; }; + /* tslint:disable:no-unbound-method */ if (fnResult && typeof fnResult.then === 'function') { return fnResult.then(afterFn); } else { diff --git a/packages/dataloader/src/batch.ts b/packages/dataloader/src/batch.ts index 2b14f08e..23aa26c9 100644 --- a/packages/dataloader/src/batch.ts +++ b/packages/dataloader/src/batch.ts @@ -44,7 +44,7 @@ class Batch { return this._requests.length; } - loadOne(key: TKey): Promise { + async loadOne(key: TKey): Promise { return new Promise((resolve, reject) => { if (this._started) { reject( @@ -93,10 +93,11 @@ export default function batch( ): (key: TKey) => Promise { const {maxBatchSize, batchScheduleFn} = normalizeBatchOptions(options); let batch: Batch | null = null; - return (key: TKey): Promise => { + return async (key: TKey): Promise => { if (batch === null) { const newBatch = new Batch(load); batch = newBatch; + /* tslint:disable:no-floating-promises */ batchScheduleFn().then(() => { if (batch === newBatch) { newBatch.processBatch(); @@ -185,7 +186,10 @@ export function batchGroups< options, ); - const batchedFunction = (group: TGroupKey, key: TKey): Promise => { + const batchedFunction = async ( + group: TGroupKey, + key: TKey, + ): Promise => { const groupKey = mapGroupKey(group); let batch = groupMap.get(groupKey); if (batch === undefined) { diff --git a/packages/dataloader/src/dedupeAsync.ts b/packages/dataloader/src/dedupeAsync.ts index acc95a00..5c01d20a 100644 --- a/packages/dataloader/src/dedupeAsync.ts +++ b/packages/dataloader/src/dedupeAsync.ts @@ -37,7 +37,7 @@ export default function dedupeAsync( ): DedupedAsyncFunction { const {cache, mapKey, shouldCache} = normalizeDedupeAsyncOptions(options); return Object.assign( - (key: TKey): Promise => { + async (key: TKey): Promise => { const cacheKey = mapKey(key); const cached = cache.get(cacheKey); if (cached !== undefined) return cached; diff --git a/packages/dataloader/src/dedupeSync.ts b/packages/dataloader/src/dedupeSync.ts index 6d96aca8..0ffd4cf7 100644 --- a/packages/dataloader/src/dedupeSync.ts +++ b/packages/dataloader/src/dedupeSync.ts @@ -59,7 +59,9 @@ interface NormalizedDedupeSyncOptions { } const identityFn = (arg: T): T => arg; const trueFn = (): true => true; -const noop = () => {}; +const noop = () => { + // noop +}; function normalizeDedupeSyncOptions( options?: DedupeSyncOptions, ): NormalizedDedupeSyncOptions { diff --git a/packages/dataloader/src/enqueuePostPromiseJob.ts b/packages/dataloader/src/enqueuePostPromiseJob.ts index 4c7936a2..6d6f9157 100644 --- a/packages/dataloader/src/enqueuePostPromiseJob.ts +++ b/packages/dataloader/src/enqueuePostPromiseJob.ts @@ -1,3 +1,5 @@ +/* tslint:disable */ + // This helper was adapted from Facebook's dataloader: // https://github.com/graphql/dataloader/blob/249b2b966a8807c50e07746ff04acb8c48fa4357/src/index.js#L206-L245