diff --git a/src/module.ts b/src/module.ts index 125b5439..78f4c4ce 100644 --- a/src/module.ts +++ b/src/module.ts @@ -1,6 +1,5 @@ import { existsSync } from 'fs' import jiti from 'jiti' -import type { Ref } from 'vue' import { defu } from 'defu' import { useLogger, addPlugin, addImports, addTemplate, createResolver, defineNuxtModule } from '@nuxt/kit' import GraphQLPlugin from '@rollup/plugin-graphql' @@ -198,11 +197,6 @@ export default defineNuxtModule({ export const defineApolloClient = (config: ClientConfig) => config -export interface ModuleRuntimeHooks { - 'apollo:auth': (params: { client: string, token: Ref }) => void - 'apollo:error': (error: ErrorResponse) => void -} - export interface ModuleRuntimeConfig { apollo: NuxtApolloConfig } @@ -211,10 +205,6 @@ export interface ModulePublicRuntimeConfig { apollo: NuxtApolloConfig } -declare module '#app' { - interface RuntimeNuxtHooks extends ModuleRuntimeHooks {} -} - declare module '@nuxt/schema' { interface NuxtConfig { ['apollo']?: Partial } interface NuxtOptions { ['apollo']?: ModuleOptions } diff --git a/src/runtime/plugin.ts b/src/runtime/plugin.ts index faeb0fa2..9263dbc1 100644 --- a/src/runtime/plugin.ts +++ b/src/runtime/plugin.ts @@ -6,9 +6,11 @@ import { ApolloClients, provideApolloClients } from '@vue/apollo-composable' import { ApolloClient, ApolloLink, createHttpLink, InMemoryCache, split } from '@apollo/client/core' import { GraphQLWsLink } from '@apollo/client/link/subscriptions' import { setContext } from '@apollo/client/link/context' +import type { ClientConfig, ErrorResponse } from '../types' import createRestartableClient from './ws' import { useApollo } from './composables' import { ref, useCookie, defineNuxtPlugin, useRequestHeaders } from '#imports' +import type { Ref } from '#imports' import { NuxtApollo } from '#apollo' import type { ApolloClientKeys } from '#apollo' @@ -18,7 +20,7 @@ export default defineNuxtPlugin((nuxtApp) => { const clients = {} as Record> - for (const [key, clientConfig] of Object.entries(NuxtApollo.clients)) { + for (const [key, clientConfig] of Object.entries(NuxtApollo.clients) as [ApolloClientKeys, ClientConfig][]) { const getAuth = async () => { const token = ref(null) @@ -155,6 +157,11 @@ export default defineNuxtPlugin((nuxtApp) => { } }) +export interface ModuleRuntimeHooks { + 'apollo:auth': (params: { client: ApolloClientKeys, token: Ref }) => void + 'apollo:error': (error: ErrorResponse) => void +} + interface DollarApolloHelpers extends ReturnType {} interface DollarApollo { clients: Record> @@ -162,6 +169,7 @@ interface DollarApollo { } declare module '#app' { + interface RuntimeNuxtHooks extends ModuleRuntimeHooks {} interface NuxtApp { $apolloHelpers: DollarApolloHelpers $apollo: DollarApollo