### Install @shellicar/build-graphql Source: https://github.com/shellicar/build-graphql/blob/main/README.md Commands to install the package as a dependency or dev dependency using npm or pnpm. ```bash npm i --save @shellicar/build-graphql pnpm add @shellicar/build-graphql pnpm add -D @shellicar/build-graphql ``` -------------------------------- ### Implement Apollo Server with Modular Schemas Source: https://context7.com/shellicar/build-graphql/llms.txt This example shows the server-side implementation of an Apollo Server using TypeScript. It defines resolvers for user management and integrates consolidated type definitions provided by the build-graphql plugin. ```typescript import { ApolloServer } from '@apollo/server'; import { startStandaloneServer } from '@apollo/server/standalone'; import typedefs from '@shellicar/build-graphql/typedefs'; interface User { id: string; name: string; email: string; } const users: User[] = []; const resolvers = { Query: { users: () => users, user: (_: unknown, { id }: { id: string }) => users.find(u => u.id === id), }, Mutation: { createUser: (_: unknown, { name, email }: { name: string; email: string }) => { const user = { id: String(users.length + 1), name, email }; users.push(user); return user; }, deleteUser: (_: unknown, { id }: { id: string }) => { const index = users.findIndex(u => u.id === id); if (index > -1) { users.splice(index, 1); return true; } return false; }, }, }; const server = new ApolloServer({ typeDefs: typedefs, resolvers, }); const { url } = await startStandaloneServer(server, { listen: { port: 4000 }, }); console.log(`Server ready at: ${url}`); ``` -------------------------------- ### Install @shellicar/build-graphql Source: https://context7.com/shellicar/build-graphql/llms.txt Installs the @shellicar/build-graphql package as a development dependency using npm or pnpm. ```bash # Using npm npm install --save-dev @shellicar/build-graphql # Using pnpm pnpm add -D @shellicar/build-graphql ``` -------------------------------- ### Install @shellicar/build-graphql using npm or pnpm Source: https://github.com/shellicar/build-graphql/blob/main/packages/build-graphql/README.md Installs the @shellicar/build-graphql package using either npm or pnpm package managers. This is the first step to integrate the plugin into your project. ```shell npm i --save @shellicar/build-graphql ``` ```shell pnpm add @shellicar/build-graphql ``` -------------------------------- ### Configure tsup with esbuild for GraphQL Source: https://context7.com/shellicar/build-graphql/llms.txt Configures tsup to use the @shellicar/build-graphql esbuild plugin for bundling TypeScript projects. This setup specifies entry points, output directory, format, bundling options, and includes the GraphQL esbuild plugin. ```typescript // tsup.config.ts import graphqlPlugin from '@shellicar/build-graphql/esbuild'; import type { Options } from '@shellicar/build-graphql/types'; import { defineConfig } from 'tsup'; const options: Options = { globPattern: 'src/**/*.graphql', debug: true, }; export default defineConfig({ entry: ['src/main.ts'], outDir: 'dist', format: ['esm'], bundle: true, esbuildPlugins: [graphqlPlugin(options)], }); ``` -------------------------------- ### Configure Vite Plugin for GraphQL Source: https://context7.com/shellicar/build-graphql/llms.txt Configures the Vite plugin for @shellicar/build-graphql to load GraphQL files. It specifies a glob pattern for file discovery and enables debug mode. This setup ensures GraphQL schemas are available in Vite projects with watch mode and HMR. ```typescript // vite.config.ts import type { Options } from '@shellicar/build-graphql/types'; import GraphQLPlugin from '@shellicar/build-graphql/vite'; import { defineConfig } from 'vite'; const options: Options = { globPattern: 'src/**/*.graphql', debug: true, }; export default defineConfig({ plugins: [GraphQLPlugin(options)], }); ``` -------------------------------- ### Configure Error Handling Policy with Vite Plugin Source: https://context7.com/shellicar/build-graphql/llms.txt Demonstrates how to configure the error handling policy for the '@shellicar/build-graphql/vite' plugin using the ErrorPolicy enum. It shows examples for 'Abort' (default), 'Report', and 'Ignore' policies, illustrating how each affects build continuation upon encountering errors. ```typescript import { ErrorPolicy } from '@shellicar/build-graphql'; import graphqlPlugin from '@shellicar/build-graphql/vite'; // Abort: Throw an error and stop the build (default) graphqlPlugin({ globPattern: 'src/**/*.graphql', errorPolicy: ErrorPolicy.Abort, }); // Report: Log errors but continue the build graphqlPlugin({ globPattern: 'src/**/*.graphql', errorPolicy: ErrorPolicy.Report, }); // Ignore: Silently ignore all errors graphqlPlugin({ globPattern: 'src/**/*.graphql', errorPolicy: ErrorPolicy.Ignore, }); ``` -------------------------------- ### Handle Plugin Error Classes with TypeScript Source: https://context7.com/shellicar/build-graphql/llms.txt Provides an example of how to catch and handle specific error classes exported by '@shellicar/build-graphql'. It demonstrates using 'instanceof' checks to differentiate between various error types like 'GraphQLLoadNoFilesError', 'GraphQLLoadPartialImportError', 'GraphQLLoadTypedefsMissingError', and 'InvalidFeatureCombinationError'. ```typescript import { GraphQLLoadError, GraphQLLoadNoFilesError, GraphQLLoadPartialImportError, GraphQLLoadTypedefsMissingError, InvalidFeatureCombinationError, } from '@shellicar/build-graphql'; try { // Build process } catch (error) { if (error instanceof GraphQLLoadNoFilesError) { console.error(`No GraphQL files found for pattern: ${error.pattern}`); } else if (error instanceof GraphQLLoadPartialImportError) { console.error('Not all GraphQL files were imported'); } else if (error instanceof GraphQLLoadTypedefsMissingError) { console.error('Typedefs virtual module was not imported'); } else if (error instanceof InvalidFeatureCombinationError) { console.error('Invalid feature combination in options'); } } ``` -------------------------------- ### Configure Plugin Features with Vite Plugin Source: https://context7.com/shellicar/build-graphql/llms.txt Shows how to enable or disable specific plugin features, such as watch mode and HMR, using the Feature enum with the '@shellicar/build-graphql/vite' plugin. Examples include disabling all watch features and selectively enabling Vite watch while disabling HMR. ```typescript import { Feature } from '@shellicar/build-graphql'; import graphqlPlugin from '@shellicar/build-graphql/vite'; // Disable all watch features for production builds graphqlPlugin({ globPattern: 'src/**/*.graphql', features: { [Feature.EsbuildWatch]: false, [Feature.ViteWatch]: false, [Feature.ViteHmr]: false, }, }); // Enable Vite watch but disable HMR graphqlPlugin({ globPattern: 'src/**/*.graphql', features: { [Feature.ViteWatch]: true, [Feature.ViteHmr]: false, }, }); ``` -------------------------------- ### Configure GraphQL Plugin for Vite Source: https://github.com/shellicar/build-graphql/blob/main/README.md Integrate the GraphQL plugin into a Vite configuration file using the vite entry point. ```typescript import { defineConfig } from 'vite'; import GraphQLPlugin from '@shellicar/build-graphql/vite'; export default defineConfig({ plugins: [ GraphQLPlugin({ globPattern: 'src/**/*.graphql' }) ], }); ``` -------------------------------- ### Options Interface Configuration Source: https://context7.com/shellicar/build-graphql/llms.txt Details the `Options` interface, which defines all configurable properties for the @shellicar/build-graphql plugin, including glob patterns, comparison functions, error policies, and feature flags. ```APIDOC ## Options Interface The Options interface defines all configuration properties for the plugin. ```typescript import type { Options } from '@shellicar/build-graphql/types'; import { ErrorPolicy, Feature } from '@shellicar/build-graphql'; import type { DocumentNode } from 'graphql'; const options: Options = { // Glob pattern to search for GraphQL files // Default: '**/*.graphql' globPattern: 'src/**/*.graphql', // Glob ignore pattern (deprecated, use globOptions.ignore) // Default: '**/node_modules/**' globIgnore: ['**/node_modules/**', '**/dist/**'], // Glob options passed directly to the glob library globOptions: { ignore: ['**/node_modules/**', '**/dist/**'], cwd: process.cwd(), }, // Compare function for sorting files // Default: localeCompare compareFn: (a, b) => a.localeCompare(b), // Error handling policy // Default: ErrorPolicy.Abort errorPolicy: ErrorPolicy.Report, // Enable debug logging // Default: false debug: true, // Feature flags for watch modes features: { [Feature.EsbuildWatch]: true, // esbuild watch mode (default: true) [Feature.ViteWatch]: true, // Vite watch mode (default: true) [Feature.ViteHmr]: true, // Vite HMR support (default: true) }, // Custom document node transformer mapDocumentNode: (doc: DocumentNode) => { // Transform or modify the parsed DocumentNode return doc; }, }; ``` ``` -------------------------------- ### Configure esbuild Plugin for GraphQL Source: https://context7.com/shellicar/build-graphql/llms.txt Sets up the esbuild plugin for @shellicar/build-graphql to bundle GraphQL files. This configuration includes entry points, output directory, bundling options, and the GraphQL plugin itself. It also demonstrates how to enable watch mode for automatic rebuilds. ```typescript // build.ts import graphqlPlugin from '@shellicar/build-graphql/esbuild'; import type { Options } from '@shellicar/build-graphql/types'; import esbuild from 'esbuild'; const options: Options = { globPattern: 'src/**/*.graphql', debug: true, }; const ctx = await esbuild.context({ entryPoints: ['src/main.ts'], outdir: 'dist', bundle: true, platform: 'node', target: 'node20', format: 'esm', plugins: [graphqlPlugin(options)], }); // For watch mode await ctx.watch(); console.log('watching...'); // For single build // await ctx.rebuild(); // ctx.dispose(); ``` -------------------------------- ### Import GraphQL Typedefs Source: https://github.com/shellicar/build-graphql/blob/main/README.md Import the virtual module containing GraphQL type definitions into your application code. ```typescript import typedefs from '@shellicar/build-graphql/typedefs'; ``` -------------------------------- ### Importing GraphQL Typedefs Source: https://context7.com/shellicar/build-graphql/llms.txt This section explains how to import all GraphQL documents as a single array of DocumentNode objects using the virtual module provided by the package. ```APIDOC ## Importing GraphQL Typedefs Import all GraphQL documents as a single array using the virtual module, which returns an array of GraphQL DocumentNode objects. ```typescript // main.ts import typedefs from '@shellicar/build-graphql/typedefs'; import { buildSchema, print } from 'graphql'; // typedefs is an array of DocumentNode objects console.log(`Loaded ${typedefs.length} GraphQL documents`); // Use with GraphQL server import { ApolloServer } from '@apollo/server'; const server = new ApolloServer({ typeDefs: typedefs, resolvers: { Query: { hello: () => 'world', }, }, }); ``` ``` -------------------------------- ### Configure GraphQL Plugin for esbuild Source: https://github.com/shellicar/build-graphql/blob/main/README.md Integrate the GraphQL plugin into an esbuild build script. It accepts a glob pattern to locate GraphQL files. ```typescript import graphqlPlugin from '@shellicar/build-graphql/esbuild'; import type { Options } from '@shellicar/build-graphql/types'; import { build } from 'esbuild'; const options: Options = { globPattern: '../**/*.graphql', debug: true, }; await build({ entryPoints: ['src/main.ts'], outdir: 'dist', bundle: true, platform: 'node', target: 'node20', tsconfig: 'tsconfig.json', plugins: [graphqlPlugin(options)], }); ``` -------------------------------- ### Import GraphQL Typedefs with TypeScript Source: https://context7.com/shellicar/build-graphql/llms.txt Demonstrates how to import all GraphQL documents as a single array of DocumentNode objects using the virtual module provided by '@shellicar/build-graphql'. This array can then be used to build a GraphQL schema or integrate with GraphQL servers like Apollo Server. ```typescript // main.ts import typedefs from '@shellicar/build-graphql/typedefs'; import { buildSchema, print } from 'graphql'; // typedefs is an array of DocumentNode objects console.log(`Loaded ${typedefs.length} GraphQL documents`); // Use with GraphQL server import { ApolloServer } from '@apollo/server'; const server = new ApolloServer({ typeDefs: typedefs, resolvers: { Query: { hello: () => 'world', }, }, }); ``` -------------------------------- ### Integrate GraphQLPlugin with esbuild Source: https://github.com/shellicar/build-graphql/blob/main/packages/build-graphql/README.md Demonstrates how to integrate the GraphQLPlugin into an esbuild build process. It configures the plugin to load GraphQL files matching a specified glob pattern. ```typescript // build.ts import GraphQLPlugin from '@shellicar/build-graphql/esbuild' await build({ // other options plugins: [ GraphQLPlugin({ globPattern: 'src/**/*.graphql' }) ] }) ``` -------------------------------- ### Configure Plugin Options Interface with TypeScript Source: https://context7.com/shellicar/build-graphql/llms.txt Illustrates the use of the Options interface to configure the '@shellicar/build-graphql' plugin. It shows how to set glob patterns for finding GraphQL files, ignore patterns, glob options, custom comparison functions, error policies, debug logging, feature flags for watch modes, and a custom document node transformer. ```typescript import type { Options } from '@shellicar/build-graphql/types'; import { ErrorPolicy, Feature } from '@shellicar/build-graphql'; import type { DocumentNode } from 'graphql'; const options: Options = { // Glob pattern to search for GraphQL files // Default: '**/*.graphql' globPattern: 'src/**/*.graphql', // Glob ignore pattern (deprecated, use globOptions.ignore) // Default: '**/node_modules/**' globIgnore: ['**/node_modules/**', '**/dist/**'], // Glob options passed directly to the glob library globOptions: { ignore: ['**/node_modules/**', '**/*.test.graphql'], cwd: process.cwd(), }, // Compare function for sorting files // Default: localeCompare compareFn: (a, b) => a.localeCompare(b), // Error handling policy // Default: ErrorPolicy.Abort errorPolicy: ErrorPolicy.Report, // Enable debug logging // Default: false debug: true, // Feature flags for watch modes features: { [Feature.EsbuildWatch]: true, // esbuild watch mode (default: true) [Feature.ViteWatch]: true, // Vite watch mode (default: true) [Feature.ViteHmr]: true, // Vite HMR support (default: true) }, // Custom document node transformer mapDocumentNode: (doc: DocumentNode) => { // Transform or modify the parsed DocumentNode return doc; }, }; ``` -------------------------------- ### Configure Farm Plugin for GraphQL Source: https://context7.com/shellicar/build-graphql/llms.txt Adds the @shellicar/build-graphql Farm plugin to a Farm-based project configuration. This enables the Farm build system to load and process GraphQL files according to the specified glob pattern. ```javascript // farm.config.ts import graphqlPlugin from '@shellicar/build-graphql/farm'; import { defineConfig } from '@farmfe/core'; export default defineConfig({ plugins: [ graphqlPlugin({ globPattern: 'src/**/*.graphql', }), ], }); ``` -------------------------------- ### Configure Astro Integration for GraphQL Source: https://context7.com/shellicar/build-graphql/llms.txt Integrates the @shellicar/build-graphql Astro integration, which utilizes the Vite plugin, into an Astro project. This allows Astro to process GraphQL files using a specified glob pattern. ```typescript // astro.config.mjs import graphqlPlugin from '@shellicar/build-graphql/astro'; import { defineConfig } from 'astro/config'; export default defineConfig({ integrations: [ graphqlPlugin({ globPattern: 'src/**/*.graphql', }), ], }); ``` -------------------------------- ### Integrate GraphQLPlugin with Vite Source: https://github.com/shellicar/build-graphql/blob/main/packages/build-graphql/README.md Shows how to integrate the GraphQLPlugin into a Vite configuration. The plugin is added to the Vite build process to handle GraphQL files based on a glob pattern. ```typescript // vite.config.ts import GraphQLPlugin from '@shellicar/build-graphql/vite' export default defineConfig({ // other options plugins: [ GraphQLPlugin({ globPattern: 'src/**/*.graphql' }) ], }); ``` -------------------------------- ### Configure Webpack Plugin for GraphQL Source: https://context7.com/shellicar/build-graphql/llms.txt Integrates the @shellicar/build-graphql Webpack plugin into a Webpack configuration. This allows Webpack to process and load GraphQL files according to the specified glob pattern. ```javascript // webpack.config.js const GraphQLPlugin = require('@shellicar/build-graphql/webpack').default; module.exports = { plugins: [ GraphQLPlugin({ globPattern: 'src/**/*.graphql', }), ], }; ``` -------------------------------- ### Configure Rspack Plugin for GraphQL Source: https://context7.com/shellicar/build-graphql/llms.txt Integrates the @shellicar/build-graphql Rspack plugin into a Rspack configuration. This enables Rspack to load and process GraphQL files based on the provided glob pattern. ```javascript // rspack.config.js const GraphQLPlugin = require('@shellicar/build-graphql/rspack').default; module.exports = { plugins: [ GraphQLPlugin({ globPattern: 'src/**/*.graphql', }), ], }; ``` -------------------------------- ### Error Classes for Exception Handling Source: https://context7.com/shellicar/build-graphql/llms.txt Details the specific error classes exported by the plugin, which can be used for robust error handling during the GraphQL build process. ```APIDOC ## Error Classes The plugin exports specific error classes for handling different failure scenarios. ```typescript import { GraphQLLoadError, GraphQLLoadNoFilesError, GraphQLLoadPartialImportError, GraphQLLoadTypedefsMissingError, InvalidFeatureCombinationError, } from '@shellicar/build-graphql'; try { // Build process } catch (error) { if (error instanceof GraphQLLoadNoFilesError) { console.error(`No GraphQL files found for pattern: ${error.pattern}`); } else if (error instanceof GraphQLLoadPartialImportError) { console.error('Not all GraphQL files were imported'); } else if (error instanceof GraphQLLoadTypedefsMissingError) { console.error('Typedefs virtual module was not imported'); } else if (error instanceof InvalidFeatureCombinationError) { console.error('Invalid feature combination in options'); } } ``` ``` -------------------------------- ### Import GraphQL typedefs Source: https://github.com/shellicar/build-graphql/blob/main/packages/build-graphql/README.md Provides a utility to import GraphQL typedefs directly. This is useful for accessing GraphQL schema definitions within your application code. ```typescript // main.ts import typedefs from '@shellicar/build-graphql/typedefs' ``` -------------------------------- ### Configure Rollup Plugin for GraphQL Source: https://context7.com/shellicar/build-graphql/llms.txt Adds the @shellicar/build-graphql Rollup plugin to a Rollup build configuration. This enables Rollup to handle GraphQL file imports, specifying the input file, output format, and the plugin with its options. ```javascript // rollup.config.js import graphqlPlugin from '@shellicar/build-graphql/rollup'; export default { input: 'src/main.js', output: { file: 'dist/bundle.js', format: 'esm', }, plugins: [ graphqlPlugin({ globPattern: 'src/**/*.graphql', }), ], }; ``` -------------------------------- ### Configure Nuxt Module for GraphQL Source: https://context7.com/shellicar/build-graphql/llms.txt Adds the @shellicar/build-graphql Nuxt module to a Nuxt 4 application. This automatically configures the underlying Vite or Webpack plugins to handle GraphQL files, with options for glob pattern and debug mode. ```typescript // nuxt.config.ts export default defineNuxtConfig({ modules: ['@shellicar/build-graphql/nuxt'], buildGraphql: { globPattern: 'graphql/**/*.graphql', debug: true, }, }); ``` -------------------------------- ### Feature Enum Usage Source: https://context7.com/shellicar/build-graphql/llms.txt Illustrates how to use the `Feature` enum to enable or disable specific plugin features, such as esbuild watch, Vite watch, and Vite HMR. ```APIDOC ## Feature Enum The Feature enum allows enabling or disabling specific plugin features like watch mode and HMR. ```typescript import { Feature } from '@shellicar/build-graphql'; import graphqlPlugin from '@shellicar/build-graphql/vite'; // Disable all watch features for production builds graphqlPlugin({ globPattern: 'src/**/*.graphql', features: { [Feature.EsbuildWatch]: false, [Feature.ViteWatch]: false, [Feature.ViteHmr]: false, }, }); // Enable Vite watch but disable HMR graphqlPlugin({ globPattern: 'src/**/*.graphql', features: { [Feature.ViteWatch]: true, [Feature.ViteHmr]: false, }, }); ``` ``` -------------------------------- ### ErrorPolicy Enum Usage Source: https://context7.com/shellicar/build-graphql/llms.txt Demonstrates how to use the `ErrorPolicy` enum to control the plugin's behavior when encountering errors during the build process. ```APIDOC ## ErrorPolicy Enum The ErrorPolicy enum controls how the plugin handles errors during the build process. ```typescript import { ErrorPolicy } from '@shellicar/build-graphql'; import graphqlPlugin from '@shellicar/build-graphql/vite'; // Abort: Throw an error and stop the build (default) graphqlPlugin({ globPattern: 'src/**/*.graphql', errorPolicy: ErrorPolicy.Abort, }); // Report: Log errors but continue the build graphqlPlugin({ globPattern: 'src/**/*.graphql', errorPolicy: ErrorPolicy.Report, }); // Ignore: Silently ignore all errors graphqlPlugin({ globPattern: 'src/**/*.graphql', errorPolicy: ErrorPolicy.Ignore, }); ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.