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

useAsyncQuery clientId parameter doesn't work #455

Closed
artm4r opened this issue Dec 5, 2022 · 3 comments · Fixed by #597
Closed

useAsyncQuery clientId parameter doesn't work #455

artm4r opened this issue Dec 5, 2022 · 3 comments · Fixed by #597
Assignees
Labels

Comments

@artm4r
Copy link

artm4r commented Dec 5, 2022

Environment

  • Operating System: Windows_NT
  • Node Version: v16.18.1
  • Nuxt Version: 3.0.0
  • Nitro Version: 1.0.0
  • Package Manager: [email protected]
  • Builder: vite
  • User Config: plugins, modules, apollo
  • Runtime Modules: @nuxtjs/[email protected], @nuxtjs/[email protected]
  • Build Modules: -

Describe the bug

useAsyncQuery(GetComentsForHome, 'reviews') uses the 'default ' client even though I specified a different client.
useQuery(GetComentsForHome, { clientId: 'reviews' }) works fine.

Expected behaviour

I expect module to use specified client instead of default

Reproduction

No response

Additional context

No response

Logs

No response

@artm4r artm4r added the bug label Dec 5, 2022
@artm4r
Copy link
Author

artm4r commented Dec 5, 2022

const { data } = await useAsyncQuery({ query: GetComentsForHome, clientId: 'reviews', })
this syntax works, but this solution is not quite obvious

@Diizzayy Diizzayy self-assigned this Dec 5, 2022
@lewebsimple
Copy link

lewebsimple commented Dec 9, 2022

I can confirm this, as I'm getting the same behaviour !

@slavanossar
Copy link
Contributor

Was also experiencing this, looking at the typings shows the different ways to pass parameters to useAsyncQuery

type TQuery<T> = QueryOptions<OperationVariables, T>['query'];
type TVariables<T> = QueryOptions<OperationVariables, T>['variables'];
type TAsyncQuery<T> = {
    query: TQuery<T>;
    variables?: TVariables<T>;
    key?: string;
    cache?: boolean;
    clientId?: string;
};
export declare function useAsyncQuery<T>(opts: TAsyncQuery<T>): AsyncData<T, Error>;
export declare function useAsyncQuery<T>(query: TQuery<T>, clientId?: string): AsyncData<T, Error>;
export declare function useAsyncQuery<T>(query: TQuery<T>, variables?: TVariables<T>, clientId?: string): AsyncData<T, Error>;

So for the following

const { data } = useAsyncQuery<MyQueryType>(
  MyQueryDocument,
  {
    someVariable: 'abc',
  },
  'myApolloClient'
)

you can rewrite it as

const { data } = useAsyncQuery<MyQueryType>({
  query: MyQueryDocument,
  variables: {
    someVariable: 'abc',
  },
  clientId: 'myApolloClient'
})

and it will work correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment