Skip to content

Commit

Permalink
improve types
Browse files Browse the repository at this point in the history
  • Loading branch information
Diizzayy committed Mar 1, 2024
1 parent 56de988 commit 8e5eed7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
10 changes: 0 additions & 10 deletions src/module.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -198,11 +197,6 @@ export default defineNuxtModule<ModuleOptions>({

export const defineApolloClient = (config: ClientConfig) => config

export interface ModuleRuntimeHooks {
'apollo:auth': (params: { client: string, token: Ref<string | null> }) => void
'apollo:error': (error: ErrorResponse) => void
}

export interface ModuleRuntimeConfig {
apollo: NuxtApolloConfig<any>
}
Expand All @@ -211,10 +205,6 @@ export interface ModulePublicRuntimeConfig {
apollo: NuxtApolloConfig<any>
}

declare module '#app' {
interface RuntimeNuxtHooks extends ModuleRuntimeHooks {}
}

declare module '@nuxt/schema' {
interface NuxtConfig { ['apollo']?: Partial<ModuleOptions> }
interface NuxtOptions { ['apollo']?: ModuleOptions }
Expand Down
10 changes: 9 additions & 1 deletion src/runtime/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -18,7 +20,7 @@ export default defineNuxtPlugin((nuxtApp) => {

const clients = {} as Record<ApolloClientKeys, ApolloClient<any>>

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<string | null>(null)

Expand Down Expand Up @@ -155,13 +157,19 @@ export default defineNuxtPlugin((nuxtApp) => {
}
})

export interface ModuleRuntimeHooks {
'apollo:auth': (params: { client: ApolloClientKeys, token: Ref<string | null> }) => void
'apollo:error': (error: ErrorResponse) => void
}

interface DollarApolloHelpers extends ReturnType<typeof useApollo> {}
interface DollarApollo {
clients: Record<ApolloClientKeys, ApolloClient<any>>
defaultClient: ApolloClient<any>
}

declare module '#app' {
interface RuntimeNuxtHooks extends ModuleRuntimeHooks {}
interface NuxtApp {
$apolloHelpers: DollarApolloHelpers
$apollo: DollarApollo
Expand Down

0 comments on commit 8e5eed7

Please sign in to comment.