usePreloadedQuery, loadQuery & loadLazyQuery #90
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
this PR introduces usePreloadedQuery, useLoad & useLazyLoad
loadQuery
same as useQuery + environment
next: ( environment: IEnvironment, gqlQuery: GraphQLTaggedNode, variables?: TOperationType['variables'], options?: QueryOptions, ) => Promise<void>
: fetches data. A promise returns to allow the await in case of SSRdispose: () => void
: cancel the subscription and dispose of the fetchsubscribe: (callback: (value: any) => any) => () => void
: used by the usePreloadedQuerygetValue: (environment?: IEnvironment) => RenderProps<TOperationType> | Promise<any>
: used by the usePreloadedQueryloadLazyQuery
is the same as loadQuery but must be used with suspense
usePreloadedQuery
input parameters
output parameters
Both the implementation and its use differs from the current implementation in relay-experimental.
In summary, it implements the logic of the BehaviorSubject of rxjs including the subscribe, getValue and the next but with the difference that the next function it is asynchronous and introduces the "dispose".
Through this management it is sufficient to create a single loadQuery to manage multiple routes and avoid using cache maps within the library.
While the dispose function has been designed to manage error cases in order to correctly delete the last route performed.