Description
Describe the bug
I have a vue project. We use the composition API. Therefore we use provideApolloClient
in order to provide the client to all usages of useQuery
, useMutation
, etc. We want to use a second apollo client for a specific new subscription. Switching to provideApolloClients
and using clientId
as an option leads to an
No apolloClients injection found, tried to resolve 'otherClient' clientId
error.
To Reproduce
On App.vue
-level we do in one hook
import { ApolloClients, provideApolloClients } from '@vue/apollo-composable';
export const useProvideApolloClients = () => {
function createApolloClient(httpLink: string, webSocketLink: string) {
// does necessary option and setup stuff specific to our clients
}
const clientA = createApolloClient(clientAHttpLink, clientAWebsockeLink);
const clientB = createApolloClient(clientAHttpLink, clientAWebsocketLink);
// This allows-composable apollo to manage the apollo client on its own, no need for providing it via vue
provideApolloClients({
default: clientA,
clientA: clientA,
clientB: clientB,
});
};
Further down the road still on App.Vue
level, we have subscriptions that use these clients. When I try to use a specific clientId
the error appears and the subscription does not work.
import { importantSubscriptionQuery } from '@/queries/important';
import { useSubscription } from '@vue/apollo-composable';
export const useImportantSubscription = () => {
const { onResult } = useSubscription(acpStartupStatusQuery, null, () => ({
enabled: state.value,
clientId: 'clientB',
}));
onResult((result) => {
// do something cool with the result
});
};
In App.vue
we first call useProvideApolloCLients
, afterwards we start the subscriptions
<script setup lang="ts">
import { useProvideApolloClients } from '@/hooks/useProvideApolloClients';
import useImportantSubscription from '@/hooks/useImportantSubscription';
useProvideApolloClients();
useImportantSubscription();
</script>
Looking into the console logs, one can see that using the clientId
always leads to an No apolloClients injection found, tried to resolve 'otherClient' clientId
error. Even when I use "default"
as clientId
. Somehow it can not find the injected clients object.
Expected behavior
I expected the above setup to work and for the subscription to use "clientB"
Versions
vue: ^3.3.4
@vue/apollo-composable: ^4.0.0-beta.1
@apollo/client: ^3.7.6
Additional context
So far I couldn't find any blog or documentation entry that actually showed how to properly use multiple clients with apollo-composable
what you can see above is what I put my self together so far. Therefore, If you know how to properly do this or saw some blogish entry on how to do this, I'd be happy to receive a link to it.
Edit:
Using no clientId
does work and leads to no error. Therefore I think it somehow can find the injected clients when default is used by the function itself. But as described above, even when I set clientId
to "default" then it still can't find any clients.