Skip to content

Commit 10b1b1a

Browse files
feat: add pnpm workspace configuration and enhance TypeScript support for GraphQL Yoga
- Introduced a new pnpm workspace configuration in `pnpm-workspace.yaml` to manage multiple packages. - Updated `src/index.ts` to include TypeScript path aliases for GraphQL types, improving IDE support. - Moved GraphQL Yoga options declaration from `src/types.ts` to `src/index.ts` for better organization. - Added a utility function `relativeWithDot` in `src/utils.ts` to handle relative paths with dot notation. - Modified `tsconfig.json` to exclude additional directories related to the new workspace structure.
1 parent fac87c5 commit 10b1b1a

File tree

8 files changed

+2436
-37
lines changed

8 files changed

+2436
-37
lines changed

.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ignore-workspace-root-check=true

playground/nitro.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { defineNitroConfig } from 'nitropack/config'
2+
// import 'nitro-graphql' // Import for types
23

34
export default defineNitroConfig({
45
srcDir: 'server',

pnpm-lock.yaml

Lines changed: 2393 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pnpm-workspace.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
packages:
2+
- playground
3+
- playground-nuxt

src/index.ts

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,19 @@ import type { Nitro } from 'nitropack/types'
22
import type { NitroGraphQLOptions } from './types'
33

44
import { defineNitroModule } from 'nitropack/kit'
5-
import { join } from 'pathe'
5+
import { dirname, join, resolve } from 'pathe'
66
import { devmode } from './dev'
7+
import { relativeWithDot } from './utils'
8+
9+
declare module 'nitropack' {
10+
interface NitroOptions {
11+
graphqlYoga?: NitroGraphQLOptions
12+
}
13+
14+
interface NitroRuntimeConfig {
15+
graphqlYoga?: NitroGraphQLOptions
16+
}
17+
}
718

819
export default defineNitroModule({
920
name: 'nitro:graphql-yoga',
@@ -153,18 +164,32 @@ export default defineEventHandler(async (event) => {
153164
})
154165
}
155166

167+
const tsConfigPath = resolve(
168+
nitro.options.buildDir,
169+
nitro.options.typescript.tsconfigPath,
170+
)
171+
const tsconfigDir = dirname(tsConfigPath)
172+
const typesDir = resolve(nitro.options.buildDir, 'types')
173+
156174
nitro.hooks.hook('types:extend', (types) => {
157175
// Add TypeScript path alias for IDE support
158176
types.tsConfig ||= {}
159177
types.tsConfig.compilerOptions ??= {}
160178
types.tsConfig.compilerOptions.paths ??= {}
161-
types.tsConfig.compilerOptions.paths['#build/graphql-types.generated'] = [
162-
join(nitro.options.buildDir, 'types', 'graphql-types.generated.ts'),
179+
// types.tsConfig.compilerOptions.paths['#build/graphql-types.generated'] = [
180+
// join(nitro.options.buildDir, 'types', 'graphql-types.generated.ts'),
181+
// ]
182+
types.tsConfig.compilerOptions.paths['#graphql/server'] = [
183+
relativeWithDot(tsconfigDir, join(typesDir, 'graphql-types.generated.ts')),
184+
]
185+
types.tsConfig.compilerOptions.paths['#graphql/client'] = [
186+
relativeWithDot(tsconfigDir, join(typesDir, 'graphql-client.generated.ts')),
163187
]
164188
types.tsConfig.include = types.tsConfig.include || []
165189
types.tsConfig.include.push(
166-
join(nitro.options.buildDir, 'types', 'graphql-types.generated.ts'),
167-
join(nitro.options.buildDir, 'types', 'graphql.d.ts'),
190+
relativeWithDot(tsconfigDir, join(typesDir, 'graphql-client.generated.ts')),
191+
relativeWithDot(tsconfigDir, join(typesDir, 'graphql-types.generated.ts')),
192+
relativeWithDot(tsconfigDir, join(typesDir, 'graphql.d.ts')),
168193
)
169194
})
170195

src/types.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,4 @@ export interface NitroGraphQLOptions {
3232
yogaConfig?: Partial<YogaServerOptions<any, any>>
3333
}
3434

35-
declare module 'nitropack' {
36-
interface NitroOptions {
37-
graphqlYoga?: NitroGraphQLOptions
38-
}
39-
40-
interface NitroRuntimeConfig {
41-
graphqlYoga?: NitroGraphQLOptions
42-
}
43-
}
44-
4535
export interface Resolvers {}

src/utils.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { YogaServerOptions } from 'graphql-yoga'
22
import type { GraphQLSchemaConfig, Resolvers } from 'nitro-graphql/types'
3+
import { relative } from 'pathe'
34

45
// TODO: check used.
56
export function defineGraphQLSchema(config: GraphQLSchemaConfig): GraphQLSchemaConfig {
@@ -20,3 +21,9 @@ export function defineYogaConfig<TServerContext = any, TUserContext = any>(
2021
): Partial<YogaServerOptions<TServerContext, TUserContext>> {
2122
return config
2223
}
24+
const RELATIVE_RE = /^\.{1,2}\//
25+
26+
export function relativeWithDot(from: string, to: string) {
27+
const rel = relative(from, to)
28+
return RELATIVE_RE.test(rel) ? rel : `./${rel}`
29+
}

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,5 @@
2626
"skipLibCheck": true
2727
},
2828
"include": ["src/**/*"],
29-
"exclude": ["node_modules", "dist"]
29+
"exclude": ["node_modules", "dist", "playground", "playground-nuxt"]
3030
}

0 commit comments

Comments
 (0)