Skip to content

Commit

Permalink
Add React Apollo changes from PR #3515
Browse files Browse the repository at this point in the history
  • Loading branch information
hwillson committed Oct 2, 2019
1 parent 0b028a1 commit 33c817b
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
7 changes: 5 additions & 2 deletions src/react/data/OperationData.ts
Expand Up @@ -26,8 +26,11 @@ export abstract class OperationData<TOptions = any> {
return this.options;
}

public setOptions(newOptions: CommonOptions<TOptions>) {
if (!isEqual(this.options, newOptions)) {
public setOptions(
newOptions: CommonOptions<TOptions>,
storePrevious: boolean = false
) {
if (storePrevious && !isEqual(this.options, newOptions)) {
this.previousOptions = this.options;
}
this.options = newOptions;
Expand Down
8 changes: 4 additions & 4 deletions src/react/data/QueryData.ts
Expand Up @@ -48,7 +48,7 @@ export class QueryData<TData, TVariables> extends OperationData {
public execute(): QueryResult<TData, TVariables> {
this.refreshClient();

const { skip, query, ssr } = this.getOptions();
const { skip, query } = this.getOptions();
if (skip || query !== this.previousData.query) {
this.removeQuerySubscription();
this.previousData.query = query;
Expand All @@ -58,9 +58,7 @@ export class QueryData<TData, TVariables> extends OperationData {

if (this.isMounted) this.startQuerySubscription();

const ssrDisabled = ssr === false;

return this.getExecuteSsrResult(ssrDisabled) || this.getExecuteResult();
return this.getExecuteSsrResult() || this.getExecuteResult();
}

public executeLazy(): QueryTuple<TData, TVariables> {
Expand Down Expand Up @@ -90,6 +88,7 @@ export class QueryData<TData, TVariables> extends OperationData {

public afterExecute({ lazy = false }: { lazy?: boolean } = {}) {
this.isMounted = true;

if (!lazy || this.runLazy) {
this.handleErrorOrCompleted();

Expand All @@ -103,6 +102,7 @@ export class QueryData<TData, TVariables> extends OperationData {
});
}

this.previousOptions = this.getOptions();
return this.unmount.bind(this);
}

Expand Down
2 changes: 1 addition & 1 deletion src/react/hooks/__tests__/useLazyQuery.test.tsx
Expand Up @@ -417,7 +417,7 @@ describe('useLazyQuery Hook', () => {
expect(loading).toEqual(false);
expect(data).toEqual(CAR_RESULT_DATA);
setTimeout(() => {
execute();
execute({ variables: { someProp: 'someValue' } });
});
break;
case 3:
Expand Down
2 changes: 1 addition & 1 deletion src/react/hooks/useSubscription.ts
Expand Up @@ -33,7 +33,7 @@ export function useSubscription<TData = any, TVariables = OperationVariables>(
}

const subscriptionData = getSubscriptionDataRef();
subscriptionData.setOptions(updatedOptions);
subscriptionData.setOptions(updatedOptions, true);
subscriptionData.context = context;

useEffect(() => subscriptionData.afterExecute());
Expand Down

0 comments on commit 33c817b

Please sign in to comment.