Skip to content

Commit

Permalink
Place not emitting actions under a flag
Browse files Browse the repository at this point in the history
  • Loading branch information
shadaj committed Jul 12, 2017
1 parent dbf646c commit 1756ab3
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 38 deletions.
86 changes: 48 additions & 38 deletions src/core/QueryManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ import {
import { ObservableQuery } from './ObservableQuery';

export class QueryManager {
public static EMIT_REDUX_ACTIONS = true;

public pollingTimers: {[queryId: string]: any};
public scheduler: QueryScheduler;
public store: ApolloStore;
Expand Down Expand Up @@ -463,23 +465,25 @@ 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,
});
if (QueryManager.EMIT_REDUX_ACTIONS) {
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;

Expand All @@ -490,16 +494,18 @@ export class QueryManager {
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 (QueryManager.EMIT_REDUX_ACTIONS) {
this.store.dispatch({
type: 'APOLLO_QUERY_RESULT_CLIENT',
result: { data: storeResult },
variables,
document: queryDoc,
operationName: getOperationName(queryDoc),
complete: !shouldFetch,
queryId,
requestId,
});
}
}

if (shouldFetch) {
Expand All @@ -516,13 +522,15 @@ export class QueryManager {
throw error;
} else {
if (requestId >= (this.lastRequestId[queryId] || 1)) {
this.store.dispatch({
type: 'APOLLO_QUERY_ERROR',
error,
queryId,
requestId,
fetchMoreForQueryId,
});
if (QueryManager.EMIT_REDUX_ACTIONS) {
this.store.dispatch({
type: 'APOLLO_QUERY_ERROR',
error,
queryId,
requestId,
fetchMoreForQueryId,
});
}

this.queryStore.markQueryError(queryId, error, fetchMoreForQueryId);
this.broadcastQueries();
Expand Down Expand Up @@ -792,10 +800,12 @@ export class QueryManager {
this.queryStore.stopQuery(queryId);
this.broadcastQueries();

this.store.dispatch({
type: 'APOLLO_QUERY_STOP',
queryId,
});
if (QueryManager.EMIT_REDUX_ACTIONS) {
this.store.dispatch({
type: 'APOLLO_QUERY_STOP',
queryId,
});
}
}

public getApolloState(): Store {
Expand Down
3 changes: 3 additions & 0 deletions test/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
import 'es6-promise';
import 'isomorphic-fetch';

import { QueryManager } from '../src/core/QueryManager';

process.env.NODE_ENV = 'test';
QueryManager.EMIT_REDUX_ACTIONS = false;

declare function require(name: string): any;
require('source-map-support').install();
Expand Down

0 comments on commit 1756ab3

Please sign in to comment.