isographlabs / isograph

The UI framework for teams that move fast — without breaking things.
MIT License
230 stars 15 forks source link

Issue: require all exposed fields to be annotated with `@loadable` #103

Open rbalicki2 opened 1 week ago

rbalicki2 commented 1 week ago

If you choose to take this task on, we should hop on a call to hammer out all the details. It seems like a lot of work, but in practice it's not — as long as you know where to make the changes. (Hence the need for a call.)

The impact of this is high, it merges an unnecessary building block (refetch/exposed mutation fields) into another abstraction: @loadable fields (which is the one we want to go with in the long term)

This is a relatively thin outline:

Background

loadable fields

__refetch and re-exposed fields

Steps

There are (at least!) four main tasks here, all of which should happen in separate PRs. 1-3 will land as a single commit, 4 can land separately:

Step 1: Enforce @loadable

The compiler should emit an error if we don't select the __refetch and exposed mutation fields loadably.

This is a pure Rust change.

Step 2: modify the generated types

Step 3: Implementation of the refetch field

Right now, the __refetch field's inner function returns void. It should return a FragmentReference<void>.

Refetch fields and exposed mutation fields (at least for now) have nothing that you actually want to read as a result of calling them. But, you might want to suspend if the network request is in flight, get a loading indicator, etc. and the mechanism for that is to return a FragmentReference

Step 4: Unify some APIs

useImperativeExposedMutationField is now useless, and it can be replaced with useImperativeLoadableField! Woohoo!

The user can also call useClientSideDefer with refetch fields (maybe we should lint against that, that's likely to be a mistake?) and with mutations (which does make sense!)

byhlel commented 1 week ago

/assign :)

rbalicki2 commented 1 week ago

... comment moved to description ...

byhlel commented 6 days ago

Okay I'm down to try, would I encounter difficulties or be unavailable to continue working on the issue I'll make sure to keep you updated! Looking forward to contributing though!