Skip to content

Commit

Permalink
Fix mutation error leak
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilkisiela committed Oct 14, 2020
1 parent bd778d1 commit 74e22c2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
14 changes: 7 additions & 7 deletions src/core/ApolloClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,11 @@ export class ApolloClient<TCacheShape> implements DataProxy {
typeof window !== 'undefined' &&
!(window as any).__APOLLO_CLIENT__;

if (
typeof connectToDevTools === 'undefined'
? defaultConnectToDevTools
: connectToDevTools && typeof window !== 'undefined'
) {
const shouldConnectToDevTools = typeof connectToDevTools === 'undefined'
? defaultConnectToDevTools
: connectToDevTools && typeof window !== 'undefined'

if (shouldConnectToDevTools) {
(window as any).__APOLLO_CLIENT__ = this;
}

Expand Down Expand Up @@ -234,7 +234,7 @@ export class ApolloClient<TCacheShape> implements DataProxy {
},
localState: this.localState,
assumeImmutableResults,
onBroadcast: () => {
onBroadcast: shouldConnectToDevTools ? () => {
if (this.devToolsHookCb) {
this.devToolsHookCb({
action: {},
Expand All @@ -245,7 +245,7 @@ export class ApolloClient<TCacheShape> implements DataProxy {
dataWithOptimisticResults: this.cache.extract(true),
});
}
},
} : undefined,
});
}

Expand Down
7 changes: 5 additions & 2 deletions src/core/MutationStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,14 @@ export class MutationStore {
};
}

public markMutationError(mutationId: string, error: Error) {
public markMutationError(mutationId: string, error?: Error) {
const mutation = this.store[mutationId];
if (mutation) {
mutation.loading = false;
mutation.error = error;

if (error) {
mutation.error = error;
}
}
}

Expand Down
8 changes: 5 additions & 3 deletions src/core/QueryManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ type QueryWithUpdater = {
queryInfo: QueryInfo;
};

const noop = () => undefined;

export class QueryManager<TStore> {
public cache: ApolloCache<TStore>;
public link: ApolloLink;
Expand All @@ -73,7 +75,7 @@ export class QueryManager<TStore> {
cache,
link,
queryDeduplication = false,
onBroadcast = () => undefined,
onBroadcast = noop,
ssrMode = false,
clientAwareness = {},
localState,
Expand Down Expand Up @@ -252,7 +254,7 @@ export class QueryManager<TStore> {
},

error(err: Error) {
self.mutationStore.markMutationError(mutationId, err);
self.mutationStore.markMutationError(mutationId, self.onBroadcast === noop ? undefined : err);
if (optimisticResponse) {
self.cache.removeOptimistic(mutationId);
}
Expand All @@ -266,7 +268,7 @@ export class QueryManager<TStore> {

complete() {
if (error) {
self.mutationStore.markMutationError(mutationId, error);
self.mutationStore.markMutationError(mutationId, self.onBroadcast === noop ? undefined : error);
}

if (optimisticResponse) {
Expand Down

0 comments on commit 74e22c2

Please sign in to comment.