nitro-graphql 0.2.2 → 0.3.0

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.
@@ -1,7 +1,7 @@
1
- import * as _nuxt_schema4 from "@nuxt/schema";
1
+ import * as _nuxt_schema1 from "@nuxt/schema";
2
2
 
3
3
  //#region src/ecosystem/nuxt.d.ts
4
4
  interface ModuleOptions {}
5
- declare const _default: _nuxt_schema4.NuxtModule<ModuleOptions, ModuleOptions, false>;
5
+ declare const _default: _nuxt_schema1.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 nitropack5 from "nitropack";
3
+ import * as nitropack0 from "nitropack";
4
4
 
5
5
  //#region src/index.d.ts
6
6
  type GraphQLFramework = 'graphql-yoga';
7
- declare const _default: nitropack5.NitroModule;
7
+ declare const _default: nitropack0.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: [],
@@ -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 h32 from "h3";
1
+ import * as h36 from "h3";
2
2
 
3
3
  //#region src/routes/apollo-server.d.ts
4
- declare const _default: h32.EventHandler<h32.EventHandlerRequest, any>;
4
+ declare const _default: h36.EventHandler<h36.EventHandlerRequest, any>;
5
5
  //#endregion
6
6
  export { _default as default };
@@ -1,6 +1,6 @@
1
- import * as h30 from "h3";
1
+ import * as h34 from "h3";
2
2
 
3
3
  //#region src/routes/graphql-yoga.d.ts
4
- declare const _default: h30.EventHandler<h30.EventHandlerRequest, Promise<Response>>;
4
+ declare const _default: h34.EventHandler<h34.EventHandlerRequest, Promise<Response>>;
5
5
  //#endregion
6
6
  export { _default as default };
@@ -1,7 +1,7 @@
1
- import * as h36 from "h3";
1
+ import * as h32 from "h3";
2
2
 
3
3
  //#region src/routes/health.d.ts
4
- declare const _default: h36.EventHandler<h36.EventHandlerRequest, Promise<{
4
+ declare const _default: h32.EventHandler<h32.EventHandlerRequest, Promise<{
5
5
  status: string;
6
6
  message: string;
7
7
  timestamp: string;
@@ -1,7 +1,7 @@
1
1
  import { ApolloServerOptions, BaseContext } from "@apollo/server";
2
2
  import { YogaServerOptions } from "graphql-yoga";
3
- import { Resolvers, ResolversTypes, StandardSchemaV1 } from "#graphql/server";
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;
@@ -59,7 +59,18 @@ async function generateTypes(schema, config = {}, outputPath) {
59
59
  `import type { StandardSchemaV1 } from 'nitro-graphql'`,
60
60
  `
61
61
  export type SchemaType = Partial<Record<Partial<keyof ResolversTypes>, StandardSchemaV1>>
62
- type SchemaKeys = keyof typeof schemas;
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;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "nitro-graphql",
3
3
  "type": "module",
4
- "version": "0.2.2",
4
+ "version": "0.3.0",
5
5
  "description": "GraphQL integration for Nitro",
6
6
  "license": "MIT",
7
7
  "sideEffects": false,