Skip to content

Commit 167cbc9

Browse files
fix: add GraphQL schema definition and update import paths
1 parent e414a6b commit 167cbc9

File tree

6 files changed

+38
-4
lines changed

6 files changed

+38
-4
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ server/
191191
│ │ ├── post-queries.resolver.ts # Post query resolvers (use named exports)
192192
│ │ └── create-post.resolver.ts # Post mutation resolvers (use named exports)
193193
│ └── config.ts # Optional GraphQL configuration
194+
│ └── schema.ts # Changing Special Return types
194195
```
195196

196197
> [!TIP]
@@ -621,6 +622,7 @@ export const postTypes = defineType({
621622
You can override schema types if needed. StandardSchema supported — Zod, Valibot, anything works:
622623

623624
```ts
625+
# server/graphql/schema.ts
624626
import { defineSchema } from 'nitro-graphql/utils/define'
625627
import { z } from 'zod'
626628

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "nitro-graphql",
33
"type": "module",
4-
"version": "0.2.0",
4+
"version": "0.2.2",
55
"packageManager": "[email protected]",
66
"description": "GraphQL integration for Nitro",
77
"license": "MIT",
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { z } from 'zod'
2+
3+
export default defineSchema({
4+
Todo: z.object({
5+
id: z.string(),
6+
title: z.string(),
7+
completed: z.boolean(),
8+
createdAt: z.date(),
9+
}),
10+
User: z.object({
11+
id: z.string(),
12+
name: z.string(),
13+
email: z.string().email(),
14+
age: z.number().min(0),
15+
}),
16+
})

playground/server/graphql/schema.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { z } from 'zod'
2+
3+
export default defineSchema({
4+
Todo: z.object({
5+
id: z.string(),
6+
title: z.string(),
7+
completed: z.boolean(),
8+
createdAt: z.date(),
9+
}),
10+
User: z.object({
11+
id: z.string(),
12+
name: z.string(),
13+
email: z.string().email(),
14+
age: z.number().min(0),
15+
}),
16+
})

src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,8 @@ declare module 'nitro-graphql' {
237237
types.tsConfig.compilerOptions.paths['#graphql/client'] = [
238238
relativeWithDot(tsconfigDir, join(typesDir, 'nitro-graphql-client.d.ts')),
239239
]
240-
types.tsConfig.compilerOptions.paths['#graphql/schemas'] = [
241-
relativeWithDot(tsconfigDir, join(nitro.graphql.serverDir, 'schemas.ts')),
240+
types.tsConfig.compilerOptions.paths['#graphql/schema'] = [
241+
relativeWithDot(tsconfigDir, join(nitro.graphql.serverDir, 'schema.ts')),
242242
]
243243
types.tsConfig.include = types.tsConfig.include || []
244244
types.tsConfig.include.push(

src/utils/server-codegen.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export async function generateTypes(
8080
plugin: () => {
8181
return {
8282
prepend: [
83-
`import schemas from '#graphql/schemas'`,
83+
`import schemas from '#graphql/schema'`,
8484
`import type { StandardSchemaV1 } from 'nitro-graphql'`,
8585

8686
`

0 commit comments

Comments
 (0)