diff --git a/src/data/storeUtils.ts b/src/data/storeUtils.ts index 8e89dd58505..cfdb0bc0844 100644 --- a/src/data/storeUtils.ts +++ b/src/data/storeUtils.ts @@ -140,7 +140,7 @@ export interface JsonValue { export type ListValue = Array; -export type StoreValue = number | string | string[] | IdValue | ListValue | JsonValue | null | undefined | void; +export type StoreValue = number | string | string[] | IdValue | ListValue | JsonValue | null | undefined | void | Object; export function isIdValue(idObject: StoreValue): idObject is IdValue { return ( diff --git a/test/ApolloClient.ts b/test/ApolloClient.ts index 2b827ed8dea..922b5884241 100644 --- a/test/ApolloClient.ts +++ b/test/ApolloClient.ts @@ -22,9 +22,9 @@ describe('ApolloClient', () => { }, }); - assert.deepEqual(client.readQuery({ query: gql`{ a }` }), { a: 1 }); - assert.deepEqual(client.readQuery({ query: gql`{ b c }` }), { b: 2, c: 3 }); - assert.deepEqual(client.readQuery({ query: gql`{ a b c }` }), { a: 1, b: 2, c: 3 }); + assert.deepEqual<{}>(client.readQuery({ query: gql`{ a }` }), { a: 1 }); + assert.deepEqual<{}>(client.readQuery({ query: gql`{ b c }` }), { b: 2, c: 3 }); + assert.deepEqual<{}>(client.readQuery({ query: gql`{ a b c }` }), { a: 1, b: 2, c: 3 }); }); it('will read some deeply nested data from the store', () => { @@ -64,15 +64,15 @@ describe('ApolloClient', () => { }, }); - assert.deepEqual( + assert.deepEqual<{}>( client.readQuery({ query: gql`{ a d { e } }` }), { a: 1, d: { e: 4, __typename: 'Foo' } }, ); - assert.deepEqual( + assert.deepEqual<{}>( client.readQuery({ query: gql`{ a d { e h { i } } }` }), { a: 1, d: { __typename: 'Foo', e: 4, h: { i: 7, __typename: 'Bar' } } }, ); - assert.deepEqual( + assert.deepEqual<{}>( client.readQuery({ query: gql`{ a b c d { e f g h { i j k } } }` }), { a: 1, b: 2, c: 3, d: { __typename: 'Foo', e: 4, f: 5, g: 6, h: { __typename: 'Bar', i: 7, j: 8, k: 9 } } }, ); @@ -92,7 +92,7 @@ describe('ApolloClient', () => { }, }); - assert.deepEqual(client.readQuery({ + assert.deepEqual<{}>(client.readQuery({ query: gql`query ($literal: Boolean, $value: Int) { a: field(literal: true, value: 42) b: field(literal: $literal, value: $value) @@ -119,7 +119,7 @@ describe('ApolloClient', () => { }, }); - assert.deepEqual(client.readQuery({ + assert.deepEqual<{}>(client.readQuery({ query: gql`query ($literal: Boolean, $value: Int = -1) { a: field(literal: $literal, value: $value) }`, @@ -129,7 +129,7 @@ describe('ApolloClient', () => { }, }), { a: 2 }); - assert.deepEqual(client.readQuery({ + assert.deepEqual<{}>(client.readQuery({ query: gql`query ($literal: Boolean, $value: Int = -1) { a: field(literal: $literal, value: $value) }`, @@ -200,23 +200,23 @@ describe('ApolloClient', () => { }, }); - assert.deepEqual( + assert.deepEqual<{} | null>( client.readFragment({ id: 'foo', fragment: gql`fragment fragmentFoo on Foo { e h { i } }` }), { __typename: 'Foo', e: 4, h: { __typename: 'Bar', i: 7 } }, ); - assert.deepEqual( + assert.deepEqual<{} | null>( client.readFragment({ id: 'foo', fragment: gql`fragment fragmentFoo on Foo { e f g h { i j k } }` }), { __typename: 'Foo', e: 4, f: 5, g: 6, h: { __typename: 'Bar', i: 7, j: 8, k: 9 } }, ); - assert.deepEqual( + assert.deepEqual<{} | null>( client.readFragment({ id: 'bar', fragment: gql`fragment fragmentBar on Bar { i }` }), { __typename: 'Bar', i: 7 }, ); - assert.deepEqual( + assert.deepEqual<{} | null>( client.readFragment({ id: 'bar', fragment: gql`fragment fragmentBar on Bar { i j k }` }), { __typename: 'Bar', i: 7, j: 8, k: 9 }, ); - assert.deepEqual( + assert.deepEqual<{} | null>( client.readFragment({ id: 'foo', fragment: gql`fragment fragmentFoo on Foo { e f g h { i j k } } fragment fragmentBar on Bar { i j k }`, @@ -224,7 +224,7 @@ describe('ApolloClient', () => { }), { __typename: 'Foo', e: 4, f: 5, g: 6, h: { __typename: 'Bar', i: 7, j: 8, k: 9 } }, ); - assert.deepEqual( + assert.deepEqual<{} | null>( client.readFragment({ id: 'bar', fragment: gql`fragment fragmentFoo on Foo { e f g h { i j k } } fragment fragmentBar on Bar { i j k }`, @@ -249,7 +249,7 @@ describe('ApolloClient', () => { }, }); - assert.deepEqual(client.readFragment({ + assert.deepEqual<{} | null>(client.readFragment({ id: 'foo', fragment: gql` fragment foo on Foo { @@ -287,7 +287,7 @@ describe('ApolloClient', () => { assert.equal(client1.readFragment({ id: 'foo', fragment: gql`fragment fooFragment on Foo { a b c }` }), null); assert.equal(client2.readFragment({ id: 'foo', fragment: gql`fragment fooFragment on Foo { a b c }` }), null); - assert.deepEqual(client3.readFragment({ id: 'foo', fragment: gql`fragment fooFragment on Foo { a b c }` }), + assert.deepEqual<{} | null>(client3.readFragment({ id: 'foo', fragment: gql`fragment fooFragment on Foo { a b c }` }), { __typename: 'Foo', a: 1, b: 2, c: 3 }); }); }); @@ -762,7 +762,7 @@ describe('ApolloClient', () => { }, }); - assert.deepEqual( + assert.deepEqual<{} | null>( client.readFragment({ id: 'foo', fragment: gql`fragment x on Foo { a b c bar { d e f } }` }), { __typename: 'Foo', a: 1, b: 2, c: 3, bar: { d: 4, e: 5, f: 6, __typename: 'Bar' } }, ); @@ -773,7 +773,7 @@ describe('ApolloClient', () => { data: { __typename: 'Foo', a: 7 }, }); - assert.deepEqual( + assert.deepEqual<{} | null>( client.readFragment({ id: 'foo', fragment: gql`fragment x on Foo { a b c bar { d e f } }` }), { __typename: 'Foo', a: 7, b: 2, c: 3, bar: { __typename: 'Bar', d: 4, e: 5, f: 6 } }, ); @@ -784,7 +784,7 @@ describe('ApolloClient', () => { data: { __typename: 'Foo', bar: { __typename: 'Bar', d: 8 } }, }); - assert.deepEqual( + assert.deepEqual<{} | null>( client.readFragment({ id: 'foo', fragment: gql`fragment x on Foo { a b c bar { d e f } }` }), { __typename: 'Foo', a: 7, b: 2, c: 3, bar: { __typename: 'Bar', d: 8, e: 5, f: 6 } }, ); @@ -795,7 +795,7 @@ describe('ApolloClient', () => { data: { __typename: 'Bar', e: 9 }, }); - assert.deepEqual( + assert.deepEqual<{} | null>( client.readFragment({ id: 'foo', fragment: gql`fragment x on Foo { a b c bar { d e f } }` }), { __typename: 'Foo', a: 7, b: 2, c: 3, bar: { __typename: 'Bar', d: 8, e: 9, f: 6 } }, ); @@ -832,7 +832,7 @@ describe('ApolloClient', () => { data: { a: 1, b: 2, foo: { __typename: 'foo', c: 3, d: 4, bar: { key: 'foobar', __typename: 'bar', e: 5, f: 6 } } }, }); - assert.deepEqual( + assert.deepEqual<{} | null>( client.readQuery({ query: gql`{ a b foo { c d bar { key e f } } }` }), { a: 1, b: 2, foo: { __typename: 'foo', c: 3, d: 4, bar: { __typename: 'bar', key: 'foobar', e: 5, f: 6 } } }, ); diff --git a/test/ObservableQuery.ts b/test/ObservableQuery.ts index d62eff2a48b..60146757658 100644 --- a/test/ObservableQuery.ts +++ b/test/ObservableQuery.ts @@ -23,7 +23,11 @@ import mockWatchQuery from './mocks/mockWatchQuery'; import mockNetworkInterface, { ParsedRequest, } from './mocks/mockNetworkInterface'; -import { ObservableQuery } from '../src/core/ObservableQuery'; +import { + ObservableQuery, + ApolloCurrentResult, +} from '../src/core/ObservableQuery'; +import { ApolloQueryResult } from '../src/core/types'; import { NetworkInterface, } from '../src/transport/networkInterface'; @@ -834,7 +838,7 @@ describe('ObservableQuery', () => { }); subscribeAndCount(done, observable, () => { - assert.deepEqual(observable.currentResult(), { + assert.deepEqual>(observable.currentResult(), { data: dataOne, loading: false, networkStatus: 7, @@ -843,14 +847,14 @@ describe('ObservableQuery', () => { done(); }); - assert.deepEqual(observable.currentResult(), { + assert.deepEqual>(observable.currentResult(), { loading: true, data: {}, networkStatus: 1, partial: true, }); setTimeout(wrap(done, () => { - assert.deepEqual(observable.currentResult(), { + assert.deepEqual>(observable.currentResult(), { loading: true, data: {}, networkStatus: 1, @@ -877,7 +881,7 @@ describe('ObservableQuery', () => { query, variables, }); - assert.deepEqual(observable.currentResult(), { + assert.deepEqual>(observable.currentResult(), { data: dataOne, loading: false, networkStatus: 7, @@ -924,7 +928,7 @@ describe('ObservableQuery', () => { variables, fetchPolicy: 'network-only', }); - assert.deepEqual(observable.currentResult(), { + assert.deepEqual>(observable.currentResult(), { data: dataOne, loading: true, networkStatus: 1, @@ -936,7 +940,7 @@ describe('ObservableQuery', () => { assert.deepEqual(subResult, { data, loading, networkStatus, stale: false }); if (handleCount === 1) { - assert.deepEqual(subResult, { + assert.deepEqual>(subResult, { data: dataTwo, loading: false, networkStatus: 7, @@ -990,7 +994,7 @@ describe('ObservableQuery', () => { assert.deepEqual(result, { data, loading, networkStatus, stale: false }); if (count === 1) { - assert.deepEqual(result, { + assert.deepEqual>(result, { data: dataOne, loading: false, networkStatus: 7, diff --git a/test/assign.ts b/test/assign.ts index ec1330cd857..5022c22a78c 100644 --- a/test/assign.ts +++ b/test/assign.ts @@ -23,8 +23,8 @@ describe('assign', () => { assert.strictEqual(assign(source2, { b: 2 }, { c: 3 }), source2); assert.strictEqual(assign(source3, { b: 2 }, { c: 3 }, { d: 4 }), source3); - assert.deepEqual(source1, { a: 1, b: 2 }); - assert.deepEqual(source2, { a: 1, b: 2, c: 3 }); - assert.deepEqual(source3, { a: 1, b: 2, c: 3, d: 4 }); + assert.deepEqual<{}>(source1, { a: 1, b: 2 }); + assert.deepEqual<{}>(source2, { a: 1, b: 2, c: 3 }); + assert.deepEqual<{}>(source3, { a: 1, b: 2, c: 3, d: 4 }); }); }); diff --git a/test/client.ts b/test/client.ts index 6f3d805388b..f4755e5dd92 100644 --- a/test/client.ts +++ b/test/client.ts @@ -1802,7 +1802,7 @@ describe('client', () => { // then query for real .then(() => client.query({ query, fetchPolicy: 'network-only' })) .then((result) => { - assert.deepEqual(result.data, { myNumber: { n: 2 } }); + assert.deepEqual<{}>(result.data, { myNumber: { n: 2 } }); }); }); @@ -1820,10 +1820,10 @@ describe('client', () => { // then query for real .then(() => client.query(options)) .then((result) => { - assert.deepEqual(result.data, { myNumber: { n: 1 } }); + assert.deepEqual<{}>(result.data, { myNumber: { n: 1 } }); // Test that options weren't mutated, issue #339 - assert.deepEqual(options, { query, fetchPolicy: 'network-only' }); + assert.deepEqual(options, { query, fetchPolicy: 'network-only' }); }); }); @@ -1845,14 +1845,14 @@ describe('client', () => { return promise; }) .then((result) => { - assert.deepEqual(result.data, { myNumber: { n: 1 } }); + assert.deepEqual<{}>(result.data, { myNumber: { n: 1 } }); clock.tick(100); const promise = client.query({ query, fetchPolicy: 'network-only' }); clock.tick(0); return promise; }) .then((result) => { - assert.deepEqual(result.data, { myNumber: { n: 2 } }); + assert.deepEqual<{}>(result.data, { myNumber: { n: 2 } }); }); clock.tick(0); return outerPromise; @@ -2051,7 +2051,7 @@ describe('client', () => { networkInterface.query({ query: firstQuery }), networkInterface.query({ query: secondQuery }), ]).then((results) => { - assert.deepEqual(results, [firstResult, secondResult]); + assert.deepEqual<[ExecutionResult]>(results, [firstResult, secondResult]); fetch = oldFetch; done(); }).catch( e => { @@ -2193,7 +2193,7 @@ describe('client', () => { new Promise( (resolve, reject) => setTimeout(() => resolve(networkInterface.query({ query: secondQuery })), 10)), ]).then((results) => { - assert.deepEqual(results, [firstResult, secondResult]); + assert.deepEqual<[ExecutionResult]>(results, [firstResult, secondResult]); fetch = oldFetch; done(); }).catch( e => { diff --git a/test/customResolvers.ts b/test/customResolvers.ts index 8360f280c74..a40024369aa 100644 --- a/test/customResolvers.ts +++ b/test/customResolvers.ts @@ -5,6 +5,10 @@ import ApolloClient, { toIdValue } from '../src'; import { NetworkStatus } from '../src/queries/networkStatus'; +import { + ApolloQueryResult, +} from '../src/core/types'; + describe('custom resolvers', () => { it(`works for cache redirection`, () => { const dataIdFromObject = (obj: any) => { @@ -46,7 +50,7 @@ describe('custom resolvers', () => { return client.query({ query: listQuery }).then(() => { return client.query({ query: itemQuery }); }).then((itemResult) => { - assert.deepEqual(itemResult, { + assert.deepEqual>(itemResult, { loading: false, networkStatus: NetworkStatus.ready, stale: false, diff --git a/test/mutationResults.ts b/test/mutationResults.ts index 0a76ec5bdea..01c89c214a0 100644 --- a/test/mutationResults.ts +++ b/test/mutationResults.ts @@ -1291,13 +1291,13 @@ describe('mutation results', () => { query ({ variables }) { switch (count++) { case 0: - assert.deepEqual(variables, { a: 1, b: 2 }); + assert.deepEqual(variables, { a: 1, b: 2 }); return Promise.resolve({ data: { result: 'hello' } }); case 1: - assert.deepEqual(variables, { a: 1, c: 3 }); + assert.deepEqual(variables, { a: 1, c: 3 }); return Promise.resolve({ data: { result: 'world' } }); case 2: - assert.deepEqual(variables, { a: undefined, b: 2, c: 3 }); + assert.deepEqual(variables, { a: undefined, b: 2, c: 3 }); return Promise.resolve({ data: { result: 'goodbye' } }); case 3: assert.deepEqual(variables, {}); @@ -1353,13 +1353,13 @@ describe('mutation results', () => { query ({ variables }) { switch (count++) { case 0: - assert.deepEqual(variables, { a: 1, b: 'water' }); + assert.deepEqual(variables, { a: 1, b: 'water' }); return Promise.resolve({ data: { result: 'hello' } }); case 1: - assert.deepEqual(variables, { a: 2, b: 'cheese', c: 3 }); + assert.deepEqual(variables, { a: 2, b: 'cheese', c: 3 }); return Promise.resolve({ data: { result: 'world' } }); case 2: - assert.deepEqual(variables, { a: 1, b: 'cheese', c: 3 }); + assert.deepEqual(variables, { a: 1, b: 'cheese', c: 3 }); return Promise.resolve({ data: { result: 'goodbye' } }); default: return Promise.reject(new Error('Too many network calls.')); @@ -1408,13 +1408,13 @@ describe('mutation results', () => { query ({ variables }) { switch (count++) { case 0: - assert.deepEqual(variables, { a: 1, b: 2, c: null }); + assert.deepEqual(variables, { a: 1, b: 2, c: null }); return Promise.resolve({ data: { result: 'hello' } }); case 1: - assert.deepEqual(variables, { a: 1, b: null, c: 3 }); + assert.deepEqual(variables, { a: 1, b: null, c: 3 }); return Promise.resolve({ data: { result: 'world' } }); case 2: - assert.deepEqual(variables, { a: null, b: null, c: null }); + assert.deepEqual(variables, { a: null, b: null, c: null }); return Promise.resolve({ data: { result: 'moon' } }); default: return Promise.reject(new Error('Too many network calls.')); diff --git a/test/proxy.ts b/test/proxy.ts index 9ef787ed2c9..b2dcb865756 100644 --- a/test/proxy.ts +++ b/test/proxy.ts @@ -7,6 +7,7 @@ import { ReduxDataProxy, TransactionDataProxy } from '../src/data/proxy'; import { toIdValue } from '../src/data/storeUtils'; import { HeuristicFragmentMatcher } from '../src/data/fragmentMatcher'; import { addTypenameToDocument } from '../src/queries/queryTransform'; +import { DataWrite } from '../src/actions'; describe('ReduxDataProxy', () => { function createDataProxy({ @@ -40,9 +41,9 @@ describe('ReduxDataProxy', () => { }, }); - assert.deepEqual(proxy.readQuery({ query: gql`{ a }` }), { a: 1 }); - assert.deepEqual(proxy.readQuery({ query: gql`{ b c }` }), { b: 2, c: 3 }); - assert.deepEqual(proxy.readQuery({ query: gql`{ a b c }` }), { a: 1, b: 2, c: 3 }); + assert.deepEqual<{}>(proxy.readQuery({ query: gql`{ a }` }), { a: 1 }); + assert.deepEqual<{}>(proxy.readQuery({ query: gql`{ b c }` }), { b: 2, c: 3 }); + assert.deepEqual<{}>(proxy.readQuery({ query: gql`{ a b c }` }), { a: 1, b: 2, c: 3 }); }); it('will read some deeply nested data from the store', () => { @@ -80,15 +81,15 @@ describe('ReduxDataProxy', () => { }, }); - assert.deepEqual( + assert.deepEqual<{}>( proxy.readQuery({ query: gql`{ a d { e } }` }), { a: 1, d: { e: 4 } }, ); - assert.deepEqual( + assert.deepEqual<{}>( proxy.readQuery({ query: gql`{ a d { e h { i } } }` }), { a: 1, d: { e: 4, h: { i: 7 } } }, ); - assert.deepEqual( + assert.deepEqual<{}>( proxy.readQuery({ query: gql`{ a b c d { e f g h { i j k } } }` }), { a: 1, b: 2, c: 3, d: { e: 4, f: 5, g: 6, h: { i: 7, j: 8, k: 9 } } }, ); @@ -131,7 +132,7 @@ describe('ReduxDataProxy', () => { `, }); - assert.deepEqual(queryResult, { + assert.deepEqual<{}>(queryResult, { thing: { a: 1, b: '2', c: null }, }); }); @@ -150,7 +151,7 @@ describe('ReduxDataProxy', () => { }, }); - assert.deepEqual(proxy.readQuery({ + assert.deepEqual<{}>(proxy.readQuery({ query: gql`query ($literal: Boolean, $value: Int) { a: field(literal: true, value: 42) b: field(literal: $literal, value: $value) @@ -224,23 +225,23 @@ describe('ReduxDataProxy', () => { }, }); - assert.deepEqual( + assert.deepEqual<{} | null>( proxy.readFragment({ id: 'foo', fragment: gql`fragment fragmentFoo on Foo { e h { i } }` }), { e: 4, h: { i: 7 } }, ); - assert.deepEqual( + assert.deepEqual<{} | null>( proxy.readFragment({ id: 'foo', fragment: gql`fragment fragmentFoo on Foo { e f g h { i j k } }` }), { e: 4, f: 5, g: 6, h: { i: 7, j: 8, k: 9 } }, ); - assert.deepEqual( + assert.deepEqual<{} | null>( proxy.readFragment({ id: 'bar', fragment: gql`fragment fragmentBar on Bar { i }` }), { i: 7 }, ); - assert.deepEqual( + assert.deepEqual<{} | null>( proxy.readFragment({ id: 'bar', fragment: gql`fragment fragmentBar on Bar { i j k }` }), { i: 7, j: 8, k: 9 }, ); - assert.deepEqual( + assert.deepEqual<{} | null>( proxy.readFragment({ id: 'foo', fragment: gql`fragment fragmentFoo on Foo { e f g h { i j k } } fragment fragmentBar on Bar { i j k }`, @@ -248,7 +249,7 @@ describe('ReduxDataProxy', () => { }), { e: 4, f: 5, g: 6, h: { i: 7, j: 8, k: 9 } }, ); - assert.deepEqual( + assert.deepEqual<{} | null>( proxy.readFragment({ id: 'bar', fragment: gql`fragment fragmentFoo on Foo { e f g h { i j k } } fragment fragmentBar on Bar { i j k }`, @@ -273,7 +274,7 @@ describe('ReduxDataProxy', () => { }, }); - assert.deepEqual(proxy.readFragment({ + assert.deepEqual<{} | null>(proxy.readFragment({ id: 'foo', fragment: gql` fragment foo on Foo { @@ -311,7 +312,9 @@ describe('ReduxDataProxy', () => { assert.equal(client1.readFragment({ id: 'foo', fragment: gql`fragment fooFragment on Foo { a b c }` }), null); assert.equal(client2.readFragment({ id: 'foo', fragment: gql`fragment fooFragment on Foo { a b c }` }), null); - assert.deepEqual(client3.readFragment({ id: 'foo', fragment: gql`fragment fooFragment on Foo { a b c }` }), { a: 1, b: 2, c: 3 }); + assert.deepEqual<{} | null>( + client3.readFragment({ id: 'foo', fragment: gql`fragment fooFragment on Foo { a b c }` }), + { a: 1, b: 2, c: 3 }); }); it('will read data using custom resolvers', () => { @@ -353,7 +356,7 @@ describe('ReduxDataProxy', () => { }`, }); - assert.deepEqual(queryResult, { + assert.deepEqual<{} | null>(queryResult, { thing: { a: 1, b: '2', c: null }, }); }); @@ -725,9 +728,9 @@ describe('TransactionDataProxy', () => { }, }, {}); - assert.deepEqual(proxy.readQuery({ query: gql`{ a }` }), { a: 1 }); - assert.deepEqual(proxy.readQuery({ query: gql`{ b c }` }), { b: 2, c: 3 }); - assert.deepEqual(proxy.readQuery({ query: gql`{ a b c }` }), { a: 1, b: 2, c: 3 }); + assert.deepEqual<{} | null>(proxy.readQuery({ query: gql`{ a }` }), { a: 1 }); + assert.deepEqual<{} | null>(proxy.readQuery({ query: gql`{ b c }` }), { b: 2, c: 3 }); + assert.deepEqual<{} | null>(proxy.readQuery({ query: gql`{ a b c }` }), { a: 1, b: 2, c: 3 }); }); it('will read some deeply nested data from the store', () => { @@ -761,15 +764,15 @@ describe('TransactionDataProxy', () => { }, }, { addTypename: true }); - assert.deepEqual( + assert.deepEqual<{}>( proxy.readQuery({ query: gql`{ a d { e } }` }), { a: 1, d: { __typename: 'Foo', e: 4 } }, ); - assert.deepEqual( + assert.deepEqual<{}>( proxy.readQuery({ query: gql`{ a d { e h { i } } }` }), { a: 1, d: { __typename: 'Foo', e: 4, h: { __typename: 'Bar', i: 7 } } }, ); - assert.deepEqual( + assert.deepEqual<{}>( proxy.readQuery({ query: gql`{ a b c d { e f g h { i j k } } }` }), { a: 1, b: 2, c: 3, d: { __typename: 'Foo', e: 4, f: 5, g: 6, h: { __typename: 'Bar', i: 7, j: 8, k: 9 } } }, ); @@ -783,7 +786,7 @@ describe('TransactionDataProxy', () => { }, }, { addTypename: true }); - assert.deepEqual(proxy.readQuery({ + assert.deepEqual<{}>(proxy.readQuery({ query: gql`query ($literal: Boolean, $value: Int) { a: field(literal: true, value: 42) b: field(literal: $literal, value: $value) @@ -827,7 +830,7 @@ describe('TransactionDataProxy', () => { `, }); - assert.deepEqual(queryResult, { + assert.deepEqual<{}>(queryResult, { thing: {__typename: 'Foo', a: 1, b: '2', c: null }, }); }); @@ -896,23 +899,23 @@ describe('TransactionDataProxy', () => { }, }, { addTypename: true }); - assert.deepEqual( + assert.deepEqual<{} | null>( proxy.readFragment({ id: 'foo', fragment: gql`fragment fragmentFoo on Foo { e h { i } }` }), { __typename: 'Foo', e: 4, h: { __typename: 'Bar', i: 7 } }, ); - assert.deepEqual( + assert.deepEqual<{} | null>( proxy.readFragment({ id: 'foo', fragment: gql`fragment fragmentFoo on Foo { e f g h { i j k } }` }), { __typename: 'Foo', e: 4, f: 5, g: 6, h: { __typename: 'Bar', i: 7, j: 8, k: 9 } }, ); - assert.deepEqual( + assert.deepEqual<{} | null>( proxy.readFragment({ id: 'bar', fragment: gql`fragment fragmentBar on Bar { i }` }), { __typename: 'Bar', i: 7 }, ); - assert.deepEqual( + assert.deepEqual<{} | null>( proxy.readFragment({ id: 'bar', fragment: gql`fragment fragmentBar on Bar { i j k }` }), { __typename: 'Bar', i: 7, j: 8, k: 9 }, ); - assert.deepEqual( + assert.deepEqual<{} | null>( proxy.readFragment({ id: 'foo', fragment: gql`fragment fragmentFoo on Foo { e f g h { i j k } } fragment fragmentBar on Bar { i j k }`, @@ -920,7 +923,7 @@ describe('TransactionDataProxy', () => { }), { __typename: 'Foo', e: 4, f: 5, g: 6, h: { __typename: 'Bar', i: 7, j: 8, k: 9 } }, ); - assert.deepEqual( + assert.deepEqual<{} | null>( proxy.readFragment({ id: 'bar', fragment: gql`fragment fragmentFoo on Foo { e f g h { i j k } } fragment fragmentBar on Bar { i j k }`, @@ -939,7 +942,7 @@ describe('TransactionDataProxy', () => { }, }, { addTypename: true }); - assert.deepEqual(proxy.readFragment({ + assert.deepEqual<{} | null>(proxy.readFragment({ id: 'foo', fragment: gql` fragment foo on Foo { @@ -965,7 +968,9 @@ describe('TransactionDataProxy', () => { assert.equal(client1.readFragment({ id: 'foo', fragment: gql`fragment fooFragment on Foo { a b c }` }), null); assert.equal(client2.readFragment({ id: 'foo', fragment: gql`fragment fooFragment on Foo { a b c }` }), null); - assert.deepEqual(client3.readFragment({ id: 'foo', fragment: gql`fragment fooFragment on Foo { a b c }` }), { a: 1, b: 2, c: 3 }); + assert.deepEqual<{} | null>( + client3.readFragment({ id: 'foo', fragment: gql`fragment fooFragment on Foo { a b c }` }), + { a: 1, b: 2, c: 3 }); }); it('will read data using custom resolvers', () => { @@ -1001,7 +1006,7 @@ describe('TransactionDataProxy', () => { }`, }); - assert.deepEqual(queryResult, { + assert.deepEqual<{} | null>(queryResult, { __typename: 'Query', thing: { __typename: 'Thing', a: 1, b: '2', c: null }, }); @@ -1034,7 +1039,7 @@ describe('TransactionDataProxy', () => { const writes = proxy.finish(); - assert.deepEqual(writes, [ + assert.deepEqual(writes, [ { rootId: 'ROOT_QUERY', result: { a: 1, b: 2, c: 3 }, @@ -1095,7 +1100,7 @@ describe('TransactionDataProxy', () => { assert.deepEqual(Object.keys(writes[1]), ['rootId', 'result', 'document', 'variables']); assert.equal(writes[1].rootId, 'bar'); assert.deepEqual(writes[1].result, { foo: { d: 4, e: 5, bar: { f: 6, g: 7 } } }); - assert.deepEqual(writes[1].variables, { id: 7 }); + assert.deepEqual(writes[1].variables, { id: 7 }); assert.equal(print(writes[1].document), print(gql` { ...fragment2 } fragment fragment1 on Foo { a b c } @@ -1128,7 +1133,7 @@ describe('TransactionDataProxy', () => { const proxy = new TransactionDataProxy(data, { addTypename: true }); - assert.deepEqual( + assert.deepEqual<{} | null>( proxy.readFragment({ id: 'foo', fragment: gql`fragment x on Foo { a b c bar { d e f } }` }), { __typename: 'Foo', a: 1, b: 2, c: 3, bar: { __typename: 'Bar', d: 4, e: 5, f: 6 } }, ); @@ -1139,7 +1144,7 @@ describe('TransactionDataProxy', () => { data: { a: 7 }, }); - assert.deepEqual( + assert.deepEqual<{} | null>( proxy.readFragment({ id: 'foo', fragment: gql`fragment x on Foo { a b c bar { d e f } }` }), { __typename: 'Foo', a: 7, b: 2, c: 3, bar: { __typename: 'Bar', d: 4, e: 5, f: 6 } }, ); @@ -1150,7 +1155,7 @@ describe('TransactionDataProxy', () => { data: { __typename: 'Foo', bar: { __typename: 'Bar', d: 8 } }, }); - assert.deepEqual( + assert.deepEqual<{} | null>( proxy.readFragment({ id: 'foo', fragment: gql`fragment x on Foo { a b c bar { d e f } }` }), { __typename: 'Foo', a: 7, b: 2, c: 3, bar: { __typename: 'Bar', d: 8, e: 5, f: 6 } }, ); @@ -1161,7 +1166,7 @@ describe('TransactionDataProxy', () => { data: { __typename: 'Bar', e: 9 }, }); - assert.deepEqual( + assert.deepEqual<{} | null>( proxy.readFragment({ id: 'foo', fragment: gql`fragment x on Foo { a b c bar { d e f } }` }), { __typename: 'Foo', a: 7, b: 2, c: 3, bar: { __typename: 'Bar', d: 8, e: 9, f: 6 } }, ); @@ -1216,7 +1221,7 @@ describe('TransactionDataProxy', () => { data: { a: 1, b: 2, foo: { __typename: 'Foo', c: 3, d: 4, bar: { __typename: 'Bar', id: 'foobar', e: 5, f: 6 } } }, }); - assert.deepEqual( + assert.deepEqual<{} | null>( proxy.readQuery({ query: gql`{ a b foo { c d bar { id e f } } }` }), { a: 1, b: 2, foo: { __typename: 'Foo', c: 3, d: 4, bar: { __typename: 'Bar', id: 'foobar', e: 5, f: 6 } } }, ); diff --git a/test/readFromStore.ts b/test/readFromStore.ts index 9f98417cc39..ab392d798ce 100644 --- a/test/readFromStore.ts +++ b/test/readFromStore.ts @@ -70,7 +70,7 @@ describe('reading from the store', () => { }); // The result of the query shouldn't contain __data_id fields - assert.deepEqual(queryResult, { + assert.deepEqual<{}>(queryResult, { stringField: result['stringField'], numberField: result['numberField'], }); @@ -107,7 +107,7 @@ describe('reading from the store', () => { variables, }); - assert.deepEqual(result, { + assert.deepEqual<{}>(result, { id: 'abcd', nullField: null, numberField: 5, @@ -148,7 +148,7 @@ describe('reading from the store', () => { variables, }); - assert.deepEqual(result, { + assert.deepEqual<{}>(result, { id: 'abcd', nullField: null, numberField: 5, @@ -196,7 +196,7 @@ describe('reading from the store', () => { }); // The result of the query shouldn't contain __data_id fields - assert.deepEqual(queryResult, { + assert.deepEqual<{}>(queryResult, { stringField: 'This is a string!', numberField: 5, nestedObj: { @@ -281,7 +281,7 @@ describe('reading from the store', () => { }); // The result of the query shouldn't contain __data_id fields - assert.deepEqual(queryResult, { + assert.deepEqual<{}>(queryResult, { stringField: 'This is a string!', numberField: 5, nullField: null, @@ -340,7 +340,7 @@ describe('reading from the store', () => { fragmentMatcherFunction, }); - assert.deepEqual(queryResult, { + assert.deepEqual<{}>(queryResult, { nestedObj: { innerArray: [{id: 'abcdef', someField: 3}], }, @@ -394,7 +394,7 @@ describe('reading from the store', () => { }); // The result of the query shouldn't contain __data_id fields - assert.deepEqual(queryResult, { + assert.deepEqual<{}>(queryResult, { stringField: 'This is a string!', numberField: 5, nestedArray: [ @@ -451,7 +451,7 @@ describe('reading from the store', () => { }); // The result of the query shouldn't contain __data_id fields - assert.deepEqual(queryResult, { + assert.deepEqual<{}>(queryResult, { stringField: 'This is a string!', numberField: 5, nestedArray: [ @@ -507,7 +507,7 @@ describe('reading from the store', () => { }); // The result of the query shouldn't contain __data_id fields - assert.deepEqual(queryResult, { + assert.deepEqual<{}>(queryResult, { stringField: 'This is a string!', numberField: 5, nestedArray: [ @@ -572,7 +572,7 @@ describe('reading from the store', () => { }); // The result of the query shouldn't contain __data_id fields - assert.deepEqual(queryResult, { + assert.deepEqual<{}>(queryResult, { stringField: 'This is a string!', numberField: 5, nestedObj: null, @@ -607,7 +607,7 @@ describe('reading from the store', () => { }); // The result of the query shouldn't contain __data_id fields - assert.deepEqual(queryResult, { + assert.deepEqual<{}>(queryResult, { stringField: 'This is a string!', numberField: 5, simpleArray: ['one', 'two', 'three'], @@ -642,7 +642,7 @@ describe('reading from the store', () => { }); // The result of the query shouldn't contain __data_id fields - assert.deepEqual(queryResult, { + assert.deepEqual<{}>(queryResult, { stringField: 'This is a string!', numberField: 5, simpleArray: [null, 'two', 'three'], @@ -681,7 +681,7 @@ describe('reading from the store', () => { }); // The result of the query shouldn't contain __data_id fields - assert.deepEqual(queryResult, { + assert.deepEqual<{}>(queryResult, { stringField: result['stringField'], numberField: result['numberField'], computedField: 'This is a string!5bit', @@ -719,7 +719,7 @@ describe('reading from the store', () => { }); // The result of the query shouldn't contain __data_id fields - assert.deepEqual(queryResult, { + assert.deepEqual<{}>(queryResult, { stringField: result['stringField'], numberField: result['numberField'], computedField: 'This is a string!5bit', @@ -783,7 +783,7 @@ describe('reading from the store', () => { `, }); - assert.deepEqual(queryResult1, { + assert.deepEqual<{}>(queryResult1, { stringField: 'This is a string too!', numberField: 6, nullField: null, @@ -806,7 +806,7 @@ describe('reading from the store', () => { `, }); - assert.deepEqual(queryResult2, { + assert.deepEqual<{}>(queryResult2, { stringField: 'This is a deep string', numberField: 7, nullField: null, diff --git a/test/scheduler.ts b/test/scheduler.ts index 2b4ba4476db..5e6bbfd3c9b 100644 --- a/test/scheduler.ts +++ b/test/scheduler.ts @@ -354,11 +354,11 @@ describe('QueryScheduler', () => { }, }; const interval = 20000; - const queryOptions1 = { + const queryOptions1: WatchQueryOptions = { query: query1, pollInterval: interval, }; - const queryOptions2 = { + const queryOptions2: WatchQueryOptions = { query: query2, pollInterval: interval, }; @@ -396,7 +396,7 @@ describe('QueryScheduler', () => { const keys = Object.keys(scheduler.intervalQueries); assert.equal(keys.length, 1); - assert.equal(keys[0], interval); + assert.equal(keys[0], String(interval)); const queryIds = (scheduler.intervalQueries)[keys[0]]; assert.equal(queryIds.length, 2); diff --git a/test/writeToStore.ts b/test/writeToStore.ts index 8d501ca28c8..ee8a2059176 100644 --- a/test/writeToStore.ts +++ b/test/writeToStore.ts @@ -25,6 +25,7 @@ import { import { NormalizedCache, + StoreObject, } from '../src/data/storeUtils'; import { @@ -57,7 +58,7 @@ describe('writing to the store', () => { nullField: null, }; - assert.deepEqual(writeQueryToStore({ + assert.deepEqual(writeQueryToStore({ query, result: cloneDeep(result), }), { @@ -238,12 +239,12 @@ describe('writing to the store', () => { }, }; - assert.deepEqual(writeQueryToStore({ + assert.deepEqual(writeQueryToStore({ query, result: cloneDeep(result), dataIdFromObject: getIdField, }), { - 'ROOT_QUERY': assign({}, assign({}, omit(result, 'nestedObj')), { + 'ROOT_QUERY': assign<{}>({}, assign({}, omit(result, 'nestedObj')), { nestedObj: { type: 'id', id: result.nestedObj.id, @@ -281,7 +282,7 @@ describe('writing to the store', () => { }, }; - assert.deepEqual(writeQueryToStore({ + assert.deepEqual(writeQueryToStore({ query, result: cloneDeep(result), }), { @@ -323,7 +324,7 @@ describe('writing to the store', () => { }, }; - assert.deepEqual(writeQueryToStore({ + assert.deepEqual(writeQueryToStore({ query, result: cloneDeep(result), }), { @@ -375,7 +376,7 @@ describe('writing to the store', () => { ], }; - assert.deepEqual(writeQueryToStore({ + assert.deepEqual(writeQueryToStore({ query, result: cloneDeep(result), dataIdFromObject: getIdField, @@ -424,12 +425,12 @@ describe('writing to the store', () => { ], }; - assert.deepEqual(writeQueryToStore({ + assert.deepEqual(writeQueryToStore({ query, result: cloneDeep(result), dataIdFromObject: getIdField, }), { - 'ROOT_QUERY': assign({}, assign({}, omit(result, 'nestedArray')), { + 'ROOT_QUERY': assign<{}>({}, assign({}, omit(result, 'nestedArray')), { nestedArray: [ { type: 'id', id: result.nestedArray[0].id, generated: false }, null, @@ -478,7 +479,7 @@ describe('writing to the store', () => { result: cloneDeep(result), }); - assert.deepEqual(normalized, { + assert.deepEqual(normalized, { 'ROOT_QUERY': assign({}, assign({}, omit(result, 'nestedArray')), { nestedArray: [ { type: 'id', generated: true, id: `ROOT_QUERY.nestedArray.0` }, @@ -525,7 +526,7 @@ describe('writing to the store', () => { result: cloneDeep(result), }); - assert.deepEqual(normalized, { + assert.deepEqual(normalized, { 'ROOT_QUERY': assign({}, assign({}, omit(result, 'nestedArray')), { nestedArray: [ null, @@ -561,8 +562,8 @@ describe('writing to the store', () => { dataIdFromObject: getIdField, }); - assert.deepEqual(normalized, { - 'ROOT_QUERY': assign({}, assign({}, omit(result, 'simpleArray')), { + assert.deepEqual(normalized, { + 'ROOT_QUERY': assign<{}>({}, assign({}, omit(result, 'simpleArray')), { simpleArray: { type: 'json', 'json': [ @@ -599,8 +600,8 @@ describe('writing to the store', () => { result: cloneDeep(result), }); - assert.deepEqual(normalized, { - 'ROOT_QUERY': assign({}, assign({}, omit(result, 'simpleArray')), { + assert.deepEqual(normalized, { + 'ROOT_QUERY': assign<{}>({}, assign({}, omit(result, 'simpleArray')), { simpleArray: { type: 'json', json: [ @@ -655,7 +656,7 @@ describe('writing to the store', () => { dataIdFromObject: getIdField, }); - assert.deepEqual(store2, { + assert.deepEqual(store2, { 'ROOT_QUERY': assign({}, result, result2), }); }); @@ -684,7 +685,7 @@ describe('writing to the store', () => { nestedObj: null, }; - assert.deepEqual(writeQueryToStore({ + assert.deepEqual(writeQueryToStore({ query, result: cloneDeep(result), }), { @@ -711,7 +712,7 @@ describe('writing to the store', () => { }, }; - assert.deepEqual(writeQueryToStore({ + assert.deepEqual(writeQueryToStore({ query, result: cloneDeep(result), }), { @@ -837,7 +838,7 @@ describe('writing to the store', () => { mutation.definitions.map((def: OperationDefinitionNode) => { if (isOperationDefinition(def)) { - assert.deepEqual(writeSelectionSetToStore({ + assert.deepEqual(writeSelectionSetToStore({ dataId: '5', selectionSet: def.selectionSet, result: cloneDeep(result), @@ -899,7 +900,7 @@ describe('writing to the store', () => { }, '$ROOT_QUERY.author': data.author, }; - assert.deepEqual(writeQueryToStore({ + assert.deepEqual(writeQueryToStore({ result: data, query, }), expStore); @@ -935,7 +936,7 @@ describe('writing to the store', () => { __typename: data.author.__typename, }, }; - assert.deepEqual(writeQueryToStore({ + assert.deepEqual(writeQueryToStore({ result: data, query, dataIdFromObject, @@ -977,7 +978,7 @@ describe('writing to the store', () => { }, }, }; - assert.deepEqual(writeQueryToStore({ + assert.deepEqual(writeQueryToStore({ result: data, query, dataIdFromObject, @@ -1054,14 +1055,14 @@ describe('writing to the store', () => { query: queryWithoutId, dataIdFromObject, }); - assert.deepEqual(storeWithoutId, expStoreWithoutId); + assert.deepEqual(storeWithoutId, expStoreWithoutId); const storeWithId = writeQueryToStore({ result: dataWithId, query: queryWithId, store: storeWithoutId, dataIdFromObject, }); - assert.deepEqual(storeWithId, expStoreWithId); + assert.deepEqual(storeWithId, expStoreWithId); }); it('does not swallow errors other than field errors', () => { @@ -1141,7 +1142,7 @@ describe('writing to the store', () => { dataIdFromObject: getIdField, }); - assert.deepEqual(newStore['1'], result.todos[0]); + assert.deepEqual(newStore['1'], result.todos[0]); }); it('should warn when it receives the wrong data with non-union fragments (using an heuristic matcher)', () => { @@ -1165,7 +1166,7 @@ describe('writing to the store', () => { fragmentMatcherFunction, }); - assert.deepEqual(newStore['1'], result.todos[0]); + assert.deepEqual(newStore['1'], result.todos[0]); }, /Missing field description/); });