nitro-graphql 1.0.1 → 1.0.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.
@@ -1,7 +1,7 @@
1
- import * as _nuxt_schema0 from "@nuxt/schema";
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: _nuxt_schema0.NuxtModule<ModuleOptions, ModuleOptions, false>;
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
- import { CodegenClientConfig, CodegenServerConfig, GenImport, NitroGraphQLOptions } from "./types/index.js";
3
- import * as nitropack7 from "nitropack";
2
+ import { CodegenClientConfig, CodegenServerConfig, GenImport, GenericSdkConfig, NitroGraphQLOptions } from "./types/index.js";
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: nitropack7.NitroModule;
7
+ declare const _default: nitropack2.NitroModule;
8
8
  //#endregion
9
- export { CodegenClientConfig, CodegenServerConfig, GenImport, GraphQLFramework, NitroGraphQLOptions, StandardSchemaV1, _default as default };
9
+ export { CodegenClientConfig, CodegenServerConfig, GenImport, GenericSdkConfig, GraphQLFramework, NitroGraphQLOptions, StandardSchemaV1, _default as default };
@@ -1,6 +1,6 @@
1
- import * as h35 from "h3";
1
+ import * as h30 from "h3";
2
2
 
3
3
  //#region src/routes/apollo-server.d.ts
4
- declare const _default: h35.EventHandler<h35.EventHandlerRequest, any>;
4
+ declare const _default: h30.EventHandler<h30.EventHandlerRequest, any>;
5
5
  //#endregion
6
6
  export { _default as default };
@@ -1,6 +1,6 @@
1
- import * as h33 from "h3";
1
+ import * as h34 from "h3";
2
2
 
3
3
  //#region src/routes/graphql-yoga.d.ts
4
- declare const _default: h33.EventHandler<h33.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 h31 from "h3";
1
+ import * as h36 from "h3";
2
2
 
3
3
  //#region src/routes/health.d.ts
