diff --git a/src/ApolloClient.ts b/src/ApolloClient.ts index ea3c0571490..466ac3aa0a8 100644 --- a/src/ApolloClient.ts +++ b/src/ApolloClient.ts @@ -434,13 +434,7 @@ export default class ApolloClient implements DataProxy { this.setStore(store); return (next: any) => (action: any) => { - const previousApolloState = this.queryManager.selectApolloState(store); const returnValue = next(action); - const newApolloState = this.queryManager.selectApolloState(store); - - if (newApolloState !== previousApolloState) { - this.queryManager.broadcastNewStore(store.getState()); - } if (this.devToolsHookCb) { this.devToolsHookCb({ diff --git a/src/actions.ts b/src/actions.ts index 2a0c72c1d2e..9c06fe1e4d0 100644 --- a/src/actions.ts +++ b/src/actions.ts @@ -39,60 +39,6 @@ export function isQueryResultAction(action: ApolloAction): action is QueryResult return action.type === 'APOLLO_QUERY_RESULT'; } -export interface QueryErrorAction { - type: 'APOLLO_QUERY_ERROR'; - error: Error; - queryId: string; - requestId: number; - fetchMoreForQueryId?: string; -} - -export function isQueryErrorAction(action: ApolloAction): action is QueryErrorAction { - return action.type === 'APOLLO_QUERY_ERROR'; -} - -export interface QueryInitAction { - type: 'APOLLO_QUERY_INIT'; - queryString: string; - document: DocumentNode; - operationName: string | null; - variables: Object; - fetchPolicy: FetchPolicy; - queryId: string; - requestId: number; - storePreviousVariables: boolean; - isRefetch: boolean; - isPoll: boolean; - fetchMoreForQueryId?: string; - metadata: any; -} - -export function isQueryInitAction(action: ApolloAction): action is QueryInitAction { - return action.type === 'APOLLO_QUERY_INIT'; -} - -export interface QueryResultClientAction { - type: 'APOLLO_QUERY_RESULT_CLIENT'; - result: ExecutionResult; - operationName: string | null; - complete: boolean; - queryId: string; - requestId: number; -} - -export function isQueryResultClientAction(action: ApolloAction): action is QueryResultClientAction { - return action.type === 'APOLLO_QUERY_RESULT_CLIENT'; -} - -export interface QueryStopAction { - type: 'APOLLO_QUERY_STOP'; - queryId: string; -} - -export function isQueryStopAction(action: ApolloAction): action is QueryStopAction { - return action.type === 'APOLLO_QUERY_STOP'; -} - // contains both the original value of a query and a reducer to transform // the query during an update export type QueryWithUpdater = { @@ -198,10 +144,6 @@ export function isWriteAction(action: ApolloAction): action is WriteAction { export type ApolloAction = QueryResultAction | - QueryErrorAction | - QueryInitAction | - QueryResultClientAction | - QueryStopAction | MutationInitAction | MutationResultAction | MutationErrorAction | diff --git a/src/core/QueryManager.ts b/src/core/QueryManager.ts index 026364cb88e..48b9e79b11c 100644 --- a/src/core/QueryManager.ts +++ b/src/core/QueryManager.ts @@ -252,11 +252,6 @@ export class QueryManager { } } - // Called from middleware - public broadcastNewStore(store: any) { - this.broadcastQueries(); - } - public mutate({ mutation, variables, @@ -463,24 +458,6 @@ export class QueryManager { this.broadcastQueries(); - this.store.dispatch({ - type: 'APOLLO_QUERY_INIT', - queryString, - document: queryDoc, - operationName: getOperationName(queryDoc), - variables, - fetchPolicy, - queryId, - requestId, - // we store the old variables in order to trigger "loading new variables" - // state if we know we will go to the server - storePreviousVariables: shouldFetch, - isPoll: fetchType === FetchType.poll, - isRefetch: fetchType === FetchType.refetch, - fetchMoreForQueryId, - metadata, - }); - this.lastRequestId[queryId] = requestId; // If there is no part of the query we need to fetch from the server (or, @@ -489,17 +466,6 @@ export class QueryManager { if (shouldDispatchClientResult) { this.queryStore.markQueryResultClient(queryId, !shouldFetch); this.broadcastQueries(); - - this.store.dispatch({ - type: 'APOLLO_QUERY_RESULT_CLIENT', - result: { data: storeResult }, - variables, - document: queryDoc, - operationName: getOperationName(queryDoc), - complete: !shouldFetch, - queryId, - requestId, - }); } if (shouldFetch) { @@ -516,14 +482,6 @@ export class QueryManager { throw error; } else { if (requestId >= (this.lastRequestId[queryId] || 1)) { - this.store.dispatch({ - type: 'APOLLO_QUERY_ERROR', - error, - queryId, - requestId, - fetchMoreForQueryId, - }); - this.queryStore.markQueryError(queryId, error, fetchMoreForQueryId); this.broadcastQueries(); } @@ -791,11 +749,6 @@ export class QueryManager { public stopQueryInStore(queryId: string) { this.queryStore.stopQuery(queryId); this.broadcastQueries(); - - this.store.dispatch({ - type: 'APOLLO_QUERY_STOP', - queryId, - }); } public getApolloState(): Store { diff --git a/test/QueryManager.ts b/test/QueryManager.ts index cca0141a19e..dd5d8723b35 100644 --- a/test/QueryManager.ts +++ b/test/QueryManager.ts @@ -1518,83 +1518,6 @@ describe('QueryManager', () => { ); }); - it('does not call broadcastNewStore when Apollo state is not affected by an action', () => { - const query = gql` - query fetchLuke($id: String) { - people_one(id: $id) { - name - } - } - `; - - const variables = { - id: '1', - }; - - const data1 = { - people_one: { - name: 'Luke Skywalker', - }, - }; - - const data2 = { - people_one: { - name: 'Luke Skywalker has a new name', - }, - }; - - function testReducer (state = false, action: any): boolean { - if (action.type === 'TOGGLE') { - return true; - } - return state; - } - const client = new ApolloClient(); - const store = createStore( - combineReducers({ - test: testReducer, - apollo: client.reducer() as any, // XXX see why this type fails - }), - applyMiddleware(client.middleware()), - ); - const qm = createQueryManager({ - networkInterface: mockNetworkInterface( - { - request: { query, variables }, - result: { data: data1 }, - }, - { - request: { query, variables }, - result: { data: data2 }, - }, - ), - store: store, - }); - - const observable = qm.watchQuery({ query, variables, notifyOnNetworkStatusChange: false }); - - return observableToPromise({ observable }, - (result) => { - assert.deepEqual(result.data, data1); - observable.refetch(); - }, - (result) => { - assert.deepEqual(result.data, data2); - - // here's the actual test. Everything else is just setup. - let called = false; - client.queryManager.broadcastNewStore = (s: any) => { - called = true; - }; - store.dispatch({ - type: 'TOGGLE', - }); - assert.equal((store.getState() as any).test, true, 'test state should have been updated'); - assert.equal(called, false, 'broadcastNewStore should not have been called'); - }, - ); - }); - it(`doesn't return data while query is loading`, () => { const query1 = gql` { diff --git a/test/store.ts b/test/store.ts index 8397dacd54b..3cddc534a8a 100644 --- a/test/store.ts +++ b/test/store.ts @@ -152,21 +152,6 @@ describe('createApolloStore', () => { initialState, }); - store.dispatch({ - type: 'APOLLO_QUERY_INIT', - queryId: 'test.0', - queryString: '', - document: queryDocument, - operationName: getOperationName(queryDocument), - variables: {}, - fetchPolicy: 'cache-first', - requestId: 1, - storePreviousVariables: false, - isPoll: false, - isRefetch: false, - metadata: null, - }); - store.dispatch({ type: 'APOLLO_STORE_RESET', observableQueryIds: ['test.0'],