Page MenuHomePhabricator

Use Apollo cache normalization for schedule stop/start
ClosedPublic

Authored by sashank on Thu, Nov 7, 10:01 PM.

Details

Reviewers
prha
Group Reviewers
Restricted Project
Commits
R1:b22e0cd23019: Use Apollo cache normalization for schedule stop/start
Summary

Previously, the Dagit scheduler page would use optimistic updates to update the state of the schedule state toggle. This diff changes it to properly use Apollo's cache normalization for mutations.

https://www.apollographql.com/docs/angular/features/cache-updates/

Test Plan

Start and stop schedules from Dagit, verify they are in the correct state

Diff Detail

Repository
R1 dagster
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

sashank created this revision.Thu, Nov 7, 10:01 PM
sashank edited the summary of this revision. (Show Details)Thu, Nov 7, 10:02 PM
sashank added a reviewer: Restricted Project.
sashank edited the summary of this revision. (Show Details)
sashank edited the test plan for this revision. (Show Details)
sashank updated this revision to Diff 6362.Thu, Nov 7, 10:12 PM

Update tests

prha added a subscriber: prha.Thu, Nov 7, 10:43 PM

How does this work? Why don't we need the optimisticResponse param described here: https://www.apollographql.com/docs/react/performance/optimistic-ui/?

@prha We used to do that manually, but now we let Apollo reconcile the response from the mutation with the store to update the UI.

Since them mutation returns

schedule {
    id
    status
}

and the root query which the toggle status depends on queries also queries for:

runningSchedules {
    id
    ... other things
   status
}

Apollo uses the __typename and id to find the record in the store to update with the new status returned from the mutation.

prha added a comment.Thu, Nov 7, 11:15 PM

I see... but that means we're no longer "optimistic"... we first have to wait for the server to respond, right?

Yup exactly. But the mutation is fast and it feels instantaneous already

sashank planned changes to this revision.Thu, Nov 7, 11:32 PM
sashank updated this revision to Diff 6386.Thu, Nov 7, 11:36 PM

Add optimisticResponse to mutations

prha accepted this revision.Fri, Nov 8, 12:13 AM

cool, I was just checking that we were doing what we wanted.

But the optimisticResponse change looks good too!

shipit

This revision is now accepted and ready to land.Fri, Nov 8, 12:13 AM