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 #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)=>{})
Goal
Plan
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:
In the long term, you should be able to embed the transforms (e.g. useLoadOnce, usePagination, etc.) in the iso literal, as in: