$ show nuxt-modules/apollo
This is a Nuxt 3 module that integrates Apollo GraphQL client into Nuxt applications. It provides a flexible configuration system for defining multiple Apollo clients with HTTP and WebSocket endpoints, authentication token management, and SSR support. The module auto-imports composables like useAsyncQuery, useQuery, useMutation, and useSubscription, and provides hooks for custom authentication and error handling. It also supports hot module replacement for Apollo client configuration files. The architecture uses Nuxt's module system (defineNuxtModule) to hook into the build process. It reads client configurations from nuxt.config or external files, generates runtime templates, and sets up a Nuxt plugin that creates ApolloClient instances with appropriate links (HTTP, WebSocket, auth, error). The composables layer provides SSR-friendly async query wrappers and authentication helpers. WebSocket support includes a restartable client for reconnection. Key entry points are src/module.ts (module setup), src/runtime/plugin.ts (client creation and plugin), and src/runtime/composables.ts (user-facing composables). External dependencies include @apollo/client, @vue/apollo-composable, graphql-ws, and @nuxt/kit.
The LLM identified 2 files worth highlighting for reuse:
Provides a factory function to create a restartable WebSocket client by wrapping graphql-ws's createClient. It adds a restart() method that closes the current socket and triggers reconnection. The implementation handles edge cases where restart is requested before the socket is opened. This component is self-contained and can be reused in any WebSocket project requiring manual reconnection control.
A utility function that serializes JavaScript objects to string representations while preserving function expressions. It recursively handles objects, arrays, primitives, and functions (using toString()). This is useful for generating code from configuration objects, e.g., for template generation in build tools. The component is isolated and can be extracted for use in other projects needing similar serialization.