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

Allow QueryManager to intercept hook functionality #11617

Merged
merged 17 commits into from
Mar 5, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
adjust comment
phryneas committed Feb 26, 2024

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
commit a114bb05ae33b5e2e55b28fbd6c0a72a404d7f4a
20 changes: 16 additions & 4 deletions src/react/hooks/internal/wrapHook.ts
Original file line number Diff line number Diff line change
@@ -45,12 +45,24 @@ interface QueryManagerWithWrappers<T> extends QueryManager<T> {
* // this is already done in `@apollo/client` for all wrappable hooks (see `WrappableHooks`)
* const wrappedUseQuery = makeHookWrappable('useQuery', useQuery, (_, options) => options.client);
*
* // although for tree-shaking purposes, in reality it looks more like
* function useQuery() {
* useQuery = makeHookWrappable('useQuery', (_, options) => options.client, _useQuery);
* return useQuery.apply(null, arguments as any);
* }
* function _useQuery() {
* // original implementation
* }
*
* // this is what a library like `@apollo/client-react-streaming` would do
* class ApolloClientWithStreaming extends ApolloClient {
* [Symbol.for("apollo.hook.wrappers")] = {
* useQuery: (original) => (query, options) => {
* console.log("useQuery was called with options", options);
* return original(query, options);
* constructor(options) {
* super(options);
* this.queryManager[Symbol.for("apollo.hook.wrappers")] = {
* useQuery: (original) => (query, options) => {
* console.log("useQuery was called with options", options);
* return original(query, options);
* }
* }
* }
* }