Skip to content

Commit 5fd5275

Browse files
committed
Avoid stale organization data when calling UpdatePartner
1 parent 4363d64 commit 5fd5275

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

src/scenes/Partners/Detail/PartnerDetail.graphql

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,20 @@ query Partner($input: ID!) {
66

77
fragment partnerDetails on Partner {
88
...Id
9-
createdAt
9+
...partnerOwnDetails
1010
organization {
1111
canRead
1212
canEdit
1313
value {
1414
...organizationDetails
1515
}
1616
}
17+
}
18+
19+
# Seperated for UpdatePartner mutation
20+
fragment partnerOwnDetails on Partner {
21+
...Id
22+
createdAt
1723
pointOfContact {
1824
canRead
1925
canEdit

src/scenes/Partners/Edit/UpdatePartner.graphql

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,20 @@ mutation UpdatePartner(
44
) {
55
updatePartner(input: { partner: $partner }) {
66
partner {
7-
...partnerDetails
7+
# Organization data cannot be fetched here as it will be stale.
8+
#
9+
# The API executes these two mutations in parallel, independently.
10+
# `Partner.organization` doesn't know it there's another organization update going on,
11+
# and will return the stale data.
12+
# Apollo Client would then receive two sets of org data:
13+
# - `updateOrganization.organization` result
14+
# - `updatePartner.partner.organization` result
15+
# They will be conflict, with the former fresh, and the latter stale.
16+
# We can avoid this race / nondeterministic behavior by only returning one org data set.
17+
#
18+
# Also, Apollo Client still has the normalized organization for the partner record,
19+
# so it knows how to connect it together when requested for the detail page.
20+
...partnerOwnDetails
821
}
922
}
1023
updateOrganization(input: { organization: $organization }) {

0 commit comments

Comments
 (0)