nitro-graphql 2.0.0-beta.37 → 2.0.0-beta.38
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/dist/cli/commands/generate.d.mts +26 -0
- package/dist/cli/commands/generate.mjs +196 -0
- package/dist/cli/commands/index.d.mts +4 -0
- package/dist/cli/commands/index.mjs +5 -0
- package/dist/cli/commands/init.d.mts +12 -0
- package/dist/cli/commands/init.mjs +100 -0
- package/dist/cli/commands/validate.d.mts +10 -0
- package/dist/cli/commands/validate.mjs +69 -0
- package/dist/cli/config.d.mts +75 -0
- package/dist/cli/config.mjs +20 -0
- package/dist/cli/index.d.mts +24 -0
- package/dist/cli/index.mjs +219 -0
- package/dist/core/codegen/client.d.mts +23 -0
- package/dist/core/codegen/client.mjs +150 -0
- package/dist/core/codegen/document-loader.d.mts +10 -0
- package/dist/core/codegen/document-loader.mjs +18 -0
- package/dist/core/codegen/index.d.mts +8 -0
- package/dist/core/codegen/index.mjs +9 -0
- package/dist/{utils/codegen-plugin.d.mts → core/codegen/plugin.d.mts} +2 -2
- package/dist/{utils/codegen-plugin.mjs → core/codegen/plugin.mjs} +1 -1
- package/dist/core/codegen/runtime.d.mts +20 -0
- package/dist/core/codegen/runtime.mjs +60 -0
- package/dist/core/codegen/schema-loader.d.mts +28 -0
- package/dist/core/codegen/schema-loader.mjs +128 -0
- package/dist/core/codegen/server.d.mts +28 -0
- package/dist/core/codegen/server.mjs +143 -0
- package/dist/{codegen → core/codegen}/validation.d.mts +1 -1
- package/dist/{codegen → core/codegen}/validation.mjs +1 -1
- package/dist/core/config.d.mts +50 -0
- package/dist/core/config.mjs +82 -0
- package/dist/core/constants.d.mts +188 -0
- package/dist/core/constants.mjs +210 -0
- package/dist/core/index.d.mts +32 -0
- package/dist/core/index.mjs +26 -0
- package/dist/core/scanning/ast-scanner.d.mts +23 -0
- package/dist/core/scanning/ast-scanner.mjs +103 -0
- package/dist/core/scanning/common.d.mts +37 -0
- package/dist/core/scanning/common.mjs +60 -0
- package/dist/core/scanning/directives.d.mts +10 -0
- package/dist/core/scanning/directives.mjs +29 -0
- package/dist/core/scanning/documents.d.mts +21 -0
- package/dist/core/scanning/documents.mjs +43 -0
- package/dist/core/scanning/index.d.mts +7 -0
- package/dist/core/scanning/index.mjs +8 -0
- package/dist/core/scanning/resolvers.d.mts +10 -0
- package/dist/core/scanning/resolvers.mjs +58 -0
- package/dist/core/scanning/schemas.d.mts +14 -0
- package/dist/core/scanning/schemas.mjs +64 -0
- package/dist/{utils/schema-builder.d.mts → core/schema/builder.d.mts} +7 -2
- package/dist/{utils/schema-builder.mjs → core/schema/builder.mjs} +22 -3
- package/dist/{utils → core/schema}/federation.d.mts +10 -5
- package/dist/{utils → core/schema}/federation.mjs +1 -1
- package/dist/core/schema/index.d.mts +3 -0
- package/dist/core/schema/index.mjs +4 -0
- package/dist/core/types/adapter.d.mts +58 -0
- package/dist/core/types/codegen.d.mts +133 -0
- package/dist/core/types/config.d.mts +212 -0
- package/dist/{types → core/types}/define.d.mts +3 -7
- package/dist/core/types/index.d.mts +5 -0
- package/dist/core/types/scanning.d.mts +69 -0
- package/dist/core/types/scanning.mjs +1 -0
- package/dist/{utils → core/utils}/directive-parser.d.mts +21 -5
- package/dist/{utils → core/utils}/directive-parser.mjs +25 -36
- package/dist/{utils → core/utils}/errors.d.mts +8 -4
- package/dist/{utils → core/utils}/errors.mjs +8 -4
- package/dist/core/utils/file-io.d.mts +24 -0
- package/dist/core/utils/file-io.mjs +47 -0
- package/dist/{utils → core/utils}/imports.d.mts +1 -1
- package/dist/{utils → core/utils}/imports.mjs +1 -1
- package/dist/core/utils/index.d.mts +7 -0
- package/dist/core/utils/index.mjs +8 -0
- package/dist/core/utils/logger.d.mts +19 -0
- package/dist/core/utils/logger.mjs +38 -0
- package/dist/{utils → core/utils}/ofetch-templates.d.mts +1 -1
- package/dist/{utils → core/utils}/ofetch-templates.mjs +1 -1
- package/dist/core/validation/external-services.d.mts +11 -0
- package/dist/{utils/validation.mjs → core/validation/external-services.mjs} +3 -3
- package/dist/core/validation/index.d.mts +2 -0
- package/dist/core/validation/index.mjs +3 -0
- package/dist/define.d.mts +1 -3
- package/dist/index.d.mts +6 -44
- package/dist/index.mjs +5 -62
- package/dist/nitro/adapter.d.mts +30 -0
- package/dist/nitro/adapter.mjs +97 -0
- package/dist/{utils → nitro}/apollo.d.mts +1 -1
- package/dist/{utils → nitro}/apollo.mjs +1 -1
- package/dist/nitro/codegen.d.mts +19 -0
- package/dist/nitro/codegen.mjs +141 -0
- package/dist/nitro/config.d.mts +52 -0
- package/dist/nitro/config.mjs +58 -0
- package/dist/nitro/index.d.mts +46 -0
- package/dist/nitro/index.mjs +65 -0
- package/dist/{utils/path-resolver.d.mts → nitro/paths.d.mts} +3 -19
- package/dist/{utils/path-resolver.mjs → nitro/paths.mjs} +2 -36
- package/dist/{rollup.d.mts → nitro/rollup.d.mts} +1 -1
- package/dist/{rollup.mjs → nitro/rollup.mjs} +11 -23
- package/dist/{routes → nitro/routes}/apollo-server.d.mts +1 -1
- package/dist/{routes → nitro/routes}/apollo-server.mjs +5 -5
- package/dist/{routes → nitro/routes}/debug-template.d.mts +1 -1
- package/dist/{routes → nitro/routes}/debug-template.mjs +1 -1
- package/dist/{routes → nitro/routes}/debug.d.mts +10 -16
- package/dist/{routes → nitro/routes}/debug.mjs +2 -2
- package/dist/{routes → nitro/routes}/graphql-yoga.d.mts +1 -1
- package/dist/{routes → nitro/routes}/graphql-yoga.mjs +3 -3
- package/dist/{routes → nitro/routes}/health.d.mts +1 -1
- package/dist/{routes → nitro/routes}/health.mjs +1 -1
- package/dist/nitro/setup/file-watcher.d.mts +16 -0
- package/dist/{setup → nitro/setup}/file-watcher.mjs +14 -18
- package/dist/{setup.d.mts → nitro/setup/logging.d.mts} +5 -6
- package/dist/nitro/setup/logging.mjs +66 -0
- package/dist/nitro/setup/rollup-integration.d.mts +16 -0
- package/dist/{setup → nitro/setup}/rollup-integration.mjs +2 -2
- package/dist/nitro/setup/routes.d.mts +10 -0
- package/dist/nitro/setup/routes.mjs +35 -0
- package/dist/nitro/setup/ts-config.d.mts +11 -0
- package/dist/{setup → nitro/setup}/ts-config.mjs +3 -3
- package/dist/nitro/setup.d.mts +12 -0
- package/dist/{setup.mjs → nitro/setup.mjs} +33 -100
- package/dist/{types/index.d.mts → nitro/types.d.mts} +125 -43
- package/dist/nitro/types.mjs +1 -0
- package/dist/nitro/virtual/generators.d.mts +31 -0
- package/dist/nitro/virtual/generators.mjs +193 -0
- package/dist/nitro/virtual/stubs.d.mts +20 -0
- package/dist/nitro/virtual/stubs.mjs +31 -0
- package/dist/{ecosystem/nuxt.d.mts → nuxt.d.mts} +1 -1
- package/dist/{ecosystem/nuxt.mjs → nuxt.mjs} +2 -2
- package/dist/{graphql/server.d.mts → stubs/index.d.mts} +5 -1
- package/dist/stubs/index.mjs +1 -0
- package/package.json +43 -42
- package/dist/codegen/client-types.d.mts +0 -13
- package/dist/codegen/client-types.mjs +0 -131
- package/dist/codegen/external-types.d.mts +0 -12
- package/dist/codegen/external-types.mjs +0 -88
- package/dist/codegen/index.d.mts +0 -18
- package/dist/codegen/index.mjs +0 -24
- package/dist/codegen/server-types.d.mts +0 -13
- package/dist/codegen/server-types.mjs +0 -64
- package/dist/config/defaults.mjs +0 -36
- package/dist/constants/scalars.mjs +0 -27
- package/dist/constants.mjs +0 -106
- package/dist/graphql/index.d.mts +0 -5
- package/dist/setup/graphql-scanner.mjs +0 -25
- package/dist/setup/scaffold-generator.mjs +0 -109
- package/dist/types/standard-schema.d.mts +0 -59
- package/dist/utils/client-codegen.d.mts +0 -41
- package/dist/utils/client-codegen.mjs +0 -277
- package/dist/utils/file-generator.d.mts +0 -37
- package/dist/utils/file-generator.mjs +0 -72
- package/dist/utils/file-writer.d.mts +0 -35
- package/dist/utils/file-writer.mjs +0 -32
- package/dist/utils/index.d.mts +0 -13
- package/dist/utils/index.mjs +0 -13
- package/dist/utils/layers.d.mts +0 -22
- package/dist/utils/layers.mjs +0 -28
- package/dist/utils/scanning/common.d.mts +0 -23
- package/dist/utils/scanning/common.mjs +0 -39
- package/dist/utils/scanning/directives.d.mts +0 -11
- package/dist/utils/scanning/directives.mjs +0 -43
- package/dist/utils/scanning/documents.d.mts +0 -15
- package/dist/utils/scanning/documents.mjs +0 -46
- package/dist/utils/scanning/index.d.mts +0 -6
- package/dist/utils/scanning/index.mjs +0 -7
- package/dist/utils/scanning/resolvers.d.mts +0 -11
- package/dist/utils/scanning/resolvers.mjs +0 -100
- package/dist/utils/scanning/schemas.d.mts +0 -15
- package/dist/utils/scanning/schemas.mjs +0 -29
- package/dist/utils/server-codegen.d.mts +0 -7
- package/dist/utils/server-codegen.mjs +0 -113
- package/dist/utils/type-generation.d.mts +0 -6
- package/dist/utils/type-generation.mjs +0 -7
- package/dist/utils/validation.d.mts +0 -11
- package/dist/virtual/debug-info.d.mts +0 -9
- package/dist/virtual/debug-info.mjs +0 -26
- package/dist/virtual/generators/config.d.mts +0 -22
- package/dist/virtual/generators/config.mjs +0 -36
- package/dist/virtual/generators/debug.d.mts +0 -14
- package/dist/virtual/generators/debug.mjs +0 -53
- package/dist/virtual/generators/directives.d.mts +0 -14
- package/dist/virtual/generators/directives.mjs +0 -52
- package/dist/virtual/generators/index.d.mts +0 -6
- package/dist/virtual/generators/index.mjs +0 -7
- package/dist/virtual/generators/resolvers.d.mts +0 -14
- package/dist/virtual/generators/resolvers.mjs +0 -55
- package/dist/virtual/generators/schemas.d.mts +0 -14
- package/dist/virtual/generators/schemas.mjs +0 -43
- package/dist/virtual/graphql-config.d.mts +0 -9
- package/dist/virtual/graphql-config.mjs +0 -10
- package/dist/virtual/module-config.d.mts +0 -9
- package/dist/virtual/module-config.mjs +0 -10
- package/dist/virtual/server-directives.d.mts +0 -11
- package/dist/virtual/server-directives.mjs +0 -10
- package/dist/virtual/server-resolvers.d.mts +0 -11
- package/dist/virtual/server-resolvers.mjs +0 -10
- package/dist/virtual/server-schemas.d.mts +0 -11
- package/dist/virtual/server-schemas.mjs +0 -10
- /package/dist/{graphql/index.mjs → core/types/adapter.mjs} +0 -0
- /package/dist/{graphql/server.mjs → core/types/codegen.mjs} +0 -0
- /package/dist/{types/define.mjs → core/types/config.mjs} +0 -0
- /package/dist/{types/index.mjs → core/types/define.mjs} +0 -0
- /package/dist/{types/standard-schema.mjs → core/types/index.mjs} +0 -0
|
@@ -1,12 +1,113 @@
|
|
|
1
|
-
import { StandardSchemaV1 } from "./standard-schema.mjs";
|
|
2
1
|
import { TypeScriptPluginConfig } from "@graphql-codegen/typescript";
|
|
3
2
|
import { plugin as plugin$1 } from "@graphql-codegen/typescript-generic-sdk";
|
|
4
3
|
import { TypeScriptDocumentsPluginConfig } from "@graphql-codegen/typescript-operations";
|
|
5
4
|
import { IResolvers } from "@graphql-tools/utils";
|
|
5
|
+
import { GraphQLSchema } from "graphql";
|
|
6
6
|
import { TypeScriptResolversPluginConfig } from "@graphql-codegen/typescript-resolvers";
|
|
7
7
|
import { ESMCodeGenOptions } from "knitwork";
|
|
8
|
+
import { ApolloServerOptions } from "@apollo/server";
|
|
9
|
+
import { H3Event } from "nitro/h3";
|
|
10
|
+
import { YogaServerOptions } from "graphql-yoga";
|
|
11
|
+
import { NPMConfig } from "#graphql/server";
|
|
8
12
|
|
|
9
|
-
//#region src/types
|
|
13
|
+
//#region src/nitro/types.d.ts
|
|
14
|
+
|
|
15
|
+
/** The Standard Schema interface. */
|
|
16
|
+
interface StandardSchemaV1<Input = unknown, Output = Input> {
|
|
17
|
+
/** The Standard Schema properties. */
|
|
18
|
+
readonly '~standard': StandardSchemaV1.Props<Input, Output>;
|
|
19
|
+
}
|
|
20
|
+
declare namespace StandardSchemaV1 {
|
|
21
|
+
/** The Standard Schema properties interface. */
|
|
22
|
+
export interface Props<Input = unknown, Output = Input> {
|
|
23
|
+
/** The version number of the standard. */
|
|
24
|
+
readonly version: 1;
|
|
25
|
+
/** The vendor name of the schema library. */
|
|
26
|
+
readonly vendor: string;
|
|
27
|
+
/** Validates unknown input values. */
|
|
28
|
+
readonly validate: (value: unknown) => Result<Output> | Promise<Result<Output>>;
|
|
29
|
+
/** Inferred types associated with the schema. */
|
|
30
|
+
readonly types?: Types<Input, Output> | undefined;
|
|
31
|
+
}
|
|
32
|
+
/** The result interface of the validate function. */
|
|
33
|
+
export type Result<Output> = SuccessResult<Output> | FailureResult;
|
|
34
|
+
/** The result interface if validation succeeds. */
|
|
35
|
+
export interface SuccessResult<Output> {
|
|
36
|
+
/** The typed output value. */
|
|
37
|
+
readonly value: Output;
|
|
38
|
+
/** The non-existent issues. */
|
|
39
|
+
readonly issues?: undefined;
|
|
40
|
+
}
|
|
41
|
+
/** The result interface if validation fails. */
|
|
42
|
+
export interface FailureResult {
|
|
43
|
+
/** The issues of failed validation. */
|
|
44
|
+
readonly issues: ReadonlyArray<Issue>;
|
|
45
|
+
}
|
|
46
|
+
/** The issue interface of the failure output. */
|
|
47
|
+
export interface Issue {
|
|
48
|
+
/** The error message of the issue. */
|
|
49
|
+
readonly message: string;
|
|
50
|
+
/** The path of the issue, if any. */
|
|
51
|
+
readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined;
|
|
52
|
+
}
|
|
53
|
+
/** The path segment interface of the issue. */
|
|
54
|
+
export interface PathSegment {
|
|
55
|
+
/** The key representing a path segment. */
|
|
56
|
+
readonly key: PropertyKey;
|
|
57
|
+
}
|
|
58
|
+
/** The Standard Schema types interface. */
|
|
59
|
+
export interface Types<Input = unknown, Output = Input> {
|
|
60
|
+
/** The input type of the schema. */
|
|
61
|
+
readonly input: Input;
|
|
62
|
+
/** The output type of the schema. */
|
|
63
|
+
readonly output: Output;
|
|
64
|
+
}
|
|
65
|
+
/** Infers the input type of a Standard Schema. */
|
|
66
|
+
export type InferInput<Schema extends StandardSchemaV1> = NonNullable<Schema['~standard']['types']>['input'];
|
|
67
|
+
/** Infers the output type of a Standard Schema. */
|
|
68
|
+
export type InferOutput<Schema extends StandardSchemaV1> = NonNullable<Schema['~standard']['types']>['output'];
|
|
69
|
+
export {};
|
|
70
|
+
}
|
|
71
|
+
type Flatten<T> = T extends infer U ? { [K in keyof U]: U[K] } : never;
|
|
72
|
+
type DefineServerConfig<T extends NPMConfig = NPMConfig> = T['framework'] extends 'graphql-yoga' ? Partial<YogaServerOptions<H3Event, Partial<H3Event>>> : T['framework'] extends 'apollo-server' ? Partial<ApolloServerOptions<H3Event>> : Partial<YogaServerOptions<H3Event, Partial<H3Event>>> | Partial<ApolloServerOptions<H3Event>>;
|
|
73
|
+
type DirectiveLocationName = 'QUERY' | 'MUTATION' | 'SUBSCRIPTION' | 'FIELD' | 'FRAGMENT_DEFINITION' | 'FRAGMENT_SPREAD' | 'INLINE_FRAGMENT' | 'VARIABLE_DEFINITION' | 'SCHEMA' | 'SCALAR' | 'OBJECT' | 'FIELD_DEFINITION' | 'ARGUMENT_DEFINITION' | 'INTERFACE' | 'UNION' | 'ENUM' | 'ENUM_VALUE' | 'INPUT_OBJECT' | 'INPUT_FIELD_DEFINITION';
|
|
74
|
+
type GraphQLScalarType = 'String' | 'Int' | 'Float' | 'Boolean' | 'ID' | 'JSON' | 'DateTime';
|
|
75
|
+
type GraphQLBaseType = GraphQLScalarType | (string & {});
|
|
76
|
+
type GraphQLArgumentType = 'String' | 'Int' | 'Float' | 'Boolean' | 'ID' | 'JSON' | 'DateTime' | 'String!' | 'Int!' | 'Float!' | 'Boolean!' | 'ID!' | 'JSON!' | 'DateTime!' | '[String]' | '[String!]' | '[String]!' | '[String!]!' | '[Int]' | '[Int!]' | '[Int]!' | '[Int!]!' | '[Float]' | '[Float!]' | '[Float]!' | '[Float!]!' | '[Boolean]' | '[Boolean!]' | '[Boolean]!' | '[Boolean!]!' | '[ID]' | '[ID!]' | '[ID]!' | '[ID!]!' | '[JSON]' | '[JSON!]' | '[JSON]!' | '[JSON!]!' | '[DateTime]' | '[DateTime!]' | '[DateTime]!' | '[DateTime!]!' | (string & {});
|
|
77
|
+
interface DirectiveArgument<T extends GraphQLArgumentType = GraphQLArgumentType> {
|
|
78
|
+
/**
|
|
79
|
+
* GraphQL type for the argument
|
|
80
|
+
* @example 'String', 'Int!', '[String!]!', 'DateTime', 'JSON'
|
|
81
|
+
*/
|
|
82
|
+
type: T;
|
|
83
|
+
defaultValue?: any;
|
|
84
|
+
description?: string;
|
|
85
|
+
}
|
|
86
|
+
interface DirectiveArg {
|
|
87
|
+
type: GraphQLArgumentType;
|
|
88
|
+
defaultValue?: any;
|
|
89
|
+
description?: string;
|
|
90
|
+
}
|
|
91
|
+
interface DirectiveDefinition {
|
|
92
|
+
name: string;
|
|
93
|
+
locations: DirectiveLocationName[];
|
|
94
|
+
args?: Record<string, DirectiveArg>;
|
|
95
|
+
description?: string;
|
|
96
|
+
isRepeatable?: boolean;
|
|
97
|
+
transformer?: (schema: GraphQLSchema) => GraphQLSchema;
|
|
98
|
+
}
|
|
99
|
+
interface DefineDirectiveConfig {
|
|
100
|
+
name: string;
|
|
101
|
+
locations: ReadonlyArray<DirectiveLocationName>;
|
|
102
|
+
args?: Record<string, {
|
|
103
|
+
type: GraphQLArgumentType;
|
|
104
|
+
defaultValue?: any;
|
|
105
|
+
description?: string;
|
|
106
|
+
}>;
|
|
107
|
+
description?: string;
|
|
108
|
+
isRepeatable?: boolean;
|
|
109
|
+
transformer?: (schema: GraphQLSchema) => GraphQLSchema;
|
|
110
|
+
}
|
|
10
111
|
type CodegenServerConfig = TypeScriptPluginConfig & TypeScriptResolversPluginConfig;
|
|
11
112
|
type DocumentModeConfig = Pick<Parameters<typeof plugin$1>[2], 'documentMode'>;
|
|
12
113
|
type DocumentModeEnum = NonNullable<DocumentModeConfig['documentMode']>;
|
|
@@ -73,8 +174,6 @@ interface ExternalServicePaths {
|
|
|
73
174
|
sdk?: FileGenerationConfig;
|
|
74
175
|
/** Type definitions file path (overrides global types.external config) */
|
|
75
176
|
types?: FileGenerationConfig;
|
|
76
|
-
/** ofetch client wrapper path (overrides global clientUtils.ofetch config) */
|
|
77
|
-
ofetch?: FileGenerationConfig;
|
|
78
177
|
}
|
|
79
178
|
interface ExternalGraphQLService {
|
|
80
179
|
/** Unique name for this service (used for file naming and type generation) */
|
|
@@ -129,34 +228,6 @@ interface FederationConfig {
|
|
|
129
228
|
* - string: Generate at custom path (supports placeholders: {serviceName}, {buildDir}, {rootDir}, {framework})
|
|
130
229
|
*/
|
|
131
230
|
type FileGenerationConfig = boolean | string;
|
|
132
|
-
/**
|
|
133
|
-
* Scaffold files configuration
|
|
134
|
-
* Control auto-generation of scaffold/boilerplate files
|
|
135
|
-
*/
|
|
136
|
-
interface ScaffoldConfig {
|
|
137
|
-
/** Enable/disable all scaffold files */
|
|
138
|
-
enabled?: boolean;
|
|
139
|
-
/** graphql.config.ts - GraphQL Config file for IDE tooling */
|
|
140
|
-
graphqlConfig?: FileGenerationConfig;
|
|
141
|
-
/** server/graphql/schema.ts - Schema definition file */
|
|
142
|
-
serverSchema?: FileGenerationConfig;
|
|
143
|
-
/** server/graphql/config.ts - GraphQL server configuration */
|
|
144
|
-
serverConfig?: FileGenerationConfig;
|
|
145
|
-
/** server/graphql/context.ts - H3 context augmentation */
|
|
146
|
-
serverContext?: FileGenerationConfig;
|
|
147
|
-
}
|
|
148
|
-
/**
|
|
149
|
-
* Client utilities configuration
|
|
150
|
-
* Control auto-generation of client-side utility files (Nuxt only)
|
|
151
|
-
*/
|
|
152
|
-
interface ClientUtilsConfig {
|
|
153
|
-
/** Enable/disable all client utilities */
|
|
154
|
-
enabled?: boolean;
|
|
155
|
-
/** app/graphql/index.ts - Main exports file */
|
|
156
|
-
index?: FileGenerationConfig;
|
|
157
|
-
/** app/graphql/{serviceName}/ofetch.ts - ofetch client wrapper */
|
|
158
|
-
ofetch?: FileGenerationConfig;
|
|
159
|
-
}
|
|
160
231
|
/**
|
|
161
232
|
* SDK files configuration
|
|
162
233
|
* Control auto-generation of GraphQL SDK files
|
|
@@ -261,16 +332,6 @@ interface NitroGraphQLOptions {
|
|
|
261
332
|
layerDirectories?: string[];
|
|
262
333
|
layerServerDirs?: string[];
|
|
263
334
|
layerAppDirs?: string[];
|
|
264
|
-
/**
|
|
265
|
-
* Scaffold files configuration
|
|
266
|
-
* Set to false to disable all scaffold file generation (library mode)
|
|
267
|
-
*/
|
|
268
|
-
scaffold?: false | ScaffoldConfig;
|
|
269
|
-
/**
|
|
270
|
-
* Client utilities configuration
|
|
271
|
-
* Set to false to disable all client utility generation
|
|
272
|
-
*/
|
|
273
|
-
clientUtils?: false | ClientUtilsConfig;
|
|
274
335
|
/**
|
|
275
336
|
* SDK files configuration
|
|
276
337
|
* Set to false to disable all SDK generation
|
|
@@ -291,6 +352,27 @@ interface NitroGraphQLOptions {
|
|
|
291
352
|
* Auto-detects NODE_ENV and applies secure defaults in production
|
|
292
353
|
*/
|
|
293
354
|
security?: SecurityConfig;
|
|
355
|
+
/**
|
|
356
|
+
* Extend GraphQL server with external packages
|
|
357
|
+
* Auto-appends /resolvers and /schema to each package path
|
|
358
|
+
* @example extend: ['@myorg/graphql', './generated']
|
|
359
|
+
*/
|
|
360
|
+
extend?: ExtendSource[];
|
|
361
|
+
/**
|
|
362
|
+
* Skip local file scanning, use only extend sources
|
|
363
|
+
* When true, only files from `extend` are used (local server/graphql ignored)
|
|
364
|
+
* @default false
|
|
365
|
+
*/
|
|
366
|
+
skipLocalScan?: boolean;
|
|
294
367
|
}
|
|
368
|
+
/**
|
|
369
|
+
* Extend source - package path or detailed config
|
|
370
|
+
* - string: auto-appends /resolvers and /schema
|
|
371
|
+
* - object: explicit paths for resolvers and/or schemas
|
|
372
|
+
*/
|
|
373
|
+
type ExtendSource = string | {
|
|
374
|
+
resolvers?: string | string[];
|
|
375
|
+
schemas?: string | string[];
|
|
376
|
+
};
|
|
295
377
|
//#endregion
|
|
296
|
-
export {
|
|
378
|
+
export { CodegenClientConfig, CodegenServerConfig, DefineDirectiveConfig, DefineServerConfig, DirectiveArgument, DirectiveDefinition, ExtendSource, ExternalGraphQLService, ExternalServicePaths, FederationConfig, FileGenerationConfig, Flatten, GenImport, GenericSdkConfig, GraphQLArgumentType, GraphQLBaseType, GraphQLScalarType, NitroGraphQLOptions, PathsConfig, SdkConfig, SecurityConfig, StandardSchemaV1, TypesConfig };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Nitro } from "nitro/types";
|
|
2
|
+
|
|
3
|
+
//#region src/nitro/virtual/generators.d.ts
|
|
4
|
+
|
|
5
|
+
declare const serverSchemas: {
|
|
6
|
+
id: string;
|
|
7
|
+
getCode: (nitro: Nitro) => string;
|
|
8
|
+
};
|
|
9
|
+
declare const serverResolvers: {
|
|
10
|
+
id: string;
|
|
11
|
+
getCode: (nitro: Nitro) => string;
|
|
12
|
+
};
|
|
13
|
+
declare const serverDirectives: {
|
|
14
|
+
id: string;
|
|
15
|
+
getCode: (nitro: Nitro) => string;
|
|
16
|
+
};
|
|
17
|
+
declare const graphqlConfig: {
|
|
18
|
+
id: string;
|
|
19
|
+
getCode: (nitro: Nitro) => string;
|
|
20
|
+
};
|
|
21
|
+
declare const moduleConfig: {
|
|
22
|
+
id: string;
|
|
23
|
+
getCode: (nitro: Nitro) => string;
|
|
24
|
+
};
|
|
25
|
+
declare const debugInfo: {
|
|
26
|
+
id: string;
|
|
27
|
+
getCode: (nitro: Nitro) => string;
|
|
28
|
+
};
|
|
29
|
+
declare function registerAllVirtualModules(nitro: Nitro): void;
|
|
30
|
+
//#endregion
|
|
31
|
+
export { debugInfo, graphqlConfig, moduleConfig, registerAllVirtualModules, serverDirectives, serverResolvers, serverSchemas };
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { getImportId } from "../../core/utils/imports.mjs";
|
|
2
|
+
import { isAbsolute, resolve } from "pathe";
|
|
3
|
+
import { genImport } from "knitwork";
|
|
4
|
+
|
|
5
|
+
//#region src/nitro/virtual/generators.ts
|
|
6
|
+
function normalizeExtendConfig(extend) {
|
|
7
|
+
if (!extend || !Array.isArray(extend) || extend.length === 0) return null;
|
|
8
|
+
const resolvers = [];
|
|
9
|
+
const schemas = [];
|
|
10
|
+
for (const source of extend) if (typeof source === "string") {
|
|
11
|
+
resolvers.push(`${source}/resolvers`);
|
|
12
|
+
schemas.push(`${source}/schema`);
|
|
13
|
+
} else if (source && typeof source === "object") {
|
|
14
|
+
const obj = source;
|
|
15
|
+
if (obj.resolvers) {
|
|
16
|
+
const r = Array.isArray(obj.resolvers) ? obj.resolvers : [obj.resolvers];
|
|
17
|
+
resolvers.push(...r);
|
|
18
|
+
}
|
|
19
|
+
if (obj.schemas) {
|
|
20
|
+
const s = Array.isArray(obj.schemas) ? obj.schemas : [obj.schemas];
|
|
21
|
+
schemas.push(...s);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
if (resolvers.length === 0 && schemas.length === 0) return null;
|
|
25
|
+
return {
|
|
26
|
+
resolvers,
|
|
27
|
+
schemas
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Resolve extend path to absolute path
|
|
32
|
+
* Supports: relative paths, absolute paths, package names
|
|
33
|
+
*/
|
|
34
|
+
function resolveExtendPath(nitro, inputPath) {
|
|
35
|
+
if (inputPath.startsWith("@") || !inputPath.startsWith(".") && !inputPath.startsWith("/")) return inputPath;
|
|
36
|
+
if (isAbsolute(inputPath)) return inputPath;
|
|
37
|
+
return resolve(nitro.options.rootDir, inputPath);
|
|
38
|
+
}
|
|
39
|
+
function generateImportModule(items, exportName, wrapperKey) {
|
|
40
|
+
if (!items.length) return `export const ${exportName} = []`;
|
|
41
|
+
const imports = items.flatMap(({ specifier, imports: list, options }) => list?.length ? [genImport(specifier, list, options)] : []);
|
|
42
|
+
const data = items.flatMap(({ imports: list }) => list.map((i) => `{ ${wrapperKey}: ${i.as || i.name} }`));
|
|
43
|
+
return `${imports.join("\n")}\n\nexport const ${exportName} = [\n${data.join(",\n")}\n]`;
|
|
44
|
+
}
|
|
45
|
+
function safeGenerateModuleCode(nitro, moduleName) {
|
|
46
|
+
try {
|
|
47
|
+
const generator = nitro.options.virtual?.[moduleName];
|
|
48
|
+
if (generator && typeof generator === "function") return generator();
|
|
49
|
+
return "// Module not found";
|
|
50
|
+
} catch (error) {
|
|
51
|
+
return `// Error: ${error instanceof Error ? error.message : String(error)}`;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
const serverSchemas = {
|
|
55
|
+
id: "#nitro-graphql/server-schemas",
|
|
56
|
+
getCode: (nitro) => {
|
|
57
|
+
const ext = normalizeExtendConfig(nitro.options.graphql?.extend);
|
|
58
|
+
const skipLocalScan = nitro.options.graphql?.skipLocalScan === true;
|
|
59
|
+
if (ext && ext.schemas.length > 0) {
|
|
60
|
+
const schemaPaths = ext.schemas.map((p) => resolveExtendPath(nitro, p));
|
|
61
|
+
const scannedSchemas = [...nitro.scanSchemas, ...nitro.options.graphql?.typedefs ?? []];
|
|
62
|
+
if (!skipLocalScan && scannedSchemas.length > 0) {
|
|
63
|
+
const extImports = schemaPaths.map((p, i) => `import { schemaString as extSchema${i} } from '${p}'`);
|
|
64
|
+
const scannedImports = scannedSchemas.map((s) => `import ${getImportId(s)} from '${s}';`);
|
|
65
|
+
const extDefs = schemaPaths.map((_, i) => `{ def: extSchema${i} }`);
|
|
66
|
+
const scannedDefs = scannedSchemas.map((s) => `{ def: ${getImportId(s)} }`);
|
|
67
|
+
return `${extImports.join("\n")}
|
|
68
|
+
${scannedImports.join("\n")}
|
|
69
|
+
|
|
70
|
+
export const schemas = [
|
|
71
|
+
${[...extDefs, ...scannedDefs].join(",\n")}
|
|
72
|
+
]`;
|
|
73
|
+
}
|
|
74
|
+
if (schemaPaths.length === 1) return `import { schemaString, typeDefs } from '${schemaPaths[0]}'
|
|
75
|
+
export { schemaString, typeDefs }
|
|
76
|
+
export const schemas = [{ def: schemaString }]`;
|
|
77
|
+
const imports = schemaPaths.map((p, i) => `import { schemaString as schema${i} } from '${p}'`);
|
|
78
|
+
const schemaVars = schemaPaths.map((_, i) => `schema${i}`);
|
|
79
|
+
const mergeCode = `export const schemaString = [${schemaVars.join(", ")}].join('\\n\\n')
|
|
80
|
+
import { parse } from 'graphql'
|
|
81
|
+
export const typeDefs = parse(schemaString)
|
|
82
|
+
export const schemas = [${schemaVars.map((v) => `{ def: ${v} }`).join(", ")}]`;
|
|
83
|
+
return `${imports.join("\n")}\n\n${mergeCode}`;
|
|
84
|
+
}
|
|
85
|
+
const schemas = [...nitro.scanSchemas, ...nitro.options.graphql?.typedefs ?? []];
|
|
86
|
+
if (!schemas.length) {
|
|
87
|
+
if (nitro.options.dev) nitro.logger.warn("[nitro-graphql] No schemas found. Virtual module will export empty array.");
|
|
88
|
+
return "export const schemas = []";
|
|
89
|
+
}
|
|
90
|
+
const importStatements = schemas.map((s) => `import ${getImportId(s)} from '${s}';`);
|
|
91
|
+
const schemaArray = schemas.map((s) => `{ def: ${getImportId(s)} }`);
|
|
92
|
+
return `${importStatements.join("\n")}\n\nexport const schemas = [\n${schemaArray.join(",\n")}\n];`;
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
const serverResolvers = {
|
|
96
|
+
id: "#nitro-graphql/server-resolvers",
|
|
97
|
+
getCode: (nitro) => {
|
|
98
|
+
const ext = normalizeExtendConfig(nitro.options.graphql?.extend);
|
|
99
|
+
const skipLocalScan = nitro.options.graphql?.skipLocalScan === true;
|
|
100
|
+
if (ext && ext.resolvers.length > 0) {
|
|
101
|
+
const resolverPaths = ext.resolvers.map((p) => resolveExtendPath(nitro, p));
|
|
102
|
+
const imports$1 = resolverPaths.map((p, i) => `import { resolvers as resolvers${i} } from '${p}'`);
|
|
103
|
+
if (!skipLocalScan && nitro.scanResolvers.length > 0) {
|
|
104
|
+
const scannedCode = generateImportModule(nitro.scanResolvers, "scannedResolvers", "resolver");
|
|
105
|
+
const spreadAll$1 = [...resolverPaths.map((_, i) => `...resolvers${i}`), "...scannedResolvers"];
|
|
106
|
+
return `${imports$1.join("\n")}
|
|
107
|
+
${scannedCode}
|
|
108
|
+
|
|
109
|
+
export const resolvers = [${spreadAll$1.join(", ")}]`;
|
|
110
|
+
}
|
|
111
|
+
if (resolverPaths.length === 1) return `export { resolvers } from '${resolverPaths[0]}'`;
|
|
112
|
+
const spreadAll = resolverPaths.map((_, i) => `...resolvers${i}`);
|
|
113
|
+
return `${imports$1.join("\n")}
|
|
114
|
+
|
|
115
|
+
export const resolvers = [${spreadAll.join(", ")}]`;
|
|
116
|
+
}
|
|
117
|
+
const imports = [...nitro.scanResolvers];
|
|
118
|
+
if (!imports.length) {
|
|
119
|
+
if (nitro.options.dev) nitro.logger.warn("[nitro-graphql] No resolvers found. Virtual module will export empty array.");
|
|
120
|
+
return "export const resolvers = []";
|
|
121
|
+
}
|
|
122
|
+
return generateImportModule(imports, "resolvers", "resolver");
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
const serverDirectives = {
|
|
126
|
+
id: "#nitro-graphql/server-directives",
|
|
127
|
+
getCode: (nitro) => {
|
|
128
|
+
const imports = nitro.scanDirectives || [];
|
|
129
|
+
if (!imports.length) return "export const directives = []";
|
|
130
|
+
return generateImportModule(imports, "directives", "directive");
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
const graphqlConfig = {
|
|
134
|
+
id: "#nitro-graphql/graphql-config",
|
|
135
|
+
getCode: (nitro) => {
|
|
136
|
+
return `import config from '${resolve(nitro.graphql.serverDir, "config.ts")}'
|
|
137
|
+
const importedConfig = config
|
|
138
|
+
export { importedConfig }
|
|
139
|
+
`;
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
const moduleConfig = {
|
|
143
|
+
id: "#nitro-graphql/module-config",
|
|
144
|
+
getCode: (nitro) => {
|
|
145
|
+
const config = nitro.options.graphql || {};
|
|
146
|
+
return `export const moduleConfig = ${JSON.stringify(config, null, 2)};`;
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
const debugInfo = {
|
|
150
|
+
id: "#nitro-graphql/debug-info",
|
|
151
|
+
getCode: (nitro) => {
|
|
152
|
+
const virtualModuleCodes = {
|
|
153
|
+
"server-schemas": safeGenerateModuleCode(nitro, "#nitro-graphql/server-schemas"),
|
|
154
|
+
"server-resolvers": safeGenerateModuleCode(nitro, "#nitro-graphql/server-resolvers"),
|
|
155
|
+
"server-directives": safeGenerateModuleCode(nitro, "#nitro-graphql/server-directives"),
|
|
156
|
+
"module-config": safeGenerateModuleCode(nitro, "#nitro-graphql/module-config"),
|
|
157
|
+
"graphql-config": safeGenerateModuleCode(nitro, "#nitro-graphql/graphql-config")
|
|
158
|
+
};
|
|
159
|
+
const info = {
|
|
160
|
+
isDev: nitro.options.dev,
|
|
161
|
+
framework: nitro.options.framework.name,
|
|
162
|
+
graphqlFramework: nitro.options.graphql?.framework,
|
|
163
|
+
federation: nitro.options.graphql?.federation,
|
|
164
|
+
scanned: {
|
|
165
|
+
schemas: nitro.scanSchemas?.length || 0,
|
|
166
|
+
schemaFiles: nitro.scanSchemas || [],
|
|
167
|
+
resolvers: nitro.scanResolvers?.length || 0,
|
|
168
|
+
resolverFiles: nitro.scanResolvers || [],
|
|
169
|
+
directives: nitro.scanDirectives?.length || 0,
|
|
170
|
+
directiveFiles: nitro.scanDirectives || [],
|
|
171
|
+
documents: nitro.scanDocuments?.length || 0,
|
|
172
|
+
documentFiles: nitro.scanDocuments || []
|
|
173
|
+
},
|
|
174
|
+
virtualModules: virtualModuleCodes
|
|
175
|
+
};
|
|
176
|
+
return `export const debugInfo = ${JSON.stringify(info, null, 2)};`;
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
const allModules = [
|
|
180
|
+
serverSchemas,
|
|
181
|
+
serverResolvers,
|
|
182
|
+
serverDirectives,
|
|
183
|
+
graphqlConfig,
|
|
184
|
+
moduleConfig,
|
|
185
|
+
debugInfo
|
|
186
|
+
];
|
|
187
|
+
function registerAllVirtualModules(nitro) {
|
|
188
|
+
nitro.options.virtual ??= {};
|
|
189
|
+
for (const mod of allModules) nitro.options.virtual[mod.id] = () => mod.getCode(nitro);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
//#endregion
|
|
193
|
+
export { debugInfo, graphqlConfig, moduleConfig, registerAllVirtualModules, serverDirectives, serverResolvers, serverSchemas };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
//#region src/nitro/virtual/stubs.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Virtual module stubs for #nitro-graphql/*
|
|
4
|
+
* Used during build to prevent import resolution errors.
|
|
5
|
+
* At runtime, Nitro overrides these with actual virtual modules.
|
|
6
|
+
*/
|
|
7
|
+
declare const schemas: Array<{
|
|
8
|
+
def: string;
|
|
9
|
+
}>;
|
|
10
|
+
declare const resolvers: Array<{
|
|
11
|
+
resolver: any;
|
|
12
|
+
}>;
|
|
13
|
+
declare const directives: Array<{
|
|
14
|
+
directive: any;
|
|
15
|
+
}>;
|
|
16
|
+
declare const moduleConfig: {};
|
|
17
|
+
declare const importedConfig: {};
|
|
18
|
+
declare const debugInfo: Record<string, any>;
|
|
19
|
+
//#endregion
|
|
20
|
+
export { debugInfo, directives, importedConfig, moduleConfig, resolvers, schemas };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
//#region src/nitro/virtual/stubs.ts
|
|
2
|
+
/**
|
|
3
|
+
* Virtual module stubs for #nitro-graphql/*
|
|
4
|
+
* Used during build to prevent import resolution errors.
|
|
5
|
+
* At runtime, Nitro overrides these with actual virtual modules.
|
|
6
|
+
*/
|
|
7
|
+
const schemas = [];
|
|
8
|
+
const resolvers = [];
|
|
9
|
+
const directives = [];
|
|
10
|
+
const moduleConfig = {};
|
|
11
|
+
const importedConfig = {};
|
|
12
|
+
const debugInfo = {
|
|
13
|
+
isDev: false,
|
|
14
|
+
framework: "",
|
|
15
|
+
graphqlFramework: "",
|
|
16
|
+
federation: {},
|
|
17
|
+
scanned: {
|
|
18
|
+
schemas: 0,
|
|
19
|
+
schemaFiles: [],
|
|
20
|
+
resolvers: 0,
|
|
21
|
+
resolverFiles: [],
|
|
22
|
+
directives: 0,
|
|
23
|
+
directiveFiles: [],
|
|
24
|
+
documents: 0,
|
|
25
|
+
documentFiles: []
|
|
26
|
+
},
|
|
27
|
+
virtualModules: {}
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
//#endregion
|
|
31
|
+
export { debugInfo, directives, importedConfig, moduleConfig, resolvers, schemas };
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { getDefaultPaths, getTypesConfig, resolveFilePath } from "
|
|
1
|
+
import { getDefaultPaths, getTypesConfig, resolveFilePath } from "./nitro/paths.mjs";
|
|
2
2
|
import { dirname, join, relative, resolve } from "pathe";
|
|
3
3
|
import { existsSync, mkdirSync, writeFileSync } from "node:fs";
|
|
4
4
|
import { defineNuxtModule, getLayerDirectories } from "@nuxt/kit";
|
|
5
5
|
|
|
6
|
-
//#region src/
|
|
6
|
+
//#region src/nuxt.ts
|
|
7
7
|
var nuxt_default = defineNuxtModule({
|
|
8
8
|
meta: {
|
|
9
9
|
name: "nitro-graphql-nuxt",
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
//#region src/
|
|
1
|
+
//#region src/stubs/index.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Runtime type stubs for GraphQL types
|
|
4
|
+
* These interfaces are replaced by generated types at build time
|
|
5
|
+
*/
|
|
2
6
|
interface StandardSchemaV1 extends Record<string, any> {}
|
|
3
7
|
interface ResolversTypes extends Record<string, any> {}
|
|
4
8
|
interface Resolvers extends Record<string, any> {}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|