Skip to content

Commit 3b718a2

Browse files
feat: add full file generation control and custom path system (#43)
* feat: add full file generation control and custom path system Add comprehensive control over auto-generated files with custom path support. Perfect for library development, monorepos, and custom project structures. Features: - Fine-grained control for each generated file (scaffold, SDK, types, client utils) - Custom path support with placeholder system - Service-specific path overrides for external services - Path resolution priority system - Global path overrides for project-wide customization New Config Options: - scaffold: Control graphql.config.ts, schema.ts, config.ts, context.ts - clientUtils: Control index.ts and ofetch.ts generation (Nuxt only) - sdk: Control main and external SDK generation - types: Control server, client, and external type generation - paths: Global path overrides (serverGraphql, clientGraphql, buildDir, typesDir) Service-Specific Paths: - Each externalService can now define custom paths - Overrides global config with service.paths.{sdk,types,ofetch} - Priority: service.paths > category config > global paths > defaults Path Placeholders: - {serviceName}, {buildDir}, {rootDir}, {framework} - {typesDir}, {serverGraphql}, {clientGraphql} New Files: - src/utils/path-resolver.ts - Path resolution and placeholder system - src/utils/file-generator.ts - File generation utilities Updated Files: - src/types/index.ts - New config types and interfaces - src/index.ts - Scaffold file generation with config control - src/utils/type-generation.ts - SDK, types, client utils with config control - README.md - Comprehensive documentation with examples Use Cases: - Library mode: scaffold: false, clientUtils: false - Monorepo: Custom paths for packages - Organization: Service-specific paths for external services 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * chore: lint --------- Co-authored-by: Claude <[email protected]>
1 parent 2494ccf commit 3b718a2

File tree

6 files changed

+981
-59
lines changed

6 files changed

+981
-59
lines changed

README.md

Lines changed: 240 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,246 @@ query {
210210

211211
## 🚀 Advanced Features
212212

213+
<details>
214+
<summary><strong>🎛️ Custom File Generation & Paths</strong></summary>
215+
216+
Control which files are auto-generated and customize their output paths. Perfect for library development, monorepos, or custom project structures.
217+
218+
### Library Mode
219+
220+
Disable all scaffold files for library/module development:
221+
222+
```ts
223+
// nitro.config.ts
224+
export default defineNitroConfig({
225+
graphql: {
226+
framework: 'graphql-yoga',
227+
scaffold: false, // Disable all scaffold files
228+
clientUtils: false, // Disable client utilities
229+
}
230+
})
231+
```
232+
233+
### Fine-Grained Control
234+
235+
Control each file individually:
236+
237+
```ts
238+
export default defineNitroConfig({
239+
graphql: {
240+
framework: 'graphql-yoga',
241+
242+
// Scaffold files
243+
scaffold: {
244+
graphqlConfig: false, // Don't generate graphql.config.ts
245+
serverSchema: true, // Generate server/graphql/schema.ts
246+
serverConfig: true, // Generate server/graphql/config.ts
247+
serverContext: false, // Don't generate server/graphql/context.ts
248+
},
249+
250+
// Client utilities (Nuxt only)
251+
clientUtils: {
252+
index: true, // Generate app/graphql/index.ts
253+
ofetch: false, // Don't generate ofetch wrappers
254+
},
255+
256+
// SDK files
257+
sdk: {
258+
main: true, // Generate default SDK
259+
external: true, // Generate external service SDKs
260+
},
261+
262+
// Type files
263+
types: {
264+
server: true, // Generate server types
265+
client: true, // Generate client types
266+
external: true, // Generate external service types
267+
}
268+
}
269+
})
270+
```
271+
272+
### Custom Paths
273+
274+
Customize where files are generated:
275+
276+
```ts
277+
export default defineNitroConfig({
278+
graphql: {
279+
framework: 'graphql-yoga',
280+
281+
// Method 1: Global paths (affects all files)
282+
paths: {
283+
serverGraphql: 'src/server/graphql',
284+
clientGraphql: 'src/client/graphql',
285+
buildDir: '.build',
286+
typesDir: '.build/types',
287+
},
288+
289+
// Method 2: Specific file paths
290+
scaffold: {
291+
serverSchema: 'lib/graphql/schema.ts',
292+
serverConfig: 'lib/graphql/config.ts',
293+
},
294+
295+
sdk: {
296+
main: 'app/graphql/organization/sdk.ts',
297+
external: 'app/graphql/{serviceName}/client-sdk.ts',
298+
},
299+
300+
types: {
301+
server: 'types/graphql-server.d.ts',
302+
client: 'types/graphql-client.d.ts',
303+
}
304+
}
305+
})
306+
```
307+
308+
### Path Placeholders
309+
310+
Use placeholders in custom paths:
311+
312+
| Placeholder | Description | Example |
313+
|------------|-------------|---------|
314+
| `{serviceName}` | External service name | `github`, `stripe` |
315+
| `{buildDir}` | Build directory | `.nitro` or `.nuxt` |
316+
| `{rootDir}` | Root directory | `/Users/you/project` |
317+
| `{framework}` | Framework name | `nuxt` or `nitro` |
318+
| `{typesDir}` | Types directory | `.nitro/types` |
319+
| `{serverGraphql}` | Server GraphQL dir | `server/graphql` |
320+
| `{clientGraphql}` | Client GraphQL dir | `app/graphql` |
321+
322+
Example:
323+
```ts
324+
sdk: {
325+
external: '{clientGraphql}/{serviceName}/sdk.ts'
326+
}
327+
// → app/graphql/github/sdk.ts
328+
// → app/graphql/stripe/sdk.ts
329+
```
330+
331+
### Service-Specific Paths
332+
333+
Customize paths for individual external services:
334+
335+
```ts
336+
export default defineNuxtConfig({
337+
nitro: {
338+
graphql: {
339+
framework: 'graphql-yoga',
340+
341+
// Global default for all external services
342+
sdk: {
343+
external: 'app/graphql/{serviceName}/sdk.ts'
344+
},
345+
346+
externalServices: [
347+
{
348+
name: 'github',
349+
endpoint: 'https://api.github.com/graphql',
350+
schema: 'https://api.github.com/graphql',
351+
352+
// GitHub-specific paths (override global config)
353+
paths: {
354+
sdk: 'app/graphql/organization/github-sdk.ts',
355+
types: 'types/github.d.ts',
356+
ofetch: 'app/graphql/organization/github-client.ts'
357+
}
358+
},
359+
{
360+
name: 'stripe',
361+
endpoint: 'https://api.stripe.com/graphql',
362+
schema: 'https://api.stripe.com/graphql',
363+
364+
// Stripe-specific paths
365+
paths: {
366+
sdk: 'app/graphql/payments/stripe-sdk.ts',
367+
types: 'types/payments/stripe.d.ts',
368+
// ofetch uses global config
369+
}
370+
},
371+
{
372+
name: 'shopify',
373+
endpoint: 'https://api.shopify.com/graphql',
374+
// No paths → uses global config
375+
// → app/graphql/shopify/sdk.ts
376+
}
377+
]
378+
}
379+
}
380+
})
381+
```
382+
383+
### Path Resolution Priority
384+
385+
When resolving file paths, the system follows this priority order:
386+
387+
1. **Service-specific path** (for external services): `service.paths.sdk`
388+
2. **Category config**: `sdk.external` or `sdk.main`
389+
3. **Global paths**: `paths.clientGraphql`
390+
4. **Framework defaults**: Nuxt vs Nitro defaults
391+
392+
Example:
393+
```ts
394+
// Given this config:
395+
{
396+
paths: { clientGraphql: 'custom/graphql' },
397+
sdk: { external: '{clientGraphql}/{serviceName}/sdk.ts' },
398+
externalServices: [
399+
{
400+
name: 'github',
401+
paths: { sdk: 'app/org/github-sdk.ts' } // ← Wins (priority 1)
402+
},
403+
{
404+
name: 'stripe',
405+
// Uses sdk.external (priority 2)
406+
// → custom/graphql/stripe/sdk.ts
407+
}
408+
]
409+
}
410+
```
411+
412+
### Use Cases
413+
414+
**Monorepo structure:**
415+
```ts
416+
paths: {
417+
serverGraphql: 'packages/api/src/graphql',
418+
clientGraphql: 'packages/web/src/graphql',
419+
typesDir: 'packages/types/src/generated',
420+
}
421+
```
422+
423+
**Multiple external service organizations:**
424+
```ts
425+
externalServices: [
426+
{
427+
name: 'github',
428+
paths: { sdk: 'app/graphql/vcs/github-sdk.ts' }
429+
},
430+
{
431+
name: 'gitlab',
432+
paths: { sdk: 'app/graphql/vcs/gitlab-sdk.ts' }
433+
},
434+
{
435+
name: 'stripe',
436+
paths: { sdk: 'app/graphql/billing/stripe-sdk.ts' }
437+
}
438+
]
439+
```
440+
441+
**Library development (no scaffolding):**
442+
```ts
443+
{
444+
scaffold: false,
445+
clientUtils: false,
446+
sdk: { enabled: true }, // Only generate SDKs
447+
types: { enabled: true }, // Only generate types
448+
}
449+
```
450+
451+
</details>
452+
213453
<details>
214454
<summary><strong>🎭 Custom Directives</strong></summary>
215455

0 commit comments

Comments
 (0)