Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFC] imperatively loadable fields to unlock refetchable, paginated, load once, etc. fields #78

Open
rbalicki2 opened this issue Apr 28, 2024 · 0 comments

Comments

@rbalicki2
Copy link
Collaborator

rbalicki2 commented Apr 28, 2024

Goal

  • Allow fields (which normally read out data) to be transformed into a common primitive that can power refetchable, loadOnce, paginated, fake deferred, etc fields

Plan

  • Add some sort of way to make fields imperatively loadable
  • Later, add the ability to make fields imperatively loaded at normalization time (including later normalization time of unrelated queries, as long as that query is mounted.) (Or, perhaps, for arbitrary code to run at normalization time iff the query is retained.) (See [RFC] Normalization-time loaded fields #79 )

Details

  • The imperatively loadable field will not have type T anymore, but instead have type { load: (variables) => Disposable<FragmentReference<_, T>> }
  • The initial way this will be used might be as follows:
iso(`
  field Query.HomePage {
    ViewerComponent @imperative
    blogs @imperative {
      BlogComponent
    }
  }
`)((data)=>{
  // loadOnce has type { kind: 'Loaded', data: T } | { kind: 'NotLoaded', load: (variables) => void }
  const loadOnce = useLoadOnce(data.ViewerComponent);
  
  // paginate has type { data: Array<T>, loadMore: (count) => void, hasNext: boolean, isLoadingMore: boolean }
  const paginate = usePagination(data.blogs);
})
  • In the long term, you should be able to embed the transforms (e.g. useLoadOnce, usePagination, etc.) in the iso literal, as in:
iso(`
  field Query.HomePage {
    ViewerComponent @imperative | useLoadOnce
  }
`)((data)=>{})
@rbalicki2 rbalicki2 changed the title [RFC] refetchable, paginated, loadable, etc. fields [RFC] imperatively loadable fields to unlock refetchable, paginated, loadable, etc. fields Apr 28, 2024
@rbalicki2 rbalicki2 changed the title [RFC] imperatively loadable fields to unlock refetchable, paginated, loadable, etc. fields [RFC] imperatively loadable fields to unlock refetchable, paginated, load once, etc. fields Apr 28, 2024
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

No branches or pull requests

1 participant