Skip to content

Allow duplicate graphql calls if variables are different#1244

Open
indykoning wants to merge 1 commit intomasterfrom
bugfix/allow-multiple-graphql-calls
Open

Allow duplicate graphql calls if variables are different#1244
indykoning wants to merge 1 commit intomasterfrom
bugfix/allow-multiple-graphql-calls

Conversation

@indykoning
Copy link
Copy Markdown
Member

@indykoning indykoning commented Mar 20, 2026

In: #740 this check was introduced.
It fixed accidental double clicks causing duplicate requests.

But it also broke the same graphql component sending a request with different variables, which would now get short circuited without sending a request to update the data.

This would for instance cause issues with postcode modules updating the address.
As the change event on a postcode field would trigger the mutate for the updated postcode, at the same time the postcode module would update the street and city.
Attempting to mutate it would result in nothing since the previous mutation has not finished yet.

When this is approved i will roll this change out to the other packages (postcode-change event), as well as the 4.x branch

ref: RAP-1827

@indykoning indykoning requested a review from royduin as a code owner March 20, 2026 12:33
@indykoning indykoning requested a review from Jade-GG March 20, 2026 12:33
methods: {
async mutateFn() {
if (this.running) {
if (this.running && JSON.stringify(this.data) === JSON.stringify(this.runningVariables)) {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be improved with canceling the previous request, or returning the current request depending on data changes.

But this would require a much larger structural change with the fetch requests, and the way functions are handled here:
https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch#canceling_a_request

This has been added to: RAP-1230

let variables = this.data,
query = this.query

this.runningVariables = JSON.parse(JSON.stringify(this.data))
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we're only really using this stringified, is it worth it just for the code consistency to end up doing JSON.stringify(JSON.parse(JSON.stringify(this.data)))?

The performance hit is essentially neglegible so it doesn't really matter too much, but it doesn't feel right to me that we're juggling the json around like this.

Perhaps we could consider a different approach as well. We already have a watcher for the variables data changing---what if we just increase a counter every time the variables are changed, and use that to compare with?

name="{{ $type }}_postcode"
v-model="variables.postcode"
v-on:change="$root.$nextTick(() => window.$emit('postcode-change', variables))"
v-on:change="(event) => $root.$nextTick(() => window.$emit('postcode-change', variables, event))"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this the best way to pass the event along? How would this look on the postcode package side?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants