dulnan / nuxt-graphql-middleware

GraphQL in the backend, fetch in the frontend. With TypeScript support.
https://nuxt-graphql-middleware.dulnan.net
MIT License
56 stars 11 forks source link

Support for static site generation (SSG) #43

Closed lewebsimple closed 2 weeks ago

lewebsimple commented 2 weeks ago

I'm trying to use nuxt-graphql-middleware with SSG and it seems to query /api/graphql_middleware/... from the client side which crashes the app.

Is there a work-around or something I'm missing to pre-render the routes ?

dulnan commented 2 weeks ago

When you use useGraphqlQuery directly in the setup of your page component Nuxt will not be able to generate a payload. Then when running the SSG app it will actually try to make a call to the middleware. However if you wrap it in useAsyncData, then Nuxt should be able to generate the payload which also works with SSG. The module also simplifies this with the useAsyncGraphqlQuery composable, which basically wraps useAsyncData + useGraphqlQuery.

lewebsimple commented 2 weeks ago

Duh it was right there in the documentation ... thanks for the quick reply!