nitro-graphql 2.0.0-beta.4 → 2.0.0-beta.41
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 +438 -27
- 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 +46 -0
- package/dist/cli/commands/init.mjs +195 -0
- package/dist/cli/commands/validate.d.mts +10 -0
- package/dist/cli/commands/validate.mjs +69 -0
- package/dist/cli/completions.d.mts +7 -0
- package/dist/cli/completions.mjs +34 -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 +253 -0
- package/dist/config.d.mts +2 -0
- package/dist/config.mjs +3 -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/core/codegen/plugin.d.mts +20 -0
- package/dist/core/codegen/plugin.mjs +30 -0
- 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/core/codegen/validation.d.mts +13 -0
- package/dist/core/codegen/validation.mjs +96 -0
- 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 +33 -0
- package/dist/core/index.mjs +27 -0
- package/dist/core/manifest.d.mts +46 -0
- package/dist/core/manifest.mjs +76 -0
- package/dist/core/scanning/ast-scanner.d.mts +28 -0
- package/dist/core/scanning/ast-scanner.mjs +122 -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 +15 -0
- package/dist/core/scanning/resolvers.mjs +59 -0
- package/dist/core/scanning/schemas.d.mts +14 -0
- package/dist/core/scanning/schemas.mjs +64 -0
- package/dist/core/schema/builder.d.mts +53 -0
- package/dist/core/schema/builder.mjs +70 -0
- package/dist/core/schema/federation.d.mts +34 -0
- package/dist/core/schema/federation.mjs +40 -0
- 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 +210 -0
- package/dist/core/types/config.mjs +1 -0
- package/dist/{utils/define.d.ts → core/types/define.d.mts} +3 -30
- package/dist/core/types/define.mjs +1 -0
- package/dist/core/types/index.d.mts +5 -0
- package/dist/core/types/index.mjs +1 -0
- package/dist/core/types/scanning.d.mts +69 -0
- package/dist/core/types/scanning.mjs +1 -0
- package/dist/{utils/directive-parser.d.ts → core/utils/directive-parser.d.mts} +21 -4
- package/dist/{utils/directive-parser.js → core/utils/directive-parser.mjs} +25 -34
- package/dist/core/utils/errors.d.mts +77 -0
- package/dist/core/utils/errors.mjs +93 -0
- package/dist/core/utils/file-io.d.mts +24 -0
- package/dist/core/utils/file-io.mjs +47 -0
- package/dist/core/utils/imports.d.mts +15 -0
- package/dist/core/utils/imports.mjs +25 -0
- 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/core/utils/ofetch-templates.d.mts +30 -0
- package/dist/core/utils/ofetch-templates.mjs +135 -0
- package/dist/core/validation/external-services.d.mts +11 -0
- package/dist/core/validation/external-services.mjs +34 -0
- package/dist/core/validation/index.d.mts +2 -0
- package/dist/core/validation/index.mjs +3 -0
- package/dist/define.d.mts +294 -0
- package/dist/define.mjs +323 -0
- package/dist/index.d.mts +6 -0
- package/dist/index.mjs +6 -0
- package/dist/nitro/adapter.d.mts +30 -0
- package/dist/nitro/adapter.mjs +97 -0
- package/dist/{utils/apollo.d.ts → nitro/apollo.d.mts} +3 -3
- package/dist/nitro/apollo.mjs +59 -0
- package/dist/nitro/codegen.d.mts +19 -0
- package/dist/nitro/codegen.mjs +141 -0
- package/dist/nitro/config.d.mts +51 -0
- package/dist/nitro/config.mjs +57 -0
- package/dist/nitro/index.d.mts +46 -0
- package/dist/nitro/index.mjs +65 -0
- package/dist/nitro/paths.d.mts +54 -0
- package/dist/nitro/paths.mjs +92 -0
- package/dist/nitro/rollup.d.mts +6 -0
- package/dist/nitro/rollup.mjs +95 -0
- package/dist/nitro/routes/apollo-server.d.mts +6 -0
- package/dist/nitro/routes/apollo-server.mjs +71 -0
- package/dist/nitro/routes/debug-template.d.mts +15 -0
- package/dist/nitro/routes/debug-template.mjs +385 -0
- package/dist/nitro/routes/debug.d.mts +55 -0
- package/dist/nitro/routes/debug.mjs +102 -0
- package/dist/nitro/routes/graphql-yoga.d.mts +6 -0
- package/dist/nitro/routes/graphql-yoga.mjs +62 -0
- package/dist/nitro/routes/health.d.mts +10 -0
- package/dist/{routes/health.js → nitro/routes/health.mjs} +4 -3
- package/dist/nitro/setup/extend-loader.d.mts +19 -0
- package/dist/nitro/setup/extend-loader.mjs +129 -0
- package/dist/nitro/setup/file-watcher.d.mts +16 -0
- package/dist/nitro/setup/file-watcher.mjs +98 -0
- package/dist/nitro/setup/logging.d.mts +17 -0
- package/dist/nitro/setup/logging.mjs +66 -0
- package/dist/nitro/setup/rollup-integration.d.mts +16 -0
- package/dist/nitro/setup/rollup-integration.mjs +90 -0
- 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/nitro/setup/ts-config.mjs +69 -0
- package/dist/nitro/setup.d.mts +12 -0
- package/dist/nitro/setup.mjs +234 -0
- package/dist/nitro/types.d.mts +374 -0
- package/dist/nitro/types.mjs +1 -0
- package/dist/nitro/virtual/generators.d.mts +31 -0
- package/dist/nitro/virtual/generators.mjs +113 -0
- package/dist/nitro/virtual/stubs.d.mts +20 -0
- package/dist/nitro/virtual/stubs.mjs +31 -0
- package/dist/{ecosystem/nuxt.d.ts → nuxt.d.mts} +1 -1
- package/dist/nuxt.mjs +109 -0
- package/dist/{graphql/server.d.ts → stubs/index.d.mts} +5 -1
- package/dist/stubs/index.mjs +1 -0
- package/package.json +102 -77
- package/dist/ecosystem/nuxt.js +0 -67
- package/dist/graphql/index.d.ts +0 -5
- package/dist/index.d.ts +0 -8
- package/dist/index.js +0 -264
- package/dist/rollup.js +0 -119
- package/dist/routes/apollo-server.d.ts +0 -6
- package/dist/routes/apollo-server.js +0 -89
- package/dist/routes/graphql-yoga.d.ts +0 -6
- package/dist/routes/graphql-yoga.js +0 -91
- package/dist/routes/health.d.ts +0 -6
- package/dist/types/index.d.ts +0 -128
- package/dist/types/standard-schema.d.ts +0 -59
- package/dist/utils/apollo.js +0 -61
- package/dist/utils/client-codegen.d.ts +0 -38
- package/dist/utils/client-codegen.js +0 -290
- package/dist/utils/define.js +0 -57
- package/dist/utils/index.d.ts +0 -39
- package/dist/utils/index.js +0 -250
- package/dist/utils/server-codegen.d.ts +0 -7
- package/dist/utils/server-codegen.js +0 -136
- package/dist/utils/type-generation.d.ts +0 -7
- package/dist/utils/type-generation.js +0 -287
- package/dist/vite.d.ts +0 -25
- package/dist/vite.js +0 -40
- /package/dist/{graphql/index.js → core/types/adapter.mjs} +0 -0
- /package/dist/{graphql/server.js → core/types/codegen.mjs} +0 -0
|
@@ -0,0 +1,374 @@
|
|
|
1
|
+
import { TypeScriptPluginConfig } from "@graphql-codegen/typescript";
|
|
2
|
+
import { plugin as plugin$1 } from "@graphql-codegen/typescript-generic-sdk";
|
|
3
|
+
import { TypeScriptDocumentsPluginConfig } from "@graphql-codegen/typescript-operations";
|
|
4
|
+
import { IResolvers } from "@graphql-tools/utils";
|
|
5
|
+
import { GraphQLSchema } from "graphql";
|
|
6
|
+
import { TypeScriptResolversPluginConfig } from "@graphql-codegen/typescript-resolvers";
|
|
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";
|
|
12
|
+
|
|
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
|
+
}
|
|
111
|
+
type CodegenServerConfig = TypeScriptPluginConfig & TypeScriptResolversPluginConfig;
|
|
112
|
+
type DocumentModeConfig = Pick<Parameters<typeof plugin$1>[2], 'documentMode'>;
|
|
113
|
+
type DocumentModeEnum = NonNullable<DocumentModeConfig['documentMode']>;
|
|
114
|
+
type DocumentModeType = `${DocumentModeEnum}`;
|
|
115
|
+
type GenericSdkConfig = Omit<Parameters<typeof plugin$1>[2], 'documentMode'> & {
|
|
116
|
+
documentMode?: DocumentModeType;
|
|
117
|
+
};
|
|
118
|
+
type CodegenClientConfig = TypeScriptPluginConfig & TypeScriptDocumentsPluginConfig & {
|
|
119
|
+
endpoint?: string;
|
|
120
|
+
/**
|
|
121
|
+
* Generate TypedDocumentNode exports for urql/Apollo Client compatibility.
|
|
122
|
+
* When enabled, generates typed document constants that can be used with
|
|
123
|
+
* any GraphQL client that supports TypedDocumentNode.
|
|
124
|
+
* @default false
|
|
125
|
+
*/
|
|
126
|
+
typedDocumentNode?: boolean;
|
|
127
|
+
};
|
|
128
|
+
interface IESMImport {
|
|
129
|
+
name: string;
|
|
130
|
+
as?: string;
|
|
131
|
+
type: 'resolver' | 'query' | 'mutation' | 'type' | 'subscription' | 'directive';
|
|
132
|
+
}
|
|
133
|
+
interface GenImport {
|
|
134
|
+
specifier: string;
|
|
135
|
+
imports: IESMImport[];
|
|
136
|
+
options?: ESMCodeGenOptions;
|
|
137
|
+
}
|
|
138
|
+
declare module 'nitro/types' {
|
|
139
|
+
interface Nitro {
|
|
140
|
+
scanSchemas: string[];
|
|
141
|
+
scanDocuments: string[];
|
|
142
|
+
scanResolvers: GenImport[];
|
|
143
|
+
scanDirectives: GenImport[];
|
|
144
|
+
graphql: {
|
|
145
|
+
buildDir: string;
|
|
146
|
+
watchDirs: string[];
|
|
147
|
+
clientDir: string;
|
|
148
|
+
serverDir: string;
|
|
149
|
+
dir: {
|
|
150
|
+
build: string;
|
|
151
|
+
client: string;
|
|
152
|
+
server: string;
|
|
153
|
+
};
|
|
154
|
+
/** Resolved extend paths from manifests (populated during setup) */
|
|
155
|
+
resolvedExtend?: {
|
|
156
|
+
schemas: string[];
|
|
157
|
+
resolvers: string[];
|
|
158
|
+
directives: string[];
|
|
159
|
+
};
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
declare module 'nitro/types' {
|
|
164
|
+
interface NitroOptions {
|
|
165
|
+
graphql?: NitroGraphQLOptions;
|
|
166
|
+
}
|
|
167
|
+
interface NitroRuntimeConfig {
|
|
168
|
+
graphql?: NitroGraphQLOptions;
|
|
169
|
+
}
|
|
170
|
+
interface NitroConfig {
|
|
171
|
+
graphql?: NitroGraphQLOptions;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Service-specific path overrides for external GraphQL services
|
|
176
|
+
* These paths override global config for this specific service
|
|
177
|
+
*/
|
|
178
|
+
interface ExternalServicePaths {
|
|
179
|
+
/** SDK file path (overrides global sdk.external config) */
|
|
180
|
+
sdk?: FileGenerationConfig;
|
|
181
|
+
/** Type definitions file path (overrides global types.external config) */
|
|
182
|
+
types?: FileGenerationConfig;
|
|
183
|
+
}
|
|
184
|
+
interface ExternalGraphQLService {
|
|
185
|
+
/** Unique name for this service (used for file naming and type generation) */
|
|
186
|
+
name: string;
|
|
187
|
+
/** GraphQL endpoint for this service (also used as schema source if `schema` is not specified) */
|
|
188
|
+
endpoint: string;
|
|
189
|
+
/**
|
|
190
|
+
* Schema source - can be URL(s) for remote schemas or file path(s) for local schemas
|
|
191
|
+
* @default Uses `endpoint` for introspection if not specified
|
|
192
|
+
*/
|
|
193
|
+
schema?: string | string[];
|
|
194
|
+
/** Optional headers for schema introspection and client requests */
|
|
195
|
+
headers?: Record<string, string> | (() => Record<string, string>);
|
|
196
|
+
/** Optional: specific document patterns for this service */
|
|
197
|
+
documents?: string[];
|
|
198
|
+
/**
|
|
199
|
+
* Optional: Download and cache schema locally for offline usage
|
|
200
|
+
* - true or 'once': Download if file doesn't exist, then use cached version (offline-friendly)
|
|
201
|
+
* - 'always': Check for updates on every build (current behavior)
|
|
202
|
+
* - 'manual': Never download automatically, user manages schema files manually
|
|
203
|
+
* - false: Disable schema downloading
|
|
204
|
+
*/
|
|
205
|
+
downloadSchema?: boolean | 'once' | 'always' | 'manual';
|
|
206
|
+
/** Optional: Custom path to save downloaded schema (default: .nitro/graphql/schemas/[serviceName].graphql) */
|
|
207
|
+
downloadPath?: string;
|
|
208
|
+
/** Optional: service-specific codegen configuration */
|
|
209
|
+
codegen?: {
|
|
210
|
+
client?: CodegenClientConfig;
|
|
211
|
+
clientSDK?: GenericSdkConfig;
|
|
212
|
+
};
|
|
213
|
+
/**
|
|
214
|
+
* Optional: Service-specific path overrides
|
|
215
|
+
* These paths take precedence over global config (sdk, types, clientUtils)
|
|
216
|
+
* Supports placeholders: {serviceName}, {buildDir}, {rootDir}, {framework}, {typesDir}, {clientDir}
|
|
217
|
+
*/
|
|
218
|
+
paths?: ExternalServicePaths;
|
|
219
|
+
}
|
|
220
|
+
interface FederationConfig {
|
|
221
|
+
/** Enable Apollo Federation subgraph support */
|
|
222
|
+
enabled: boolean;
|
|
223
|
+
/** Service name for federation (used in subgraph config) */
|
|
224
|
+
serviceName?: string;
|
|
225
|
+
/** Service version for federation */
|
|
226
|
+
serviceVersion?: string;
|
|
227
|
+
/** Service URL for federation gateway */
|
|
228
|
+
serviceUrl?: string;
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* File generation control:
|
|
232
|
+
* - false: Do not generate this file
|
|
233
|
+
* - true: Generate at default location
|
|
234
|
+
* - string: Generate at custom path (supports placeholders: {serviceName}, {buildDir}, {rootDir}, {framework})
|
|
235
|
+
*/
|
|
236
|
+
type FileGenerationConfig = boolean | string;
|
|
237
|
+
/**
|
|
238
|
+
* SDK files configuration
|
|
239
|
+
* Control auto-generation of GraphQL SDK files
|
|
240
|
+
*/
|
|
241
|
+
interface SdkConfig {
|
|
242
|
+
/** Enable/disable all SDK files */
|
|
243
|
+
enabled?: boolean;
|
|
244
|
+
/** app/graphql/default/sdk.ts - Main service SDK */
|
|
245
|
+
main?: FileGenerationConfig;
|
|
246
|
+
/** app/graphql/{serviceName}/sdk.ts - External service SDKs */
|
|
247
|
+
external?: FileGenerationConfig;
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Type files configuration
|
|
251
|
+
* Control auto-generation of TypeScript type definition files
|
|
252
|
+
*/
|
|
253
|
+
interface TypesConfig {
|
|
254
|
+
/** Enable/disable all type files */
|
|
255
|
+
enabled?: boolean;
|
|
256
|
+
/** .nitro/types/nitro-graphql-server.d.ts - Server-side types */
|
|
257
|
+
server?: FileGenerationConfig;
|
|
258
|
+
/** .nitro/types/nitro-graphql-client.d.ts - Client-side types */
|
|
259
|
+
client?: FileGenerationConfig;
|
|
260
|
+
/** .nitro/types/nitro-graphql-client-{serviceName}.d.ts - External service types */
|
|
261
|
+
external?: FileGenerationConfig;
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Security configuration for production environments
|
|
265
|
+
* All options auto-detect based on NODE_ENV when not explicitly set
|
|
266
|
+
*/
|
|
267
|
+
interface SecurityConfig {
|
|
268
|
+
/**
|
|
269
|
+
* Enable GraphQL introspection queries
|
|
270
|
+
* @default true in development, false in production
|
|
271
|
+
*/
|
|
272
|
+
introspection?: boolean;
|
|
273
|
+
/**
|
|
274
|
+
* Enable GraphQL playground/sandbox UI
|
|
275
|
+
* @default true in development, false in production
|
|
276
|
+
*/
|
|
277
|
+
playground?: boolean;
|
|
278
|
+
/**
|
|
279
|
+
* Mask internal error details in responses
|
|
280
|
+
* When enabled, internal errors show "Internal server error" instead of actual message
|
|
281
|
+
* @default false in development, true in production
|
|
282
|
+
*/
|
|
283
|
+
maskErrors?: boolean;
|
|
284
|
+
/**
|
|
285
|
+
* Disable "Did you mean X?" field suggestions in error messages
|
|
286
|
+
* Prevents attackers from discovering field names via brute force
|
|
287
|
+
* @default false in development, true in production
|
|
288
|
+
*/
|
|
289
|
+
disableSuggestions?: boolean;
|
|
290
|
+
}
|
|
291
|
+
interface NitroGraphQLOptions {
|
|
292
|
+
framework?: 'graphql-yoga' | 'apollo-server';
|
|
293
|
+
/**
|
|
294
|
+
* Enable/disable GraphQL server functionality
|
|
295
|
+
* When set to false, only external services client types will be generated
|
|
296
|
+
* Server routes, resolvers, schemas, and directives will not be processed
|
|
297
|
+
* @default true
|
|
298
|
+
*/
|
|
299
|
+
server?: boolean;
|
|
300
|
+
endpoint?: {
|
|
301
|
+
graphql?: string;
|
|
302
|
+
healthCheck?: string;
|
|
303
|
+
};
|
|
304
|
+
playground?: boolean;
|
|
305
|
+
typedefs?: string[];
|
|
306
|
+
resolvers?: Array<IResolvers<any, any>>;
|
|
307
|
+
loader?: {
|
|
308
|
+
include?: RegExp;
|
|
309
|
+
exclude?: RegExp;
|
|
310
|
+
validate?: boolean;
|
|
311
|
+
};
|
|
312
|
+
codegen?: {
|
|
313
|
+
server?: CodegenServerConfig;
|
|
314
|
+
client?: CodegenClientConfig;
|
|
315
|
+
clientSDK?: GenericSdkConfig;
|
|
316
|
+
};
|
|
317
|
+
/** External GraphQL services to generate types and SDKs for */
|
|
318
|
+
externalServices?: ExternalGraphQLService[];
|
|
319
|
+
/** Apollo Federation configuration */
|
|
320
|
+
federation?: FederationConfig;
|
|
321
|
+
/** Server GraphQL directory path (default: 'server/graphql') */
|
|
322
|
+
serverDir?: string;
|
|
323
|
+
/** Client GraphQL directory path (default: 'app/graphql' for Nuxt, 'graphql' for Nitro) */
|
|
324
|
+
clientDir?: string;
|
|
325
|
+
/** Types directory path (default: '{buildDir}/types') */
|
|
326
|
+
typesDir?: string;
|
|
327
|
+
/** Layer directories (populated by Nuxt module) */
|
|
328
|
+
layerDirectories?: string[];
|
|
329
|
+
layerServerDirs?: string[];
|
|
330
|
+
layerAppDirs?: string[];
|
|
331
|
+
/**
|
|
332
|
+
* SDK files configuration
|
|
333
|
+
* Set to false to disable all SDK generation
|
|
334
|
+
*/
|
|
335
|
+
sdk?: false | SdkConfig;
|
|
336
|
+
/**
|
|
337
|
+
* Type files configuration
|
|
338
|
+
* Set to false to disable all type generation
|
|
339
|
+
*/
|
|
340
|
+
types?: false | TypesConfig;
|
|
341
|
+
/**
|
|
342
|
+
* Security configuration for production environments
|
|
343
|
+
* Auto-detects NODE_ENV and applies secure defaults in production
|
|
344
|
+
*/
|
|
345
|
+
security?: SecurityConfig;
|
|
346
|
+
/**
|
|
347
|
+
* Extend GraphQL server with external packages
|
|
348
|
+
* Auto-appends /resolvers and /schema to each package path
|
|
349
|
+
* @example extend: ['@myorg/graphql', './generated']
|
|
350
|
+
*/
|
|
351
|
+
extend?: ExtendSource[];
|
|
352
|
+
/**
|
|
353
|
+
* Skip local file scanning, use only extend sources
|
|
354
|
+
* When true, only files from `extend` are used (local server/graphql ignored)
|
|
355
|
+
* @default false
|
|
356
|
+
*/
|
|
357
|
+
skipLocalScan?: boolean;
|
|
358
|
+
}
|
|
359
|
+
/**
|
|
360
|
+
* Extend source - package path or detailed config
|
|
361
|
+
* - string: package name, requires graphql-manifest.json in package root
|
|
362
|
+
* - object with manifest: explicit manifest path
|
|
363
|
+
* - object with resolvers/schemas: explicit paths (legacy)
|
|
364
|
+
*/
|
|
365
|
+
type ExtendSource = string | {
|
|
366
|
+
/** Explicit manifest path */
|
|
367
|
+
manifest?: string;
|
|
368
|
+
/** Explicit resolver paths (legacy, prefer manifest) */
|
|
369
|
+
resolvers?: string | string[];
|
|
370
|
+
/** Explicit schema paths (legacy, prefer manifest) */
|
|
371
|
+
schemas?: string | string[];
|
|
372
|
+
};
|
|
373
|
+
//#endregion
|
|
374
|
+
export { CodegenClientConfig, CodegenServerConfig, DefineDirectiveConfig, DefineServerConfig, DirectiveArgument, DirectiveDefinition, ExtendSource, ExternalGraphQLService, ExternalServicePaths, FederationConfig, FileGenerationConfig, Flatten, GenImport, GenericSdkConfig, GraphQLArgumentType, GraphQLBaseType, GraphQLScalarType, NitroGraphQLOptions, 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,113 @@
|
|
|
1
|
+
import { getImportId } from "../../core/utils/imports.mjs";
|
|
2
|
+
import { resolve } from "pathe";
|
|
3
|
+
import { genImport } from "knitwork";
|
|
4
|
+
|
|
5
|
+
//#region src/nitro/virtual/generators.ts
|
|
6
|
+
function generateImportModule(items, exportName, wrapperKey) {
|
|
7
|
+
if (!items.length) return `export const ${exportName} = []`;
|
|
8
|
+
const imports = items.flatMap(({ specifier, imports: list, options }) => list?.length ? [genImport(specifier, list, options)] : []);
|
|
9
|
+
const data = items.flatMap(({ imports: list }) => list.map((i) => `{ ${wrapperKey}: ${i.as || i.name} }`));
|
|
10
|
+
return `${imports.join("\n")}\n\nexport const ${exportName} = [\n${data.join(",\n")}\n]`;
|
|
11
|
+
}
|
|
12
|
+
function safeGenerateModuleCode(nitro, moduleName) {
|
|
13
|
+
try {
|
|
14
|
+
const generator = nitro.options.virtual?.[moduleName];
|
|
15
|
+
if (generator && typeof generator === "function") return generator();
|
|
16
|
+
return "// Module not found";
|
|
17
|
+
} catch (error) {
|
|
18
|
+
return `// Error: ${error instanceof Error ? error.message : String(error)}`;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
const serverSchemas = {
|
|
22
|
+
id: "#nitro-graphql/server-schemas",
|
|
23
|
+
getCode: (nitro) => {
|
|
24
|
+
const schemas = [...nitro.scanSchemas, ...nitro.options.graphql?.typedefs ?? []];
|
|
25
|
+
if (!schemas.length) {
|
|
26
|
+
if (nitro.options.dev) nitro.logger.warn("[nitro-graphql] No schemas found. Virtual module will export empty array.");
|
|
27
|
+
return "export const schemas = []";
|
|
28
|
+
}
|
|
29
|
+
const importStatements = schemas.map((s) => `import ${getImportId(s)} from '${s}';`);
|
|
30
|
+
const schemaArray = schemas.map((s) => `{ def: ${getImportId(s)} }`);
|
|
31
|
+
return `${importStatements.join("\n")}\n\nexport const schemas = [\n${schemaArray.join(",\n")}\n];`;
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
const serverResolvers = {
|
|
35
|
+
id: "#nitro-graphql/server-resolvers",
|
|
36
|
+
getCode: (nitro) => {
|
|
37
|
+
const imports = [...nitro.scanResolvers];
|
|
38
|
+
if (!imports.length) {
|
|
39
|
+
if (nitro.options.dev) nitro.logger.warn("[nitro-graphql] No resolvers found. Virtual module will export empty array.");
|
|
40
|
+
return "export const resolvers = []";
|
|
41
|
+
}
|
|
42
|
+
return generateImportModule(imports, "resolvers", "resolver");
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
const serverDirectives = {
|
|
46
|
+
id: "#nitro-graphql/server-directives",
|
|
47
|
+
getCode: (nitro) => {
|
|
48
|
+
const imports = nitro.scanDirectives || [];
|
|
49
|
+
if (!imports.length) return "export const directives = []";
|
|
50
|
+
return generateImportModule(imports, "directives", "directive");
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
const graphqlConfig = {
|
|
54
|
+
id: "#nitro-graphql/graphql-config",
|
|
55
|
+
getCode: (nitro) => {
|
|
56
|
+
return `import config from '${resolve(nitro.graphql.serverDir, "config.ts")}'
|
|
57
|
+
const importedConfig = config
|
|
58
|
+
export { importedConfig }
|
|
59
|
+
`;
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
const moduleConfig = {
|
|
63
|
+
id: "#nitro-graphql/module-config",
|
|
64
|
+
getCode: (nitro) => {
|
|
65
|
+
const config = nitro.options.graphql || {};
|
|
66
|
+
return `export const moduleConfig = ${JSON.stringify(config, null, 2)};`;
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
const debugInfo = {
|
|
70
|
+
id: "#nitro-graphql/debug-info",
|
|
71
|
+
getCode: (nitro) => {
|
|
72
|
+
const virtualModuleCodes = {
|
|
73
|
+
"server-schemas": safeGenerateModuleCode(nitro, "#nitro-graphql/server-schemas"),
|
|
74
|
+
"server-resolvers": safeGenerateModuleCode(nitro, "#nitro-graphql/server-resolvers"),
|
|
75
|
+
"server-directives": safeGenerateModuleCode(nitro, "#nitro-graphql/server-directives"),
|
|
76
|
+
"module-config": safeGenerateModuleCode(nitro, "#nitro-graphql/module-config"),
|
|
77
|
+
"graphql-config": safeGenerateModuleCode(nitro, "#nitro-graphql/graphql-config")
|
|
78
|
+
};
|
|
79
|
+
const info = {
|
|
80
|
+
isDev: nitro.options.dev,
|
|
81
|
+
framework: nitro.options.framework.name,
|
|
82
|
+
graphqlFramework: nitro.options.graphql?.framework,
|
|
83
|
+
federation: nitro.options.graphql?.federation,
|
|
84
|
+
scanned: {
|
|
85
|
+
schemas: nitro.scanSchemas?.length || 0,
|
|
86
|
+
schemaFiles: nitro.scanSchemas || [],
|
|
87
|
+
resolvers: nitro.scanResolvers?.length || 0,
|
|
88
|
+
resolverFiles: nitro.scanResolvers || [],
|
|
89
|
+
directives: nitro.scanDirectives?.length || 0,
|
|
90
|
+
directiveFiles: nitro.scanDirectives || [],
|
|
91
|
+
documents: nitro.scanDocuments?.length || 0,
|
|
92
|
+
documentFiles: nitro.scanDocuments || []
|
|
93
|
+
},
|
|
94
|
+
virtualModules: virtualModuleCodes
|
|
95
|
+
};
|
|
96
|
+
return `export const debugInfo = ${JSON.stringify(info, null, 2)};`;
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
const allModules = [
|
|
100
|
+
serverSchemas,
|
|
101
|
+
serverResolvers,
|
|
102
|
+
serverDirectives,
|
|
103
|
+
graphqlConfig,
|
|
104
|
+
moduleConfig,
|
|
105
|
+
debugInfo
|
|
106
|
+
];
|
|
107
|
+
function registerAllVirtualModules(nitro) {
|
|
108
|
+
nitro.options.virtual ??= {};
|
|
109
|
+
for (const mod of allModules) nitro.options.virtual[mod.id] = () => mod.getCode(nitro);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
//#endregion
|
|
113
|
+
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 };
|