nuxt-graphql-client icon indicating copy to clipboard operation
nuxt-graphql-client copied to clipboard

Types broken inside api routes

Open madebyfabian opened this issue 2 years ago • 1 comments
trafficstars

Environment

Describe the bug

I want to use a graphql operation server-side.

  1. This works, but is not typed:
export default defineEventHandler(async event => {
	const data = await GqlSendContactFormRequest() 

	return {
		data, // -> any
	}
})
  1. 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'
// ...
  1. 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

madebyfabian avatar Oct 09 '23 13:10 madebyfabian

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?

iBobik avatar Apr 17 '24 15:04 iBobik