nuxt-graphql-client
nuxt-graphql-client copied to clipboard
Types broken inside api routes
trafficstars
Environment
- Operating System: Darwin
- Node Version: v18.16.1
- Nuxt Version: 3.7.4
- CLI Version: 3.9.0
- Nitro Version: 2.6.3
- Package Manager: [email protected]
- Builder: -
- User Config: devtools, experimental, typescript, vite, app, modules, image, graphql-client, site
- Runtime Modules: @nuxtjs/[email protected], [email protected], @nuxt/[email protected], [email protected], @nuxtseo/[email protected]
- Build Modules: -
Describe the bug
I want to use a graphql operation server-side.
- This works, but is not typed:
export default defineEventHandler(async event => {
const data = await GqlSendContactFormRequest()
return {
data, // -> any
}
})
- I tried to import it like this. Now types work, But this breaks the runtime. Since I am importing types as a const.
import { GqlSendContactFormRequest } from '#gql'
// ...
- The hacky way: Types & Runtime works, but I don't think it should be like this.
import type { GqlSendContactFormRequest as RequestT } from '#gql'
export default defineEventHandler(async event => {
const data = (await GqlSendContactFormRequest()) as typeof RequestT
return {
data, // -> Correct type
}
})
Are these methods not intended to use server-side? I think some of the latest nuxt releases might broke this module, since server typed are handled seperately in a server/tsconfig.json now.
Expected behaviour
I expect the operation methods to work without having to manually type them
Reproduction
No response
Additional context
No response
Logs
No response
Another possible workaround is to import return type:
import type { ListOrderPacketsInTransportQuery } from '#gql'
export default defineTask({
async run({ payload, context }) {
const { orderItems }: ListOrderPacketsInTransportQuery = await GqlListOrderPacketsInTransport()
I remember it worked in a past too. Considering many other server-side related issues it seems @Diizzayy does not use GraphQL server-side in his projects. ;-) Anything we can do for you to help you with server-side features and bugs?