nuxt-graphql-client is a comprehensive Nuxt 3 module designed to integrate GraphQL client capabilities with built-in code generation. Currently at version 0.2.46, the package sees frequent patch releases, indicating active development and responsiveness to bug fixes and minor feature enhancements. It leverages `graphql-request` for executing GraphQL operations and `graphql-code-generator` to automatically generate TypeScript types and composables (`useGql`, `useAsyncGql`, `Gql<OperationName>`) directly from your GraphQL schema and `.gql` files. This approach ensures full TypeScript support and Hot Module Reload (HMR) for GraphQL documents. Its key differentiators include a 'zero configuration' option for rapid setup, deep integration with the Nuxt 3 reactivity system and composables, and streamlined developer experience by automating boilerplate for GraphQL interactions, providing a modern alternative to more manually configured GraphQL client setups in Nuxt applications.
npm install nuxt-graphql-clientVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to configure the module, define a simple GraphQL query in a `.gql` file, and fetch data using the `useAsyncGql` composable within a Nuxt page, complete with loading and error states.
Consult the GitHub releases page and documentation for detailed migration guides between minor versions.
Configure `tokenStorage.mode` to `'cookie'` in `nuxt.config.ts` for SSR compatibility.
Access Nuxt composables before the `gql:auth:init` hook is invoked, or ensure they are called in a context where the Nuxt instance is guaranteed to be available (e.g., top-level `<script setup>` in a component or directly within a plugin's `setup` function before `await`).
Inspect the conflicting types and either refactor your GraphQL schemas to avoid naming collisions or use schema stitching/transformation tools outside of `nuxt-graphql-client` to reconcile the schemas before feeding them to the module.
Ensure that if multiple GraphQL schemas are being consumed, there are no naming conflicts for types or fields, or consider isolating clients to distinct type generation outputs.
Refactor your authentication plugin to ensure Nuxt composables are accessed before any `await` statements or before the `gql:auth:init` hook is executed.
Set the `NUXT_PUBLIC_GQL_HOST` environment variable or configure `runtimeConfig.public.graphqlClient.clients.default.host` in your `nuxt.config.ts` file.
Verify that your GraphQL API endpoint is correctly configured and returning valid JSON responses, especially for errors. Inspect the network response in developer tools to see the actual content returned by the server.