Diizzayy / nuxt-graphql-client

⚡️ Minimal GraphQL Client + Code Generation for Nuxt3
https://nuxt-graphql-client.web.app
MIT License
366 stars 43 forks source link

Types broken inside api routes #401

Open madebyfabian opened 1 year ago

madebyfabian commented 1 year ago

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
    }
    })
  2. 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_
iBobik commented 7 months ago

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?