Skip to content

Commit

Permalink
Fix default variable handling
Browse files Browse the repository at this point in the history
  • Loading branch information
phryneas committed Aug 5, 2024
1 parent c95848e commit c440b32
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/tall-emus-rush.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@apollo/client": patch
---

Fix default variable handling
25 changes: 21 additions & 4 deletions src/core/ObservableQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,13 @@ export class ObservableQuery<
this.queryName = opDef && opDef.name && opDef.name.value;
}

private prepareVariables(variables: TVariables, query = this.query) {
return this.queryManager["getVariables"](
this.queryManager.transform(query),
variables
) as TVariables;
}

public result(): Promise<ApolloQueryResult<TData>> {
return new Promise((resolve, reject) => {
// TODO: this code doesn’t actually make sense insofar as the observer
Expand Down Expand Up @@ -412,10 +419,11 @@ Did you mean to call refetch(variables) instead of refetch({ variables })?`,

if (variables && !equal(this.options.variables, variables)) {
// Update the existing options with new variables
reobserveOptions.variables = this.options.variables = {
...this.options.variables,
...variables,
} as TVariables;
reobserveOptions.variables = this.options.variables =
this.prepareVariables({
...this.options.variables,
...variables,
} as TVariables);
}

this.queryInfo.resetLastWrite();
Expand Down Expand Up @@ -914,6 +922,15 @@ Did you mean to call refetch(variables) instead of refetch({ variables })?`,
const oldVariables = this.options.variables;
const oldFetchPolicy = this.options.fetchPolicy;

if (newOptions && newOptions.variables) {
newOptions = {
...newOptions,
variables: this.prepareVariables(
newOptions.variables,
newOptions.query
),
};
}
const mergedOptions = compact(this.options, newOptions || {});
const options =
useDisposableConcast ?
Expand Down

0 comments on commit c440b32

Please sign in to comment.