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

provideQueryClient accept a function #204

Open
radekdob opened this issue Jan 11, 2025 · 1 comment
Open

provideQueryClient accept a function #204

radekdob opened this issue Jan 11, 2025 · 1 comment

Comments

@radekdob
Copy link

Which @ngneat/query-* package(s) are relevant/releated to the feature request?

query

Description

I was implementing SSR with new AngularAppNodeEngine and the current solution from docs of how to support hydration process is not available since now, server.ts no longer allows to specify providers, so we can't define a queryClient there and provide it downstream using provideQueryClient(client).

What we can do is to initialise query client on each request handler and put it into REQUEST_CONTEXT token which will be available in application scope, e.g. in app.server.config.

But we need to be in injection context and provideQueryClient() does not support passing factory function(so we can extract query client and use it).

Proposed solution

expected usage

provideQueryClient(() => {
     const requestContext = inject(REQUEST_CONTEXT, { optional: true }) as {
       queryClient: QueryClient;
     } | undefined;

     return requestContext?.queryClient || new QueryClient();
   })

modified function

function provideQueryClient(queryClientOrFactory) {
  return {
    provide: QueryClientToken,
    useFactory:
      typeof queryClientOrFactory === 'function'
        ? queryClientOrFactory
        : () => queryClientOrFactory,
  };
}

Alternatives considered

export token which is provided by provideQueryClient?

Do you want to create a pull request?

Yes

@NetanelBasal
Copy link
Member

You're welcome to create a PR

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

2 participants