nitro-graphql 2.0.0-beta.4 → 2.0.0-beta.40
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 +441 -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/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 +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/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 +212 -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 +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/nitro/paths.d.mts +54 -0
- package/dist/nitro/paths.mjs +93 -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/file-watcher.d.mts +16 -0
- package/dist/nitro/setup/file-watcher.mjs +80 -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 +231 -0
- package/dist/nitro/types.d.mts +378 -0
- 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.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 +97 -78
- 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,133 @@
|
|
|
1
|
+
import { Source } from "@graphql-tools/utils";
|
|
2
|
+
import { GraphQLSchema } from "graphql";
|
|
3
|
+
|
|
4
|
+
//#region src/core/types/codegen.d.ts
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Scalar type mapping (can be string or input/output object)
|
|
8
|
+
*/
|
|
9
|
+
type ScalarType = string | {
|
|
10
|
+
input: string;
|
|
11
|
+
output: string;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Server codegen configuration
|
|
15
|
+
*/
|
|
16
|
+
interface ServerCodegenConfig {
|
|
17
|
+
scalars?: Record<string, ScalarType>;
|
|
18
|
+
defaultScalarType?: string;
|
|
19
|
+
defaultMapper?: string;
|
|
20
|
+
contextType?: string;
|
|
21
|
+
maybeValue?: string;
|
|
22
|
+
inputMaybeValue?: string;
|
|
23
|
+
declarationKind?: string;
|
|
24
|
+
enumsAsTypes?: boolean;
|
|
25
|
+
federation?: boolean;
|
|
26
|
+
[key: string]: unknown;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Client codegen configuration
|
|
30
|
+
*/
|
|
31
|
+
interface ClientCodegenConfig {
|
|
32
|
+
emitLegacyCommonJSImports?: boolean;
|
|
33
|
+
useTypeImports?: boolean;
|
|
34
|
+
enumsAsTypes?: boolean;
|
|
35
|
+
strictScalars?: boolean;
|
|
36
|
+
maybeValue?: string;
|
|
37
|
+
inputMaybeValue?: string;
|
|
38
|
+
documentMode?: string;
|
|
39
|
+
pureMagicComment?: boolean;
|
|
40
|
+
dedupeOperationSuffix?: boolean;
|
|
41
|
+
rawRequest?: boolean;
|
|
42
|
+
scalars?: Record<string, ScalarType>;
|
|
43
|
+
typedDocumentNode?: boolean;
|
|
44
|
+
[key: string]: unknown;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* SDK codegen configuration
|
|
48
|
+
*/
|
|
49
|
+
interface SdkCodegenConfig extends ClientCodegenConfig {
|
|
50
|
+
[key: string]: unknown;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Input for server type generation
|
|
54
|
+
*/
|
|
55
|
+
interface ServerCodegenInput {
|
|
56
|
+
/** GraphQL framework name */
|
|
57
|
+
framework: string;
|
|
58
|
+
/** Parsed GraphQL schema */
|
|
59
|
+
schema: GraphQLSchema;
|
|
60
|
+
/** Server codegen configuration */
|
|
61
|
+
config?: ServerCodegenConfig;
|
|
62
|
+
/** Whether federation is enabled */
|
|
63
|
+
federationEnabled?: boolean;
|
|
64
|
+
/** Output filename (optional) */
|
|
65
|
+
outputPath?: string;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Result of server type generation
|
|
69
|
+
*/
|
|
70
|
+
interface ServerCodegenResult {
|
|
71
|
+
/** Generated TypeScript types content */
|
|
72
|
+
types: string;
|
|
73
|
+
/** Printed GraphQL schema */
|
|
74
|
+
schemaString: string;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Input for client type generation
|
|
78
|
+
*/
|
|
79
|
+
interface ClientCodegenInput {
|
|
80
|
+
/** Parsed GraphQL schema */
|
|
81
|
+
schema: GraphQLSchema;
|
|
82
|
+
/** Loaded GraphQL documents */
|
|
83
|
+
documents: Source[];
|
|
84
|
+
/** Client codegen configuration */
|
|
85
|
+
config?: ClientCodegenConfig;
|
|
86
|
+
/** SDK codegen configuration */
|
|
87
|
+
sdkConfig?: SdkCodegenConfig;
|
|
88
|
+
/** Output filename (optional) */
|
|
89
|
+
outputPath?: string;
|
|
90
|
+
/** Service name for external services */
|
|
91
|
+
serviceName?: string;
|
|
92
|
+
/** Virtual types import path */
|
|
93
|
+
virtualTypesPath?: string;
|
|
94
|
+
/** Generation options */
|
|
95
|
+
options?: {
|
|
96
|
+
silent?: boolean;
|
|
97
|
+
isInitial?: boolean;
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Result of client type generation
|
|
102
|
+
*/
|
|
103
|
+
interface ClientCodegenResult {
|
|
104
|
+
/** Generated TypeScript types content */
|
|
105
|
+
types: string;
|
|
106
|
+
/** Generated SDK content */
|
|
107
|
+
sdk: string;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* External service configuration for codegen
|
|
111
|
+
*/
|
|
112
|
+
interface ExternalServiceCodegenConfig {
|
|
113
|
+
name: string;
|
|
114
|
+
schema: string | string[];
|
|
115
|
+
endpoint: string;
|
|
116
|
+
headers?: Record<string, string> | (() => Record<string, string>);
|
|
117
|
+
documents?: string[];
|
|
118
|
+
downloadSchema?: boolean | 'once' | 'always' | 'manual';
|
|
119
|
+
downloadPath?: string;
|
|
120
|
+
codegen?: {
|
|
121
|
+
client?: ClientCodegenConfig;
|
|
122
|
+
clientSDK?: SdkCodegenConfig;
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Schema loading options
|
|
127
|
+
*/
|
|
128
|
+
interface SchemaLoadOptions {
|
|
129
|
+
headers?: Record<string, string>;
|
|
130
|
+
loaders?: unknown[];
|
|
131
|
+
}
|
|
132
|
+
//#endregion
|
|
133
|
+
export { ClientCodegenConfig, ClientCodegenInput, ClientCodegenResult, ExternalServiceCodegenConfig, ScalarType, SchemaLoadOptions, SdkCodegenConfig, ServerCodegenConfig, ServerCodegenInput, ServerCodegenResult };
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import { GraphQLFramework } from "../constants.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/core/types/config.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Core logger interface
|
|
7
|
+
* Abstracts logging functionality for framework independence
|
|
8
|
+
*/
|
|
9
|
+
interface CoreLogger {
|
|
10
|
+
info: (message: string, ...args: unknown[]) => void;
|
|
11
|
+
warn: (message: string, ...args: unknown[]) => void;
|
|
12
|
+
error: (message: string, ...args: unknown[]) => void;
|
|
13
|
+
success: (message: string, ...args: unknown[]) => void;
|
|
14
|
+
debug: (message: string, ...args: unknown[]) => void;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* GraphQL codegen configuration
|
|
18
|
+
*/
|
|
19
|
+
interface CoreCodegenConfig {
|
|
20
|
+
/** Server-side codegen options */
|
|
21
|
+
server?: Record<string, unknown>;
|
|
22
|
+
/** Client-side codegen options */
|
|
23
|
+
client?: Record<string, unknown>;
|
|
24
|
+
/** Client SDK codegen options */
|
|
25
|
+
clientSDK?: Record<string, unknown>;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Security configuration options
|
|
29
|
+
*/
|
|
30
|
+
interface CoreSecurityConfig {
|
|
31
|
+
/** Enable/disable GraphQL introspection */
|
|
32
|
+
introspection?: boolean;
|
|
33
|
+
/** Enable/disable GraphQL playground */
|
|
34
|
+
playground?: boolean;
|
|
35
|
+
/** Enable/disable error masking in responses */
|
|
36
|
+
maskErrors?: boolean;
|
|
37
|
+
/** Disable field suggestions in error messages */
|
|
38
|
+
disableSuggestions?: boolean;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* External GraphQL service configuration
|
|
42
|
+
*/
|
|
43
|
+
interface CoreExternalService {
|
|
44
|
+
/** Unique service name */
|
|
45
|
+
name: string;
|
|
46
|
+
/** GraphQL schema URL or file path */
|
|
47
|
+
schema: string;
|
|
48
|
+
/** GraphQL endpoint URL */
|
|
49
|
+
endpoint: string;
|
|
50
|
+
/** Headers for schema introspection */
|
|
51
|
+
headers?: Record<string, string> | (() => Record<string, string>);
|
|
52
|
+
/** Document patterns for this service */
|
|
53
|
+
documents?: string[];
|
|
54
|
+
/** Service-specific path overrides */
|
|
55
|
+
paths?: {
|
|
56
|
+
sdk?: string;
|
|
57
|
+
types?: string;
|
|
58
|
+
ofetch?: string;
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Apollo Federation configuration
|
|
63
|
+
*/
|
|
64
|
+
interface CoreFederationConfig {
|
|
65
|
+
/** Enable federation support */
|
|
66
|
+
enabled?: boolean;
|
|
67
|
+
/** Service name for federation */
|
|
68
|
+
serviceName?: string;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Path configuration with placeholders
|
|
72
|
+
*/
|
|
73
|
+
interface CorePathsConfig {
|
|
74
|
+
/** Server GraphQL directory (default: 'server/graphql') */
|
|
75
|
+
serverGraphql?: string;
|
|
76
|
+
/** Client GraphQL directory (default: 'app/graphql' or 'graphql') */
|
|
77
|
+
clientGraphql?: string;
|
|
78
|
+
/** Build directory (default: '.nitro' or '.nuxt') */
|
|
79
|
+
buildDir?: string;
|
|
80
|
+
/** Types output directory (default: '{buildDir}/types') */
|
|
81
|
+
typesDir?: string;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Scaffold file generation configuration
|
|
85
|
+
*/
|
|
86
|
+
interface CoreScaffoldConfig {
|
|
87
|
+
/** Master switch for all scaffold files */
|
|
88
|
+
enabled?: boolean;
|
|
89
|
+
/** Generate graphql.config.ts */
|
|
90
|
+
graphqlConfig?: boolean | string;
|
|
91
|
+
/** Generate server schema.ts */
|
|
92
|
+
serverSchema?: boolean | string;
|
|
93
|
+
/** Generate server config.ts */
|
|
94
|
+
serverConfig?: boolean | string;
|
|
95
|
+
/** Generate server context.d.ts */
|
|
96
|
+
serverContext?: boolean | string;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Type generation configuration
|
|
100
|
+
*/
|
|
101
|
+
interface CoreTypesConfig {
|
|
102
|
+
/** Master switch for type generation */
|
|
103
|
+
enabled?: boolean;
|
|
104
|
+
/** Server types output path */
|
|
105
|
+
server?: boolean | string;
|
|
106
|
+
/** Client types output path */
|
|
107
|
+
client?: boolean | string;
|
|
108
|
+
/** External service types output path */
|
|
109
|
+
external?: boolean | string;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* SDK generation configuration
|
|
113
|
+
*/
|
|
114
|
+
interface CoreSdkConfig {
|
|
115
|
+
/** Master switch for SDK generation */
|
|
116
|
+
enabled?: boolean;
|
|
117
|
+
/** Main SDK output path */
|
|
118
|
+
main?: boolean | string;
|
|
119
|
+
/** External service SDK output path */
|
|
120
|
+
external?: boolean | string;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Client utilities configuration
|
|
124
|
+
*/
|
|
125
|
+
interface CoreClientUtilsConfig {
|
|
126
|
+
/** Master switch for client utilities */
|
|
127
|
+
enabled?: boolean;
|
|
128
|
+
/** Index file output path */
|
|
129
|
+
index?: boolean | string;
|
|
130
|
+
/** Ofetch client output path */
|
|
131
|
+
ofetch?: boolean | string;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Core GraphQL options
|
|
135
|
+
* Framework-agnostic GraphQL configuration
|
|
136
|
+
*/
|
|
137
|
+
interface CoreGraphQLOptions {
|
|
138
|
+
/** GraphQL framework to use */
|
|
139
|
+
framework?: GraphQLFramework;
|
|
140
|
+
/** GraphQL endpoint path */
|
|
141
|
+
endpoint?: string;
|
|
142
|
+
/** Codegen configuration */
|
|
143
|
+
codegen?: CoreCodegenConfig;
|
|
144
|
+
/** Security configuration */
|
|
145
|
+
security?: CoreSecurityConfig;
|
|
146
|
+
/** External GraphQL services */
|
|
147
|
+
externalServices?: CoreExternalService[];
|
|
148
|
+
/** Apollo Federation configuration */
|
|
149
|
+
federation?: CoreFederationConfig;
|
|
150
|
+
/** Path configuration */
|
|
151
|
+
paths?: CorePathsConfig;
|
|
152
|
+
/** Scaffold file configuration */
|
|
153
|
+
scaffold?: false | CoreScaffoldConfig;
|
|
154
|
+
/** Type generation configuration */
|
|
155
|
+
types?: false | CoreTypesConfig;
|
|
156
|
+
/** SDK generation configuration */
|
|
157
|
+
sdk?: false | CoreSdkConfig;
|
|
158
|
+
/** Client utilities configuration */
|
|
159
|
+
clientUtils?: false | CoreClientUtilsConfig;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Core configuration
|
|
163
|
+
* Main configuration interface that replaces Nitro-specific options
|
|
164
|
+
*/
|
|
165
|
+
interface CoreConfig {
|
|
166
|
+
/** Root directory of the project */
|
|
167
|
+
rootDir: string;
|
|
168
|
+
/** Build output directory */
|
|
169
|
+
buildDir: string;
|
|
170
|
+
/** Server GraphQL directory */
|
|
171
|
+
serverDir: string;
|
|
172
|
+
/** Client GraphQL directory */
|
|
173
|
+
clientDir: string;
|
|
174
|
+
/** Types output directory */
|
|
175
|
+
typesDir: string;
|
|
176
|
+
/** GraphQL framework to use */
|
|
177
|
+
framework: GraphQLFramework;
|
|
178
|
+
/** Whether running in Nuxt context */
|
|
179
|
+
isNuxt: boolean;
|
|
180
|
+
/** Whether running in development mode */
|
|
181
|
+
isDev: boolean;
|
|
182
|
+
/** GraphQL options */
|
|
183
|
+
graphqlOptions: CoreGraphQLOptions;
|
|
184
|
+
/** Logger instance */
|
|
185
|
+
logger: CoreLogger;
|
|
186
|
+
/** Patterns to ignore during scanning */
|
|
187
|
+
ignorePatterns: string[];
|
|
188
|
+
/** Layer server directories (Nuxt) */
|
|
189
|
+
layerServerDirs?: string[];
|
|
190
|
+
/** Layer app directories (Nuxt) */
|
|
191
|
+
layerAppDirs?: string[];
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Core context for runtime operations
|
|
195
|
+
* Holds resolved configuration and state
|
|
196
|
+
*/
|
|
197
|
+
interface CoreContext {
|
|
198
|
+
/** Resolved configuration */
|
|
199
|
+
config: CoreConfig;
|
|
200
|
+
/** GraphQL build directory */
|
|
201
|
+
graphqlBuildDir: string;
|
|
202
|
+
/** Watch directories for file watching */
|
|
203
|
+
watchDirs: string[];
|
|
204
|
+
/** Relative directory paths */
|
|
205
|
+
dir: {
|
|
206
|
+
build: string;
|
|
207
|
+
client: string;
|
|
208
|
+
server: string;
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
//#endregion
|
|
212
|
+
export { CoreClientUtilsConfig, CoreCodegenConfig, CoreConfig, CoreContext, CoreExternalService, CoreFederationConfig, CoreGraphQLOptions, CoreLogger, CorePathsConfig, CoreScaffoldConfig, CoreSdkConfig, CoreSecurityConfig, CoreTypesConfig };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -1,23 +1,8 @@
|
|
|
1
1
|
import { GraphQLSchema } from "graphql";
|
|
2
|
-
import { ApolloServerOptions } from "@apollo/server";
|
|
3
|
-
import { H3Event } from "h3";
|
|
4
|
-
import { YogaServerOptions } from "graphql-yoga";
|
|
5
|
-
import { NPMConfig, Resolvers, ResolversTypes } from "#graphql/server";
|
|
6
|
-
import { StandardSchemaV1 } from "nitro-graphql";
|
|
7
2
|
|
|
8
|
-
//#region src/
|
|
3
|
+
//#region src/core/types/define.d.ts
|
|
4
|
+
|
|
9
5
|
type Flatten<T> = T extends infer U ? { [K in keyof U]: U[K] } : never;
|
|
10
|
-
declare function defineSchema<T extends Partial<Record<keyof ResolversTypes, StandardSchemaV1>>>(config: T): Flatten<T>;
|
|
11
|
-
declare function defineResolver(resolvers: Resolvers): Resolvers;
|
|
12
|
-
type ResolverQuery = Resolvers extends {
|
|
13
|
-
Query: infer Q;
|
|
14
|
-
} ? Q : never;
|
|
15
|
-
declare function defineQuery(resolvers?: Resolvers['Query']): Resolvers;
|
|
16
|
-
declare function defineMutation(resolvers?: Resolvers['Mutation']): Resolvers;
|
|
17
|
-
declare function defineSubscription(resolvers?: Resolvers['Subscription']): Resolvers;
|
|
18
|
-
declare function defineType(resolvers: Resolvers): Resolvers;
|
|
19
|
-
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>>;
|
|
20
|
-
declare function defineGraphQLConfig<T extends NPMConfig = NPMConfig>(config: Partial<DefineServerConfig<T>>): Partial<DefineServerConfig<T>>;
|
|
21
6
|
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';
|
|
22
7
|
type GraphQLScalarType = 'String' | 'Int' | 'Float' | 'Boolean' | 'ID' | 'JSON' | 'DateTime';
|
|
23
8
|
type GraphQLBaseType = GraphQLScalarType | (string & {});
|
|
@@ -56,17 +41,5 @@ interface DefineDirectiveConfig {
|
|
|
56
41
|
isRepeatable?: boolean;
|
|
57
42
|
transformer?: (schema: GraphQLSchema) => GraphQLSchema;
|
|
58
43
|
}
|
|
59
|
-
/**
|
|
60
|
-
* Helper function to create directive arguments with proper type inference
|
|
61
|
-
* @example
|
|
62
|
-
* args: {
|
|
63
|
-
* myArg: arg('String!', { defaultValue: 'hello' })
|
|
64
|
-
* }
|
|
65
|
-
*/
|
|
66
|
-
declare function arg<T extends GraphQLArgumentType>(type: T, options?: {
|
|
67
|
-
defaultValue?: any;
|
|
68
|
-
description?: string;
|
|
69
|
-
}): DirectiveArgument<T>;
|
|
70
|
-
declare function defineDirective(config: DefineDirectiveConfig): DirectiveDefinition;
|
|
71
44
|
//#endregion
|
|
72
|
-
export { DefineDirectiveConfig,
|
|
45
|
+
export { DefineDirectiveConfig, DirectiveArgument, DirectiveDefinition, Flatten, GraphQLArgumentType, GraphQLBaseType, GraphQLScalarType };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { ClientCodegenConfig, ClientCodegenInput, ClientCodegenResult, ExternalServiceCodegenConfig, ScalarType, SchemaLoadOptions, SdkCodegenConfig, ServerCodegenConfig, ServerCodegenInput, ServerCodegenResult } from "./codegen.mjs";
|
|
2
|
+
import { CoreClientUtilsConfig, CoreCodegenConfig, CoreConfig, CoreContext, CoreExternalService, CoreFederationConfig, CoreGraphQLOptions, CoreLogger, CorePathsConfig, CoreScaffoldConfig, CoreSdkConfig, CoreSecurityConfig, CoreTypesConfig } from "./config.mjs";
|
|
3
|
+
import { DefineDirectiveConfig, DirectiveArgument, DirectiveDefinition, Flatten, GraphQLArgumentType, GraphQLBaseType, GraphQLScalarType } from "./define.mjs";
|
|
4
|
+
import { ResolverImport, ScanContext, ScanResult, ScannedFile, ScannedResolver } from "./scanning.mjs";
|
|
5
|
+
export { ClientCodegenConfig, ClientCodegenInput, ClientCodegenResult, CoreClientUtilsConfig, CoreCodegenConfig, CoreConfig, CoreContext, CoreExternalService, CoreFederationConfig, CoreGraphQLOptions, CoreLogger, CorePathsConfig, CoreScaffoldConfig, CoreSdkConfig, CoreSecurityConfig, CoreTypesConfig, DefineDirectiveConfig, DirectiveArgument, DirectiveDefinition, ExternalServiceCodegenConfig, Flatten, GraphQLArgumentType, GraphQLBaseType, GraphQLScalarType, ResolverImport, ScalarType, ScanContext, ScanResult, ScannedFile, ScannedResolver, SchemaLoadOptions, SdkCodegenConfig, ServerCodegenConfig, ServerCodegenInput, ServerCodegenResult };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { CoreLogger } from "./config.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/core/types/scanning.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Scan context for file scanning operations
|
|
7
|
+
* Provides all necessary information for scanning without framework dependencies
|
|
8
|
+
*/
|
|
9
|
+
interface ScanContext {
|
|
10
|
+
/** Root directory of the project */
|
|
11
|
+
rootDir: string;
|
|
12
|
+
/** Server GraphQL directory */
|
|
13
|
+
serverDir: string;
|
|
14
|
+
/** Client GraphQL directory */
|
|
15
|
+
clientDir: string;
|
|
16
|
+
/** Patterns to ignore during scanning */
|
|
17
|
+
ignorePatterns: string[];
|
|
18
|
+
/** Whether running in development mode */
|
|
19
|
+
isDev: boolean;
|
|
20
|
+
/** Logger instance */
|
|
21
|
+
logger: CoreLogger;
|
|
22
|
+
/** Layer server directories (Nuxt layers) */
|
|
23
|
+
layerServerDirs?: string[];
|
|
24
|
+
/** Layer app directories (Nuxt layers) */
|
|
25
|
+
layerAppDirs?: string[];
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Generic scan result wrapper
|
|
29
|
+
* Provides consistent result structure with warnings and errors
|
|
30
|
+
*/
|
|
31
|
+
interface ScanResult<T> {
|
|
32
|
+
/** Scanned items */
|
|
33
|
+
items: T[];
|
|
34
|
+
/** Non-fatal warnings encountered during scanning */
|
|
35
|
+
warnings: string[];
|
|
36
|
+
/** Errors encountered during scanning */
|
|
37
|
+
errors: string[];
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* File information from scanning
|
|
41
|
+
*/
|
|
42
|
+
interface ScannedFile {
|
|
43
|
+
/** Relative path from scan directory */
|
|
44
|
+
path: string;
|
|
45
|
+
/** Absolute file path */
|
|
46
|
+
fullPath: string;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Resolver import information
|
|
50
|
+
*/
|
|
51
|
+
interface ResolverImport {
|
|
52
|
+
/** Export name */
|
|
53
|
+
name: string;
|
|
54
|
+
/** Resolver type (query, mutation, resolver, type, subscription, directive) */
|
|
55
|
+
type: 'query' | 'mutation' | 'resolver' | 'type' | 'subscription' | 'directive';
|
|
56
|
+
/** Aliased import name */
|
|
57
|
+
as: string;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Scanned resolver information
|
|
61
|
+
*/
|
|
62
|
+
interface ScannedResolver {
|
|
63
|
+
/** File specifier (path) */
|
|
64
|
+
specifier: string;
|
|
65
|
+
/** Exports from this file */
|
|
66
|
+
imports: ResolverImport[];
|
|
67
|
+
}
|
|
68
|
+
//#endregion
|
|
69
|
+
export { ResolverImport, ScanContext, ScanResult, ScannedFile, ScannedResolver };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
//#region src/utils/directive-parser.d.ts
|
|
1
|
+
//#region src/core/utils/directive-parser.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Directive parser utilities
|
|
4
|
+
* AST-based parsing for GraphQL directive definitions
|
|
5
|
+
*/
|
|
2
6
|
interface ParsedDirective {
|
|
3
7
|
name: string;
|
|
4
8
|
locations: string[];
|
|
@@ -69,12 +73,25 @@ declare class DirectiveParser {
|
|
|
69
73
|
*/
|
|
70
74
|
declare function generateDirectiveSchema(directive: ParsedDirective): string;
|
|
71
75
|
/**
|
|
72
|
-
*
|
|
76
|
+
* Directive file reference
|
|
77
|
+
* Can be either { fullPath } or { specifier } (for GenImport compatibility)
|
|
73
78
|
*/
|
|
74
|
-
|
|
79
|
+
type DirectiveFileRef = {
|
|
80
|
+
fullPath: string;
|
|
81
|
+
} | {
|
|
82
|
+
specifier: string;
|
|
83
|
+
};
|
|
75
84
|
/**
|
|
76
85
|
* Singleton instance for reuse
|
|
77
86
|
*/
|
|
78
87
|
declare const directiveParser: DirectiveParser;
|
|
88
|
+
/**
|
|
89
|
+
* Generate GraphQL schemas from an array of parsed directives
|
|
90
|
+
*/
|
|
91
|
+
declare function generateDirectiveSchemas(nitro: {
|
|
92
|
+
graphql: {
|
|
93
|
+
buildDir: string;
|
|
94
|
+
};
|
|
95
|
+
}, directives: DirectiveFileRef[]): Promise<string | null>;
|
|
79
96
|
//#endregion
|
|
80
|
-
export { DirectiveParser, ParsedDirective, directiveParser, generateDirectiveSchema, generateDirectiveSchemas };
|
|
97
|
+
export { DirectiveFileRef, DirectiveParser, ParsedDirective, directiveParser, generateDirectiveSchema, generateDirectiveSchemas };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//#region src/utils/directive-parser.ts
|
|
1
|
+
//#region src/core/utils/directive-parser.ts
|
|
2
2
|
/**
|
|
3
3
|
* Clean AST-based directive parser using oxc-parser
|
|
4
4
|
*/
|
|
@@ -180,45 +180,36 @@ function generateDirectiveSchema(directive) {
|
|
|
180
180
|
return `directive @${directive.name}${args} on ${locations}`;
|
|
181
181
|
}
|
|
182
182
|
/**
|
|
183
|
-
*
|
|
183
|
+
* Get the file path from a directive reference
|
|
184
184
|
*/
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
const { existsSync, readFileSync, writeFileSync, mkdirSync } = await import("node:fs");
|
|
188
|
-
const { readFile } = await import("node:fs/promises");
|
|
189
|
-
const { resolve, dirname } = await import("pathe");
|
|
190
|
-
const directiveSchemas = [];
|
|
191
|
-
const seenDirectives = /* @__PURE__ */ new Set();
|
|
192
|
-
const parser = new DirectiveParser();
|
|
193
|
-
for (const dir of directives) for (const _imp of dir.imports) {
|
|
194
|
-
const fileContent = await readFile(dir.specifier, "utf-8");
|
|
195
|
-
const directiveDefs = await parser.parseDirectives(fileContent, dir.specifier);
|
|
196
|
-
for (const def of directiveDefs) {
|
|
197
|
-
if (seenDirectives.has(def.name)) continue;
|
|
198
|
-
seenDirectives.add(def.name);
|
|
199
|
-
const schema = generateDirectiveSchema(def);
|
|
200
|
-
directiveSchemas.push(schema);
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
if (directiveSchemas.length > 0) {
|
|
204
|
-
const directivesPath = resolve(nitro.graphql.buildDir, "_directives.graphql");
|
|
205
|
-
const content = `# WARNING: This file is auto-generated by nitro-graphql
|
|
206
|
-
# Do not modify this file directly. It will be overwritten.
|
|
207
|
-
# To define custom directives, create .directive.ts files using defineDirective()
|
|
208
|
-
|
|
209
|
-
${directiveSchemas.join("\n\n")}`;
|
|
210
|
-
const targetDir = dirname(directivesPath);
|
|
211
|
-
if (!existsSync(targetDir)) mkdirSync(targetDir, { recursive: true });
|
|
212
|
-
let shouldWrite = true;
|
|
213
|
-
if (existsSync(directivesPath)) shouldWrite = readFileSync(directivesPath, "utf-8") !== content;
|
|
214
|
-
if (shouldWrite) writeFileSync(directivesPath, content, "utf-8");
|
|
215
|
-
if (!nitro.scanSchemas.includes(directivesPath)) nitro.scanSchemas.push(directivesPath);
|
|
216
|
-
}
|
|
185
|
+
function getFilePath(ref) {
|
|
186
|
+
return "fullPath" in ref ? ref.fullPath : ref.specifier;
|
|
217
187
|
}
|
|
218
188
|
/**
|
|
219
189
|
* Singleton instance for reuse
|
|
220
190
|
*/
|
|
221
191
|
const directiveParser = new DirectiveParser();
|
|
192
|
+
/**
|
|
193
|
+
* Generate GraphQL schemas from an array of parsed directives
|
|
194
|
+
*/
|
|
195
|
+
async function generateDirectiveSchemas(nitro, directives) {
|
|
196
|
+
if (directives.length === 0) return null;
|
|
197
|
+
const fs = await import("node:fs");
|
|
198
|
+
const path = await import("pathe");
|
|
199
|
+
const allParsedDirectives = [];
|
|
200
|
+
for (const directive of directives) try {
|
|
201
|
+
const filePath = getFilePath(directive);
|
|
202
|
+
const content = fs.readFileSync(filePath, "utf-8");
|
|
203
|
+
const parsed = await directiveParser.parseDirectives(content, filePath);
|
|
204
|
+
allParsedDirectives.push(...parsed);
|
|
205
|
+
} catch {}
|
|
206
|
+
if (allParsedDirectives.length === 0) return null;
|
|
207
|
+
const schemaContent = allParsedDirectives.map((d) => generateDirectiveSchema(d)).join("\n\n");
|
|
208
|
+
const directivesPath = path.join(nitro.graphql.buildDir, "_directives.graphql");
|
|
209
|
+
fs.mkdirSync(path.dirname(directivesPath), { recursive: true });
|
|
210
|
+
fs.writeFileSync(directivesPath, schemaContent, "utf-8");
|
|
211
|
+
return directivesPath;
|
|
212
|
+
}
|
|
222
213
|
|
|
223
214
|
//#endregion
|
|
224
215
|
export { DirectiveParser, directiveParser, generateDirectiveSchema, generateDirectiveSchemas };
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
//#region src/core/utils/errors.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Error handling utilities for GraphQL
|
|
4
|
+
* Framework-agnostic error masking and handling
|
|
5
|
+
*/
|
|
6
|
+
interface MaskErrorOptions {
|
|
7
|
+
/**
|
|
8
|
+
* Default HTTP status code for validation errors (ZodError)
|
|
9
|
+
* @default 400
|
|
10
|
+
*/
|
|
11
|
+
validationStatusCode?: number;
|
|
12
|
+
/**
|
|
13
|
+
* Default HTTP status code for HTTP errors when status is not provided
|
|
14
|
+
* @default 500
|
|
15
|
+
*/
|
|
16
|
+
defaultHttpStatusCode?: number;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Default error masking function for GraphQL Yoga
|
|
20
|
+
* Handles common error types like ZodError and HTTPError
|
|
21
|
+
*
|
|
22
|
+
* @param options - Configuration options for error handling
|
|
23
|
+
*
|
|
24
|
+
* @example Basic usage
|
|
25
|
+
* ```ts
|
|
26
|
+
* import { defineGraphQLConfig } from 'nitro-graphql/define'
|
|
27
|
+
* import { createDefaultMaskError } from 'nitro-graphql/core'
|
|
28
|
+
*
|
|
29
|
+
* export default defineGraphQLConfig({
|
|
30
|
+
* maskedErrors: {
|
|
31
|
+
* maskError: createDefaultMaskError()
|
|
32
|
+
* }
|
|
33
|
+
* })
|
|
34
|
+
* ```
|
|
35
|
+
*
|
|
36
|
+
* @example Custom status codes
|
|
37
|
+
* ```ts
|
|
38
|
+
* import { defineGraphQLConfig } from 'nitro-graphql/define'
|
|
39
|
+
* import { createDefaultMaskError } from 'nitro-graphql/core'
|
|
40
|
+
*
|
|
41
|
+
* export default defineGraphQLConfig({
|
|
42
|
+
* maskedErrors: {
|
|
43
|
+
* maskError: createDefaultMaskError({
|
|
44
|
+
* validationStatusCode: 422, // Use 422 for validation errors
|
|
45
|
+
* defaultHttpStatusCode: 500 // Use 500 for unknown HTTP errors
|
|
46
|
+
* })
|
|
47
|
+
* }
|
|
48
|
+
* })
|
|
49
|
+
* ```
|
|
50
|
+
*
|
|
51
|
+
* @example Custom error handling with fallback to default
|
|
52
|
+
* ```ts
|
|
53
|
+
* import { defineGraphQLConfig } from 'nitro-graphql/define'
|
|
54
|
+
* import { createDefaultMaskError } from 'nitro-graphql/core'
|
|
55
|
+
*
|
|
56
|
+
* const defaultMaskError = createDefaultMaskError()
|
|
57
|
+
*
|
|
58
|
+
* export default defineGraphQLConfig({
|
|
59
|
+
* maskedErrors: {
|
|
60
|
+
* maskError: (error: unknown) => {
|
|
61
|
+
* // Handle custom errors first
|
|
62
|
+
* if (error instanceof MyCustomError) {
|
|
63
|
+
* return new GraphQLError(error.message, {
|
|
64
|
+
* extensions: { code: 'CUSTOM_ERROR' }
|
|
65
|
+
* })
|
|
66
|
+
* }
|
|
67
|
+
*
|
|
68
|
+
* // Fall back to default handling
|
|
69
|
+
* return defaultMaskError(error)
|
|
70
|
+
* }
|
|
71
|
+
* }
|
|
72
|
+
* })
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
declare function createDefaultMaskError(options?: MaskErrorOptions): (error: unknown) => Error;
|
|
76
|
+
//#endregion
|
|
77
|
+
export { MaskErrorOptions, createDefaultMaskError };
|