nitro-graphql 0.2.1 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/dist/ecosystem/nuxt.d.ts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +33 -6
- package/dist/routes/apollo-server.d.ts +2 -2
- package/dist/routes/graphql-yoga.d.ts +2 -2
- package/dist/utils/define.d.ts +2 -2
- package/dist/utils/server-codegen.js +13 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -191,6 +191,7 @@ server/
|
|
|
191
191
|
│ │ ├── post-queries.resolver.ts # Post query resolvers (use named exports)
|
|
192
192
|
│ │ └── create-post.resolver.ts # Post mutation resolvers (use named exports)
|
|
193
193
|
│ └── config.ts # Optional GraphQL configuration
|
|
194
|
+
│ └── schema.ts # Changing Special Return types
|
|
194
195
|
```
|
|
195
196
|
|
|
196
197
|
> [!TIP]
|
|
@@ -621,6 +622,7 @@ export const postTypes = defineType({
|
|
|
621
622
|
You can override schema types if needed. StandardSchema supported — Zod, Valibot, anything works:
|
|
622
623
|
|
|
623
624
|
```ts
|
|
625
|
+
# server/graphql/schema.ts
|
|
624
626
|
import { defineSchema } from 'nitro-graphql/utils/define'
|
|
625
627
|
import { z } from 'zod'
|
|
626
628
|
|
package/dist/ecosystem/nuxt.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as _nuxt_schema3 from "@nuxt/schema";
|
|
2
2
|
|
|
3
3
|
//#region src/ecosystem/nuxt.d.ts
|
|
4
4
|
interface ModuleOptions {}
|
|
5
|
-
declare const _default:
|
|
5
|
+
declare const _default: _nuxt_schema3.NuxtModule<ModuleOptions, ModuleOptions, false>;
|
|
6
6
|
//#endregion
|
|
7
7
|
export { ModuleOptions, _default as default };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { StandardSchemaV1 } from "./types/standard-schema.js";
|
|
2
2
|
import { CodegenClientConfig, CodegenServerConfig, GenImport, NitroGraphQLOptions } from "./types/index.js";
|
|
3
|
-
import * as
|
|
3
|
+
import * as nitropack2 from "nitropack";
|
|
4
4
|
|
|
5
5
|
//#region src/index.d.ts
|
|
6
6
|
type GraphQLFramework = 'graphql-yoga';
|
|
7
|
-
declare const _default:
|
|
7
|
+
declare const _default: nitropack2.NitroModule;
|
|
8
8
|
//#endregion
|
|
9
9
|
export { CodegenClientConfig, CodegenServerConfig, GenImport, GraphQLFramework, NitroGraphQLOptions, StandardSchemaV1, _default as default };
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { relativeWithDot, scanDefs, scanResolvers } from "./utils/index.js";
|
|
2
2
|
import { clientTypeGeneration, serverTypeGeneration } from "./utils/server-type-generation.js";
|
|
3
3
|
import { rollupConfig } from "./rollup.js";
|
|
4
|
-
import { existsSync, writeFileSync } from "node:fs";
|
|
4
|
+
import { existsSync, mkdirSync, writeFileSync } from "node:fs";
|
|
5
5
|
import { fileURLToPath } from "node:url";
|
|
6
6
|
import { watch } from "chokidar";
|
|
7
7
|
import consola from "consola";
|
|
@@ -13,10 +13,7 @@ import { dirname, join, resolve } from "pathe";
|
|
|
13
13
|
var src_default = defineNitroModule({
|
|
14
14
|
name: "nitro-graphql",
|
|
15
15
|
async setup(nitro) {
|
|
16
|
-
if (!nitro.options.graphql?.framework)
|
|
17
|
-
consola.warn("No GraphQL framework specified. Please set graphql.framework to \"graphql-yoga\" or \"apollo-server\".");
|
|
18
|
-
return;
|
|
19
|
-
}
|
|
16
|
+
if (!nitro.options.graphql?.framework) consola.warn("No GraphQL framework specified. Please set graphql.framework to \"graphql-yoga\" or \"apollo-server\".");
|
|
20
17
|
nitro.graphql ||= {
|
|
21
18
|
buildDir: "",
|
|
22
19
|
watchDirs: [],
|
|
@@ -149,7 +146,7 @@ declare module 'nitro-graphql' {
|
|
|
149
146
|
types.tsConfig.compilerOptions.paths ??= {};
|
|
150
147
|
types.tsConfig.compilerOptions.paths["#graphql/server"] = [relativeWithDot(tsconfigDir, join(typesDir, "nitro-graphql-server.d.ts"))];
|
|
151
148
|
types.tsConfig.compilerOptions.paths["#graphql/client"] = [relativeWithDot(tsconfigDir, join(typesDir, "nitro-graphql-client.d.ts"))];
|
|
152
|
-
types.tsConfig.compilerOptions.paths["#graphql/
|
|
149
|
+
types.tsConfig.compilerOptions.paths["#graphql/schema"] = [relativeWithDot(tsconfigDir, join(nitro.graphql.serverDir, "schema.ts"))];
|
|
153
150
|
types.tsConfig.include = types.tsConfig.include || [];
|
|
154
151
|
types.tsConfig.include.push(relativeWithDot(tsconfigDir, join(typesDir, "nitro-graphql-server.d.ts")), relativeWithDot(tsconfigDir, join(typesDir, "nitro-graphql-client.d.ts")), relativeWithDot(tsconfigDir, join(typesDir, "graphql.d.ts")));
|
|
155
152
|
});
|
|
@@ -172,6 +169,36 @@ export default <IGraphQLConfig> {
|
|
|
172
169
|
},
|
|
173
170
|
}`, "utf-8");
|
|
174
171
|
}
|
|
172
|
+
if (!existsSync(nitro.graphql.serverDir)) mkdirSync(nitro.graphql.serverDir, { recursive: true });
|
|
173
|
+
if (!existsSync(join(nitro.graphql.serverDir, "schema.ts"))) writeFileSync(join(nitro.graphql.serverDir, "schema.ts"), `export default defineSchema({
|
|
174
|
+
|
|
175
|
+
})
|
|
176
|
+
`, "utf-8");
|
|
177
|
+
if (!existsSync(join(nitro.graphql.serverDir, "config.ts"))) writeFileSync(join(nitro.graphql.serverDir, "config.ts"), `// Example GraphQL config file please change it to your needs
|
|
178
|
+
// import * as tables from '../drizzle/schema/index'
|
|
179
|
+
// import { useDatabase } from '../utils/useDb'
|
|
180
|
+
|
|
181
|
+
export default defineGraphQLConfig({
|
|
182
|
+
// graphql-yoga example config
|
|
183
|
+
// context: () => {
|
|
184
|
+
// return {
|
|
185
|
+
// context: {
|
|
186
|
+
// useDatabase,
|
|
187
|
+
// tables,
|
|
188
|
+
// },
|
|
189
|
+
// }
|
|
190
|
+
// },
|
|
191
|
+
})
|
|
192
|
+
`, "utf-8");
|
|
193
|
+
if (!existsSync(join(nitro.graphql.serverDir, "context.d.ts"))) writeFileSync(join(nitro.graphql.serverDir, "context.d.ts"), `// Example context definition please change it to your needs
|
|
194
|
+
// import type { Database } from '../utils/useDb'
|
|
195
|
+
|
|
196
|
+
declare module 'h3' {
|
|
197
|
+
interface H3EventContext {
|
|
198
|
+
// useDatabase: () => Database
|
|
199
|
+
// tables: typeof import('~~/server/drizzle/schema/index')
|
|
200
|
+
}
|
|
201
|
+
}`, "utf-8");
|
|
175
202
|
}
|
|
176
203
|
});
|
|
177
204
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as h34 from "h3";
|
|
2
2
|
|
|
3
3
|
//#region src/routes/apollo-server.d.ts
|
|
4
|
-
declare const _default:
|
|
4
|
+
declare const _default: h34.EventHandler<h34.EventHandlerRequest, any>;
|
|
5
5
|
//#endregion
|
|
6
6
|
export { _default as default };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as h30 from "h3";
|
|
2
2
|
|
|
3
3
|
//#region src/routes/graphql-yoga.d.ts
|
|
4
|
-
declare const _default:
|
|
4
|
+
declare const _default: h30.EventHandler<h30.EventHandlerRequest, Promise<Response>>;
|
|
5
5
|
//#endregion
|
|
6
6
|
export { _default as default };
|
package/dist/utils/define.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ApolloServerOptions, BaseContext } from "@apollo/server";
|
|
2
2
|
import { YogaServerOptions } from "graphql-yoga";
|
|
3
|
-
import { Resolvers, ResolversTypes
|
|
4
|
-
import { GraphQLFramework } from "nitro-graphql";
|
|
3
|
+
import { Resolvers, ResolversTypes } from "#graphql/server";
|
|
4
|
+
import { GraphQLFramework, StandardSchemaV1 } from "nitro-graphql";
|
|
5
5
|
|
|
6
6
|
//#region src/utils/define.d.ts
|
|
7
7
|
type Flatten<T> = T extends infer U ? { [K in keyof U]: U[K] } : never;
|
|
@@ -55,11 +55,22 @@ async function generateTypes(schema, config = {}, outputPath) {
|
|
|
55
55
|
imports: { plugin: () => {
|
|
56
56
|
return {
|
|
57
57
|
prepend: [
|
|
58
|
-
`import schemas from '#graphql/
|
|
58
|
+
`import schemas from '#graphql/schema'`,
|
|
59
59
|
`import type { StandardSchemaV1 } from 'nitro-graphql'`,
|
|
60
60
|
`
|
|
61
61
|
export type SchemaType = Partial<Record<Partial<keyof ResolversTypes>, StandardSchemaV1>>
|
|
62
|
-
|
|
62
|
+
|
|
63
|
+
// Check if schemas is empty object, return never if so
|
|
64
|
+
type SafeSchemaKeys<T> = T extends Record<PropertyKey, never>
|
|
65
|
+
? never
|
|
66
|
+
: keyof T extends string | number | symbol
|
|
67
|
+
? keyof T extends never
|
|
68
|
+
? never
|
|
69
|
+
: keyof T
|
|
70
|
+
: never;
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
type SchemaKeys = SafeSchemaKeys<typeof schemas>;
|
|
63
74
|
|
|
64
75
|
type InferInput<T> = T extends StandardSchemaV1 ? StandardSchemaV1.InferInput<T> : unknown;
|
|
65
76
|
type InferOutput<T> = T extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<T> : unknown;
|