-
Notifications
You must be signed in to change notification settings - Fork 19
Ability to pass CallOptions #516
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
Comments
Changing this option to callOption and passing callotpion here from all places which use this would solve this issue. |
We didn't expose call options intentionally because it can be a little tricky to also track those options with the query key (if the call option changes, making sure it also triggers a query, etc). Is there a specific call option you are trying to pass? |
@paul-sachs I am trying to pass contextValues from callOption. |
So contextValues is one of those things that's hard to track in a querykey since there's currently no way to expose all the values set, and I'm not sure we'd want to trigger a fetch on anytime those context values change. It might help to identify exactly how you're using context to identify a good way we can build context support into connect-query without breaking the reactivity model.
|
Do interceptors in the web set this context and should that trigger additional fetches? |
Hmm I think I understand. We can pass through context values but being responsive to their changes is a little tricky. You can create your own implementation of ContextValues that is perhaps backed by a signals implementation like preact/signals but we'd still need a way to modify the connect-query key to include those values, and ideally, a way to filter those down to only include the keys you actually use in the query. I'm thinking this could look something like this: // A hypothetical API
import { createContextKey, useContextValues } from "some-package";
import { useQuery } from "@connectrpc/connect-query";
const kLogBody = createContextKey<boolean>(false, {
description: "Log request/response body",
});
const SomeComponent = () => {
const ctxValues = useContextValues([kLogBody]);
const someQuery = useQuery(schema, undefined, { contextValues: ctxValues });
...
} The above API is purely hypothetical and relies on the relatively new concept of reactive signals but would be compatible with the We'll need to do some investigation to figure out how can break this up into pieces and ideally not absorb a new dependency (like signals). |
@ravilamichhane did you find a workaround? We've experimented internally with my solution but it has some quirks that we're starting to think aren't worth supporting. You can still get by with using custom transport with interceptors which set the contextValues. |
I needed to pass callOptions for a few mutations — mainly to inject some contextValues our interceptors depend on. So I just modified useMutation to accept callOptions directly. It’s a pretty minimal change and doesn’t affect queries at all, which was nice. Not clean, but it got the job done. |
I am using multiple interceptors on my transport that take calloption and perform certain actions.
When using a client created from createClient we can pass calloptions to the methods. But I didnot find any option to pass calloption when using connect-query. It would be nice to have this feature.
The text was updated successfully, but these errors were encountered: