Skip to content

Commit

Permalink
fixed react query client context setting
Browse files Browse the repository at this point in the history
  • Loading branch information
Zetazzz committed Oct 22, 2024
1 parent ef1b2c8 commit 7b6985a
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 16 deletions.
14 changes: 10 additions & 4 deletions __fixtures__/v-next/outputhelperfunc/react-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ export const useRpcClient = <TData = ProtobufRpcClient>({
options,
rpcClientQueryKey,
}: UseRpcClientQuery<TData>) => {
const queryClient = useQueryClient();
const queryClient = useQueryClient({
context: options?.context
});
const key = rpcClientQueryKey || DEFAULT_RPC_CLIENT_QUERY_KEY;
return useQuery<ProtobufRpcClient, Error, TData>([key, rpcEndpoint], async () => {
if(!rpcEndpoint) {
Expand Down Expand Up @@ -120,7 +122,9 @@ export function buildUseQuery<TReq, TRes>(opts: UseQueryBuilderOptions<TReq, TRe
rpcClientQueryKey,
customizedQueryKey,
}: UseQueryParams<TReq, TRes, TData>) => {
const queryClient = useQueryClient();
const queryClient = useQueryClient({
context: options?.context
});
const key = rpcClientQueryKey || DEFAULT_RPC_CLIENT_QUERY_KEY;
const queryKey = rpcEndpoint ? [key, rpcEndpoint] : [key];
const rpc = queryClient.getQueryData<Rpc>(queryKey);
Expand All @@ -137,7 +141,7 @@ export interface UseQueryParams<TReq, TRes, TData = TRes> extends ReactQueryPara
}

export interface ReactMutationParams<TData, TError, TVariables, TContext = unknown> {
options?: MutationOptions<TData, TError, TVariables, TContext>;
options?: UseMutationOptions<TData, TError, TVariables, TContext>;
rpcEndpoint?: string | HttpEndpoint;
signingClientQueryKey?: string;
}
Expand All @@ -159,7 +163,9 @@ export function buildUseMutation<TMsg, TError>(opts: UseMutationBuilderOptions<T
rpcEndpoint,
signingClientQueryKey
}: ReactMutationParams<DeliverTxResponse, TError, ITxArgs<TMsg>>) => {
const queryClient = useQueryClient();
const queryClient = useQueryClient({
context: options?.context
});
const key = signingClientQueryKey || DEFAULT_SIGNING_CLIENT_QUERY_KEY;
const queryKey = rpcEndpoint ? [key, rpcEndpoint] : [DEFAULT_SIGNING_CLIENT_QUERY_KEY];
const signingClient = queryClient.getQueryData<ISigningClient>(queryKey);
Expand Down
14 changes: 10 additions & 4 deletions __fixtures__/v-next/outputicjs/react-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ export const useRpcClient = <TData = ProtobufRpcClient>({
options,
rpcClientQueryKey,
}: UseRpcClientQuery<TData>) => {
const queryClient = useQueryClient();
const queryClient = useQueryClient({
context: options?.context
});
const key = rpcClientQueryKey || DEFAULT_RPC_CLIENT_QUERY_KEY;
return useQuery<ProtobufRpcClient, Error, TData>([key, rpcEndpoint], async () => {
if(!rpcEndpoint) {
Expand Down Expand Up @@ -93,7 +95,9 @@ export function buildUseQuery<TReq, TRes>(opts: UseQueryBuilderOptions<TReq, TRe
rpcClientQueryKey,
customizedQueryKey,
}: UseQueryParams<TReq, TRes, TData>) => {
const queryClient = useQueryClient();
const queryClient = useQueryClient({
context: options?.context
});
const key = rpcClientQueryKey || DEFAULT_RPC_CLIENT_QUERY_KEY;
const queryKey = rpcEndpoint ? [key, rpcEndpoint] : [key];
const rpc = queryClient.getQueryData<Rpc>(queryKey);
Expand All @@ -110,7 +114,7 @@ export interface UseQueryParams<TReq, TRes, TData = TRes> extends ReactQueryPara
}

export interface ReactMutationParams<TData, TError, TVariables, TContext = unknown> {
options?: MutationOptions<TData, TError, TVariables, TContext>;
options?: UseMutationOptions<TData, TError, TVariables, TContext>;
rpcEndpoint?: string | HttpEndpoint;
signingClientQueryKey?: string;
}
Expand All @@ -132,7 +136,9 @@ export function buildUseMutation<TMsg, TError>(opts: UseMutationBuilderOptions<T
rpcEndpoint,
signingClientQueryKey
}: ReactMutationParams<DeliverTxResponse, TError, ITxArgs<TMsg>>) => {
const queryClient = useQueryClient();
const queryClient = useQueryClient({
context: options?.context
});
const key = signingClientQueryKey || DEFAULT_SIGNING_CLIENT_QUERY_KEY;
const queryKey = rpcEndpoint ? [key, rpcEndpoint] : [DEFAULT_SIGNING_CLIENT_QUERY_KEY];
const signingClient = queryClient.getQueryData<ISigningClient>(queryKey);
Expand Down
14 changes: 10 additions & 4 deletions packages/telescope/src/helpers/react-query-hooks-icjs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ export const useRpcClient = <TData = ProtobufRpcClient>({
options,
rpcClientQueryKey,
}: UseRpcClientQuery<TData>) => {
const queryClient = useQueryClient();
const queryClient = useQueryClient({
context: options?.context
});
const key = rpcClientQueryKey || DEFAULT_RPC_CLIENT_QUERY_KEY;
return useQuery<ProtobufRpcClient, Error, TData>([key, rpcEndpoint], async () => {
if(!rpcEndpoint) {
Expand Down Expand Up @@ -110,7 +112,9 @@ export function buildUseQuery<TReq, TRes>(opts: UseQueryBuilderOptions<TReq, TRe
rpcClientQueryKey,
customizedQueryKey,
}: UseQueryParams<TReq, TRes, TData>) => {
const queryClient = useQueryClient();
const queryClient = useQueryClient({
context: options?.context
});
const key = rpcClientQueryKey || DEFAULT_RPC_CLIENT_QUERY_KEY;
const queryKey = rpcEndpoint ? [key, rpcEndpoint] : [key];
const rpc = queryClient.getQueryData<Rpc>(queryKey);
Expand All @@ -127,7 +131,7 @@ export interface UseQueryParams<TReq, TRes, TData = TRes> extends ReactQueryPara
}
export interface ReactMutationParams<TData, TError, TVariables, TContext = unknown> {
options?: MutationOptions<TData, TError, TVariables, TContext>;
options?: UseMutationOptions<TData, TError, TVariables, TContext>;
rpcEndpoint?: string | HttpEndpoint;
signingClientQueryKey?: string;
}
Expand All @@ -149,7 +153,9 @@ export function buildUseMutation<TMsg, TError>(opts: UseMutationBuilderOptions<T
rpcEndpoint,
signingClientQueryKey
}: ReactMutationParams<DeliverTxResponse, TError, ITxArgs<TMsg>>) => {
const queryClient = useQueryClient();
const queryClient = useQueryClient({
context: options?.context
});
const key = signingClientQueryKey || DEFAULT_SIGNING_CLIENT_QUERY_KEY;
const queryKey = rpcEndpoint ? [key, rpcEndpoint] : [DEFAULT_SIGNING_CLIENT_QUERY_KEY];
const signingClient = queryClient.getQueryData<ISigningClient>(queryKey);
Expand Down
14 changes: 10 additions & 4 deletions packages/telescope/src/helpers/react-query-hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ export const useRpcClient = <TData = ProtobufRpcClient>({
options,
rpcClientQueryKey,
}: UseRpcClientQuery<TData>) => {
const queryClient = useQueryClient();
const queryClient = useQueryClient({
context: options?.context
});
const key = rpcClientQueryKey || DEFAULT_RPC_CLIENT_QUERY_KEY;
return useQuery<ProtobufRpcClient, Error, TData>([key, rpcEndpoint], async () => {
if(!rpcEndpoint) {
Expand Down Expand Up @@ -151,7 +153,9 @@ export function buildUseQuery<TReq, TRes>(opts: UseQueryBuilderOptions<TReq, TRe
rpcClientQueryKey,
customizedQueryKey,
}: UseQueryParams<TReq, TRes, TData>) => {
const queryClient = useQueryClient();
const queryClient = useQueryClient({
context: options?.context
});
const key = rpcClientQueryKey || DEFAULT_RPC_CLIENT_QUERY_KEY;
const queryKey = rpcEndpoint ? [key, rpcEndpoint] : [key];
const rpc = queryClient.getQueryData<Rpc>(queryKey);
Expand All @@ -168,7 +172,7 @@ export interface UseQueryParams<TReq, TRes, TData = TRes> extends ReactQueryPara
}
export interface ReactMutationParams<TData, TError, TVariables, TContext = unknown> {
options?: MutationOptions<TData, TError, TVariables, TContext>;
options?: UseMutationOptions<TData, TError, TVariables, TContext>;
rpcEndpoint?: string | HttpEndpoint;
signingClientQueryKey?: string;
}
Expand All @@ -190,7 +194,9 @@ export function buildUseMutation<TMsg, TError>(opts: UseMutationBuilderOptions<T
rpcEndpoint,
signingClientQueryKey
}: ReactMutationParams<DeliverTxResponse, TError, ITxArgs<TMsg>>) => {
const queryClient = useQueryClient();
const queryClient = useQueryClient({
context: options?.context
});
const key = signingClientQueryKey || DEFAULT_SIGNING_CLIENT_QUERY_KEY;
const queryKey = rpcEndpoint ? [key, rpcEndpoint] : [DEFAULT_SIGNING_CLIENT_QUERY_KEY];
const signingClient = queryClient.getQueryData<ISigningClient>(queryKey);
Expand Down

0 comments on commit 7b6985a

Please sign in to comment.