nuxt-modules / apollo

Nuxt.js module to use Vue-Apollo. The Apollo integration for GraphQL.
https://apollo.nuxtjs.org
MIT License
929 stars 194 forks source link

Argument of type '"apollo:error"' is not assignable to parameter of type 'HookKeys<RuntimeNuxtHooks>' #558

Closed martinszeltins closed 7 months ago

martinszeltins commented 8 months ago

Environment

------------------------------
- Operating System: Linux (Docker)
- Node Version:     v20.8.1
- Nuxt Version:     3.7.3
- CLI Version:      3.8.4
- Nitro Version:    2.6.3
- Package Manager:  pnpm@8.9.2
- Builder:          -
- User Config:      ssr, runtimeConfig, modules, app, routeRules, alias, serverDir, dir, components, imports, typescript, experimental, css, build, devtools, vite, tailwindcss, postcss, apollo, i18n
- Runtime Modules:  @vueuse/nuxt@10.4.0, @nuxtjs/apollo@5.0.0-alpha.6, @nuxtjs/tailwindcss@6.8.0, @nuxtjs/i18n@8.0.0-rc.4-28257783.3664302, nuxt-radash@1.0.0, @pinia/nuxt@0.4.11, @pinia-plugin-persistedstate/nuxt@1.1.1
- Build Modules:    -
------------------------------

Describe the bug

I wanted to use the Error Hook as described in the docs but I does not seem work and I am getting this error:

Argument of type '"apollo:error"' is not assignable to parameter of type 'HookKeys<RuntimeNuxtHooks>'.
 FILE  /var/www/common/plugins/apolloErrorHandler.ts:4:18

    2 |
    3 | export default defineNuxtPlugin(nuxtApp => {
  > 4 |     nuxtApp.hook('apollo:error', (error: ErrorResponse) => {
      |                  ^^^^^^^^^^^^^^
    5 |         console.log('Hello from apollo:error hook! This is the Apollo Error Handler Plugin!')
    6 |         console.log('The error was:')
    7 |         console.log(error)

All I did was add plugins/apolloErrorHandler.ts with this content:

import { ErrorResponse } from '@nuxtjs/apollo'

export default defineNuxtPlugin(nuxtApp => {
    nuxtApp.hook('apollo:error', (error: ErrorResponse) => {
        console.log('Hello from apollo:error hook! This is the Apollo Error Handler Plugin!')
        console.log('The error was:')
        console.log(error)
    })
})

Note: Everything else in Nuxt Apollo seems to be working fine except for this Error Hook.

Expected behaviour

I expected it to work as described in the docs

Reproduction

No response

Additional context

No response

Logs

No response