4
- declare const _default: h31.EventHandler<h31.EventHandlerRequest, Promise<{
4
+ declare const _default: h36.EventHandler<h36.EventHandlerRequest, Promise<{
5
5
  status: string;
6
6
  message: string;
7
7
  timestamp: string;
@@ -2,11 +2,21 @@ import { StandardSchemaV1 } from "./standard-schema.js";
2
2
  import { ESMCodeGenOptions } from "knitwork";
3
3
  import { IResolvers } from "@graphql-tools/utils";
4
4
  import { TypeScriptPluginConfig } from "@graphql-codegen/typescript";
5
+ import { plugin as plugin$1 } from "@graphql-codegen/typescript-generic-sdk";
5
6
  import { TypeScriptDocumentsPluginConfig } from "@graphql-codegen/typescript-operations";
6
7
  import { TypeScriptResolversPluginConfig } from "@graphql-codegen/typescript-resolvers";
7
8
 
8
9
  //#region src/types/index.d.ts
9
10
  type CodegenServerConfig = TypeScriptPluginConfig & TypeScriptResolversPluginConfig;
11
+ type DocumentModeConfig = Pick<Parameters<typeof plugin$1>[2], 'documentMode'>;
12
+ type DocumentModeEnum = NonNullable<DocumentModeConfig['documentMode']>;
13
+ type DocumentModeType = `${DocumentModeEnum}`;
14
+ type GenericSdkConfig = Omit<Parameters<typeof plugin$1>[2], 'documentMode'> & {
15
+ documentMode?: DocumentModeType;
16
+ };
17
+ type CodegenClientConfig = TypeScriptPluginConfig & TypeScriptDocumentsPluginConfig & {
18
+ endpoint?: string;
19
+ };
10
20
  interface IESMImport {
11
21
  name: string;
12
22
  as?: string;
@@ -46,10 +56,6 @@ declare module 'nitropack' {
46
56
  graphql?: NitroGraphQLOptions;
47
57
  }
48
58
  }
49
- interface CodegenClientConfig extends TypeScriptPluginConfig, TypeScriptDocumentsPluginConfig {
50
- endpoint?: string;
51
- documentMode?: 'string' | 'graphQLTag' | 'documentNode' | 'documentNodeImportFragments' | 'external';
52
- }
53
59
  interface NitroGraphQLOptions {
54
60
  framework: 'graphql-yoga' | 'apollo-server';
55
61
  endpoint?: {
@@ -67,7 +73,8 @@ interface NitroGraphQLOptions {
67
73
  codegen?: {
68
74
  server?: CodegenServerConfig;
69
75
  client?: CodegenClientConfig;
76
+ clientSDK?: GenericSdkConfig;
70
77
  };
71
78
  }
72
79
  //#endregion
73
- export { CodegenClientConfig, CodegenServerConfig, GenImport, NitroGraphQLOptions };
80
+ export { CodegenClientConfig, CodegenServerConfig, GenImport, GenericSdkConfig, NitroGraphQLOptions };
@@ -1,4 +1,4 @@
1
- import { CodegenClientConfig } from "../types/index.js";
1
+ import { CodegenClientConfig, GenericSdkConfig } from "../types/index.js";
2
2
  import { GraphQLSchema } from "graphql";
3
3
  import { Source } from "@graphql-tools/utils";
4
4
  import { LoadSchemaOptions, UnnormalizedTypeDefPointer } from "@graphql-tools/load";
@@ -15,7 +15,7 @@ type GraphQLTypeDefPointer = UnnormalizedTypeDefPointer | UnnormalizedTypeDefPoi
15
15
  type GraphQLLoadSchemaOptions = Partial<LoadSchemaOptions>;
16
16
  declare function graphQLLoadSchemaSync(schemaPointers: GraphQLTypeDefPointer, data?: GraphQLLoadSchemaOptions): Promise<GraphQLSchema | undefined>;
17
17
  declare function loadGraphQLDocuments(patterns: string | string[]): Promise<Source[]>;
18
- declare function generateClientTypes(schema: GraphQLSchema, docs: Source[], config?: CodegenClientConfig, outputPath?: string): Promise<false | {
18
+ declare function generateClientTypes(schema: GraphQLSchema, docs: Source[], config?: CodegenClientConfig, sdkConfig?: GenericSdkConfig, outputPath?: string): Promise<false | {
19
19
  types: string;
20
20
  sdk: string;
21
21
  }>;
@@ -47,14 +47,13 @@ async function loadGraphQLDocuments(patterns) {
47
47
  else throw e;
48
48
  }
49
49
  }
50
- async function generateClientTypes(schema, docs, config = {}, outputPath) {
50
+ async function generateClientTypes(schema, docs, config = {}, sdkConfig = {}, outputPath) {
51
51
  if (docs.length === 0) {
52
52
  consola$1.info("[graphql] No client GraphQL files found. Skipping client type generation.");
53
53
  return false;
54
54
  }
55
55
  consola$1.info(`[graphql] Found ${docs.length} client GraphQL documents`);
56
56
  const defaultConfig = {
57
- documentMode: "string",
58
57
  emitLegacyCommonJSImports: false,
59
58
  useTypeImports: true,
60
59
  enumsAsTypes: true,
@@ -70,6 +69,22 @@ async function generateClientTypes(schema, docs, config = {}, outputPath) {
70
69
  }
71
70
  };
72
71
  const mergedConfig = defu$1(config, defaultConfig);
72
+ const defaultSdkConfig = {
73
+ documentMode: "string",
74
+ pureMagicComment: true,
75
+ strictScalars: true,
76
+ useTypeImports: true,
77
+ dedupeOperationSuffix: true,
78
+ rawRequest: true,
79
+ scalars: {
80
+ DateTime: "Date",
81
+ JSON: "any",
82
+ UUID: "string",
83
+ NonEmptyString: "string",
84
+ Currency: "string"
85
+ }
86
+ };
87
+ const mergedSdkConfig = defu$1(sdkConfig, defaultSdkConfig);
73
88
  try {
74
89
  const output = await codegen({
75
90
  filename: outputPath || "client-types.generated.ts",
@@ -91,26 +106,9 @@ async function generateClientTypes(schema, docs, config = {}, outputPath) {
91
106
  baseOutputDir: outputPath || "client-types.generated.ts",
92
107
  schema: parse(printSchemaWithDirectives(schema)),
93
108
  documents: [...docs],
94
- config: {
95
- fetcher: "function",
96
- documentMode: "string",
97
- pureMagicComment: true,
98
- strictScalars: true,
99
- avoidOptionals: true,
100
- useTypeImports: true,
101
- dedupeOperationSuffix: true,
102
- exportFragmentSpreadSubTypes: true,
103
- enumsAsTypes: true,
104
- scalars: {
105
- DateTime: "Date",
106
- JSON: "any",
107
- UUID: "string",
108
- NonEmptyString: "string",
109
- Currency: "string"
110
- }
111
- },
109
+ config: mergedSdkConfig,
112
110
  presetConfig: { typesPath: "#graphql/client" },
113
- plugins: [{ pluginContent: {} }, { typescriptGenericSdk: { rawRequest: false } }],
111
+ plugins: [{ pluginContent: {} }, { typescriptGenericSdk: {} }],
114
112
  pluginMap: {
115
113
  pluginContent: { plugin: pluginContent },
116
114
  typescriptGenericSdk: { plugin: plugin$1 }
@@ -14,7 +14,6 @@ function generateNuxtOfetchClient(clientDir) {
14
14
  if (!existsSync(ofetchPath)) {
15
15
  const ofetchContent = `// This file is auto-generated once by nitro-graphql for quick start
16
16
  // You can modify this file according to your needs
17
- import type { ExecutionResult } from 'graphql'
18
17
  import type { Requester } from './sdk'
19
18
  import { getSdk } from './sdk'
20
19
 
@@ -29,11 +28,9 @@ export function createGraphQLClient(endpoint: string): Requester {
29
28
  'Content-Type': 'application/json',
30
29
  ...headers,
31
30
  },
32
- }) as ExecutionResult
31
+ })
33
32
 
34
- return result.errors?.length
35
- ? Promise.reject(new Error(result.errors[0]?.message || 'GraphQL error'))
36
- : result.data as R
33
+ return result as R
37
34
  }
38
35
  }
39
36
 
@@ -77,7 +74,7 @@ async function clientTypeGeneration(nitro) {
77
74
  }
78
75
  const graphqlString = readFileSync(schemaFilePath, "utf-8");
79
76
  const schema = buildSchema(graphqlString);
80
- const types = await generateClientTypes(schema, loadDocs, nitro.options.graphql?.codegen?.client ?? {});
77
+ const types = await generateClientTypes(schema, loadDocs, nitro.options.graphql?.codegen?.client ?? {}, nitro.options.graphql?.codegen?.clientSDK ?? {});
81
78
  if (types === false) return;
82
79
  const clientTypesPath = resolve(nitro.options.buildDir, "types", "nitro-graphql-client.d.ts");
83
80
  const sdkTypesPath = resolve(nitro.graphql.clientDir, "sdk.ts");
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "nitro-graphql",
3
3
  "type": "module",
4
- "version": "1.0.1",
4
+ "version": "1.0.3",
5
5
  "description": "GraphQL integration for Nitro",
6
6
  "license": "MIT",
7
7
  "sideEffects": false,