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,188 @@
|
|
|
1
|
+
//#region src/core/constants.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Constants and magic strings used throughout nitro-graphql core
|
|
4
|
+
* Centralizing these values prevents typos and makes refactoring easier
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Default scalar type mappings for GraphQL codegen
|
|
8
|
+
* These scalars are commonly used and have proper TypeScript type mappings
|
|
9
|
+
*/
|
|
10
|
+
declare const DEFAULT_GRAPHQL_SCALARS: {
|
|
11
|
+
readonly DateTime: string;
|
|
12
|
+
readonly DateTimeISO: string;
|
|
13
|
+
readonly UUID: string;
|
|
14
|
+
readonly JSON: string;
|
|
15
|
+
readonly JSONObject: string;
|
|
16
|
+
readonly NonEmptyString: string;
|
|
17
|
+
readonly Currency: string;
|
|
18
|
+
readonly File: {
|
|
19
|
+
readonly input: "File";
|
|
20
|
+
readonly output: "File";
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* GraphQL schema file extensions
|
|
25
|
+
*/
|
|
26
|
+
declare const GRAPHQL_EXTENSIONS: readonly [".graphql", ".gql"];
|
|
27
|
+
/**
|
|
28
|
+
* Resolver file extensions
|
|
29
|
+
*/
|
|
30
|
+
declare const RESOLVER_EXTENSIONS: readonly [".resolver.ts", ".resolver.js"];
|
|
31
|
+
/**
|
|
32
|
+
* Directive file extensions
|
|
33
|
+
*/
|
|
34
|
+
declare const DIRECTIVE_EXTENSIONS: readonly [".directive.ts", ".directive.js"];
|
|
35
|
+
/**
|
|
36
|
+
* Combined pattern for glob scanning
|
|
37
|
+
*/
|
|
38
|
+
declare const GLOB_SCAN_PATTERN: "**/*.{graphql,gql,js,mjs,cjs,ts,mts,cts,tsx,jsx}";
|
|
39
|
+
/**
|
|
40
|
+
* GraphQL file pattern for glob
|
|
41
|
+
*/
|
|
42
|
+
declare const GRAPHQL_GLOB_PATTERN: "**/*.graphql";
|
|
43
|
+
/**
|
|
44
|
+
* Resolver file pattern for glob
|
|
45
|
+
*/
|
|
46
|
+
declare const RESOLVER_GLOB_PATTERN: "**/*.resolver.{ts,js}";
|
|
47
|
+
/**
|
|
48
|
+
* Directive file pattern for glob
|
|
49
|
+
*/
|
|
50
|
+
declare const DIRECTIVE_GLOB_PATTERN: "**/*.directive.{ts,js}";
|
|
51
|
+
/**
|
|
52
|
+
* Framework names
|
|
53
|
+
*/
|
|
54
|
+
declare const FRAMEWORK_NUXT: "nuxt";
|
|
55
|
+
declare const FRAMEWORK_NITRO: "nitro";
|
|
56
|
+
declare const FRAMEWORK_STANDALONE: "standalone";
|
|
57
|
+
/**
|
|
58
|
+
* GraphQL server framework identifiers
|
|
59
|
+
*/
|
|
60
|
+
declare const GRAPHQL_FRAMEWORK_YOGA: "graphql-yoga";
|
|
61
|
+
declare const GRAPHQL_FRAMEWORK_APOLLO: "apollo-server";
|
|
62
|
+
type Framework = typeof FRAMEWORK_NUXT | typeof FRAMEWORK_NITRO | typeof FRAMEWORK_STANDALONE;
|
|
63
|
+
type GraphQLFramework = typeof GRAPHQL_FRAMEWORK_YOGA | typeof GRAPHQL_FRAMEWORK_APOLLO;
|
|
64
|
+
/**
|
|
65
|
+
* Default directory names for GraphQL files
|
|
66
|
+
*/
|
|
67
|
+
declare const DIR_SERVER_GRAPHQL: "server/graphql";
|
|
68
|
+
declare const DIR_ROUTES_GRAPHQL: "routes/graphql";
|
|
69
|
+
declare const DIR_APP_GRAPHQL: "app/graphql";
|
|
70
|
+
declare const DIR_CLIENT_GRAPHQL: "graphql";
|
|
71
|
+
declare const DIR_EXTERNAL: "external";
|
|
72
|
+
/**
|
|
73
|
+
* Windows-compatible server GraphQL directory
|
|
74
|
+
*/
|
|
75
|
+
declare const DIR_SERVER_GRAPHQL_WIN: "server\\graphql";
|
|
76
|
+
/**
|
|
77
|
+
* Build directory names
|
|
78
|
+
*/
|
|
79
|
+
declare const DIR_BUILD_NITRO: ".nitro";
|
|
80
|
+
declare const DIR_BUILD_NUXT: ".nuxt";
|
|
81
|
+
/**
|
|
82
|
+
* Default GraphQL endpoint paths
|
|
83
|
+
*/
|
|
84
|
+
declare const ENDPOINT_GRAPHQL: "/api/graphql";
|
|
85
|
+
declare const ENDPOINT_HEALTH: "/api/graphql/health";
|
|
86
|
+
declare const ENDPOINT_DEBUG: "/_nitro/graphql/debug";
|
|
87
|
+
/**
|
|
88
|
+
* Configuration and scaffold file names
|
|
89
|
+
*/
|
|
90
|
+
declare const FILE_GRAPHQL_CONFIG: "graphql.config.ts";
|
|
91
|
+
declare const FILE_SCHEMA_GRAPHQL: "schema.graphql";
|
|
92
|
+
declare const FILE_SCHEMA_TS: "schema.ts";
|
|
93
|
+
declare const FILE_CONFIG_TS: "config.ts";
|
|
94
|
+
declare const FILE_CONTEXT_DTS: "context.d.ts";
|
|
95
|
+
declare const FILE_CONTEXT_TS: "context.ts";
|
|
96
|
+
declare const FILE_INDEX_TS: "index.ts";
|
|
97
|
+
declare const FILE_OFETCH_TS: "ofetch.ts";
|
|
98
|
+
declare const FILE_SDK_TS: "sdk.ts";
|
|
99
|
+
declare const FILE_DIRECTIVES_GRAPHQL: "_directives.graphql";
|
|
100
|
+
/**
|
|
101
|
+
* Generated type definition file names
|
|
102
|
+
*/
|
|
103
|
+
declare const FILE_SERVER_TYPES: "nitro-graphql-server.d.ts";
|
|
104
|
+
declare const FILE_CLIENT_TYPES: "nitro-graphql-client.d.ts";
|
|
105
|
+
declare const FILE_GRAPHQL_DTS: "graphql.d.ts";
|
|
106
|
+
/**
|
|
107
|
+
* Generated type file name patterns with placeholders
|
|
108
|
+
*/
|
|
109
|
+
declare const PATTERN_CLIENT_EXTERNAL_TYPES: "nitro-graphql-client-{serviceName}.d.ts";
|
|
110
|
+
/**
|
|
111
|
+
* Rollup/Rolldown chunk output paths
|
|
112
|
+
*/
|
|
113
|
+
declare const CHUNK_PATH_GRAPHQL: "chunks/graphql/[name].mjs";
|
|
114
|
+
declare const CHUNK_PATH_UNKNOWN: "chunks/_/[name].mjs";
|
|
115
|
+
/**
|
|
116
|
+
* Default chunk names
|
|
117
|
+
*/
|
|
118
|
+
declare const CHUNK_NAME_SCHEMAS: "schemas";
|
|
119
|
+
declare const CHUNK_NAME_RESOLVERS: "resolvers";
|
|
120
|
+
/**
|
|
121
|
+
* Valid define function names for resolver exports
|
|
122
|
+
*/
|
|
123
|
+
declare const DEFINE_FUNCTIONS: readonly ["defineResolver", "defineQuery", "defineMutation", "defineField", "defineSubscription", "defineDirective"];
|
|
124
|
+
declare const DEFINE_RESOLVER: "defineResolver";
|
|
125
|
+
declare const DEFINE_QUERY: "defineQuery";
|
|
126
|
+
declare const DEFINE_MUTATION: "defineMutation";
|
|
127
|
+
declare const DEFINE_FIELD: "defineField";
|
|
128
|
+
declare const DEFINE_SUBSCRIPTION: "defineSubscription";
|
|
129
|
+
declare const DEFINE_DIRECTIVE: "defineDirective";
|
|
130
|
+
declare const DEFINE_GRAPHQL_CONFIG: "defineGraphQLConfig";
|
|
131
|
+
declare const DEFINE_SCHEMA: "defineSchema";
|
|
132
|
+
type DefineFunction = typeof DEFINE_FUNCTIONS[number];
|
|
133
|
+
/**
|
|
134
|
+
* Built-in GraphQL scalar types (should not be flagged as duplicates)
|
|
135
|
+
*/
|
|
136
|
+
declare const BUILTIN_SCALARS: readonly ["String", "Int", "Float", "Boolean", "ID", "DateTime", "JSON"];
|
|
137
|
+
/**
|
|
138
|
+
* Codegen parser dependencies (always external)
|
|
139
|
+
*/
|
|
140
|
+
declare const CODEGEN_EXTERNALS: readonly ["oxc-parser", "@oxc-parser"];
|
|
141
|
+
/**
|
|
142
|
+
* Apollo Federation dependencies (external when federation disabled)
|
|
143
|
+
*/
|
|
144
|
+
declare const FEDERATION_EXTERNALS: readonly ["@apollo/subgraph", "@apollo/federation-internals", "@apollo/cache-control-types"];
|
|
145
|
+
/**
|
|
146
|
+
* Supported HTTP methods for GraphQL endpoints
|
|
147
|
+
*/
|
|
148
|
+
declare const GRAPHQL_HTTP_METHODS: readonly ["GET", "POST", "OPTIONS"];
|
|
149
|
+
/**
|
|
150
|
+
* Default paths for type generation (relative to buildDir)
|
|
151
|
+
*/
|
|
152
|
+
declare const DEFAULT_SERVER_TYPES_PATH: ".graphql/nitro-graphql-server.d.ts";
|
|
153
|
+
declare const DEFAULT_CLIENT_TYPES_PATH: ".graphql/nitro-graphql-client.d.ts";
|
|
154
|
+
/**
|
|
155
|
+
* Valid resolver export types detected from AST parsing
|
|
156
|
+
*/
|
|
157
|
+
declare const RESOLVER_TYPE_QUERY: "query";
|
|
158
|
+
declare const RESOLVER_TYPE_MUTATION: "mutation";
|
|
159
|
+
declare const RESOLVER_TYPE_RESOLVER: "resolver";
|
|
160
|
+
declare const RESOLVER_TYPE_TYPE: "type";
|
|
161
|
+
declare const RESOLVER_TYPE_SUBSCRIPTION: "subscription";
|
|
162
|
+
declare const RESOLVER_TYPE_DIRECTIVE: "directive";
|
|
163
|
+
type ResolverType = typeof RESOLVER_TYPE_QUERY | typeof RESOLVER_TYPE_MUTATION | typeof RESOLVER_TYPE_RESOLVER | typeof RESOLVER_TYPE_TYPE | typeof RESOLVER_TYPE_SUBSCRIPTION | typeof RESOLVER_TYPE_DIRECTIVE;
|
|
164
|
+
/**
|
|
165
|
+
* Placeholder strings used in path resolution
|
|
166
|
+
*/
|
|
167
|
+
declare const PLACEHOLDER_SERVICE_NAME: "{serviceName}";
|
|
168
|
+
declare const PLACEHOLDER_BUILD_DIR: "{buildDir}";
|
|
169
|
+
declare const PLACEHOLDER_ROOT_DIR: "{rootDir}";
|
|
170
|
+
declare const PLACEHOLDER_FRAMEWORK: "{framework}";
|
|
171
|
+
declare const PLACEHOLDER_TYPES_DIR: "{typesDir}";
|
|
172
|
+
declare const PLACEHOLDER_SERVER_GRAPHQL: "{serverGraphql}";
|
|
173
|
+
declare const PLACEHOLDER_CLIENT_GRAPHQL: "{clientGraphql}";
|
|
174
|
+
/**
|
|
175
|
+
* Logger tag for nitro-graphql module
|
|
176
|
+
*/
|
|
177
|
+
declare const LOG_TAG: "nitro-graphql";
|
|
178
|
+
/**
|
|
179
|
+
* HTTP status codes for error handling
|
|
180
|
+
*/
|
|
181
|
+
declare const HTTP_STATUS_BAD_REQUEST: 400;
|
|
182
|
+
declare const HTTP_STATUS_INTERNAL_ERROR: 500;
|
|
183
|
+
/**
|
|
184
|
+
* Default service directory name for main service
|
|
185
|
+
*/
|
|
186
|
+
declare const SERVICE_DEFAULT: "default";
|
|
187
|
+
//#endregion
|
|
188
|
+
export { BUILTIN_SCALARS, CHUNK_NAME_RESOLVERS, CHUNK_NAME_SCHEMAS, CHUNK_PATH_GRAPHQL, CHUNK_PATH_UNKNOWN, CODEGEN_EXTERNALS, DEFAULT_CLIENT_TYPES_PATH, DEFAULT_GRAPHQL_SCALARS, DEFAULT_SERVER_TYPES_PATH, DEFINE_DIRECTIVE, DEFINE_FIELD, DEFINE_FUNCTIONS, DEFINE_GRAPHQL_CONFIG, DEFINE_MUTATION, DEFINE_QUERY, DEFINE_RESOLVER, DEFINE_SCHEMA, DEFINE_SUBSCRIPTION, DIRECTIVE_EXTENSIONS, DIRECTIVE_GLOB_PATTERN, DIR_APP_GRAPHQL, DIR_BUILD_NITRO, DIR_BUILD_NUXT, DIR_CLIENT_GRAPHQL, DIR_EXTERNAL, DIR_ROUTES_GRAPHQL, DIR_SERVER_GRAPHQL, DIR_SERVER_GRAPHQL_WIN, DefineFunction, ENDPOINT_DEBUG, ENDPOINT_GRAPHQL, ENDPOINT_HEALTH, FEDERATION_EXTERNALS, FILE_CLIENT_TYPES, FILE_CONFIG_TS, FILE_CONTEXT_DTS, FILE_CONTEXT_TS, FILE_DIRECTIVES_GRAPHQL, FILE_GRAPHQL_CONFIG, FILE_GRAPHQL_DTS, FILE_INDEX_TS, FILE_OFETCH_TS, FILE_SCHEMA_GRAPHQL, FILE_SCHEMA_TS, FILE_SDK_TS, FILE_SERVER_TYPES, FRAMEWORK_NITRO, FRAMEWORK_NUXT, FRAMEWORK_STANDALONE, Framework, GLOB_SCAN_PATTERN, GRAPHQL_EXTENSIONS, GRAPHQL_FRAMEWORK_APOLLO, GRAPHQL_FRAMEWORK_YOGA, GRAPHQL_GLOB_PATTERN, GRAPHQL_HTTP_METHODS, GraphQLFramework, HTTP_STATUS_BAD_REQUEST, HTTP_STATUS_INTERNAL_ERROR, LOG_TAG, PATTERN_CLIENT_EXTERNAL_TYPES, PLACEHOLDER_BUILD_DIR, PLACEHOLDER_CLIENT_GRAPHQL, PLACEHOLDER_FRAMEWORK, PLACEHOLDER_ROOT_DIR, PLACEHOLDER_SERVER_GRAPHQL, PLACEHOLDER_SERVICE_NAME, PLACEHOLDER_TYPES_DIR, RESOLVER_EXTENSIONS, RESOLVER_GLOB_PATTERN, RESOLVER_TYPE_DIRECTIVE, RESOLVER_TYPE_MUTATION, RESOLVER_TYPE_QUERY, RESOLVER_TYPE_RESOLVER, RESOLVER_TYPE_SUBSCRIPTION, RESOLVER_TYPE_TYPE, ResolverType, SERVICE_DEFAULT };
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import { CurrencyResolver, DateTimeISOResolver, DateTimeResolver, JSONObjectResolver, JSONResolver, NonEmptyStringResolver, UUIDResolver } from "graphql-scalars";
|
|
2
|
+
|
|
3
|
+
//#region src/core/constants.ts
|
|
4
|
+
/**
|
|
5
|
+
* Constants and magic strings used throughout nitro-graphql core
|
|
6
|
+
* Centralizing these values prevents typos and makes refactoring easier
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Default scalar type mappings for GraphQL codegen
|
|
10
|
+
* These scalars are commonly used and have proper TypeScript type mappings
|
|
11
|
+
*/
|
|
12
|
+
const DEFAULT_GRAPHQL_SCALARS = {
|
|
13
|
+
DateTime: DateTimeResolver.extensions.codegenScalarType,
|
|
14
|
+
DateTimeISO: DateTimeISOResolver.extensions.codegenScalarType,
|
|
15
|
+
UUID: UUIDResolver.extensions.codegenScalarType,
|
|
16
|
+
JSON: JSONResolver.extensions.codegenScalarType,
|
|
17
|
+
JSONObject: JSONObjectResolver.extensions.codegenScalarType,
|
|
18
|
+
NonEmptyString: NonEmptyStringResolver.extensions.codegenScalarType,
|
|
19
|
+
Currency: CurrencyResolver.extensions.codegenScalarType,
|
|
20
|
+
File: {
|
|
21
|
+
input: "File",
|
|
22
|
+
output: "File"
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* GraphQL schema file extensions
|
|
27
|
+
*/
|
|
28
|
+
const GRAPHQL_EXTENSIONS = [".graphql", ".gql"];
|
|
29
|
+
/**
|
|
30
|
+
* Resolver file extensions
|
|
31
|
+
*/
|
|
32
|
+
const RESOLVER_EXTENSIONS = [".resolver.ts", ".resolver.js"];
|
|
33
|
+
/**
|
|
34
|
+
* Directive file extensions
|
|
35
|
+
*/
|
|
36
|
+
const DIRECTIVE_EXTENSIONS = [".directive.ts", ".directive.js"];
|
|
37
|
+
/**
|
|
38
|
+
* Combined pattern for glob scanning
|
|
39
|
+
*/
|
|
40
|
+
const GLOB_SCAN_PATTERN = "**/*.{graphql,gql,js,mjs,cjs,ts,mts,cts,tsx,jsx}";
|
|
41
|
+
/**
|
|
42
|
+
* GraphQL file pattern for glob
|
|
43
|
+
*/
|
|
44
|
+
const GRAPHQL_GLOB_PATTERN = "**/*.graphql";
|
|
45
|
+
/**
|
|
46
|
+
* Resolver file pattern for glob
|
|
47
|
+
*/
|
|
48
|
+
const RESOLVER_GLOB_PATTERN = "**/*.resolver.{ts,js}";
|
|
49
|
+
/**
|
|
50
|
+
* Directive file pattern for glob
|
|
51
|
+
*/
|
|
52
|
+
const DIRECTIVE_GLOB_PATTERN = "**/*.directive.{ts,js}";
|
|
53
|
+
/**
|
|
54
|
+
* Framework names
|
|
55
|
+
*/
|
|
56
|
+
const FRAMEWORK_NUXT = "nuxt";
|
|
57
|
+
const FRAMEWORK_NITRO = "nitro";
|
|
58
|
+
const FRAMEWORK_STANDALONE = "standalone";
|
|
59
|
+
/**
|
|
60
|
+
* GraphQL server framework identifiers
|
|
61
|
+
*/
|
|
62
|
+
const GRAPHQL_FRAMEWORK_YOGA = "graphql-yoga";
|
|
63
|
+
const GRAPHQL_FRAMEWORK_APOLLO = "apollo-server";
|
|
64
|
+
/**
|
|
65
|
+
* Default directory names for GraphQL files
|
|
66
|
+
*/
|
|
67
|
+
const DIR_SERVER_GRAPHQL = "server/graphql";
|
|
68
|
+
const DIR_ROUTES_GRAPHQL = "routes/graphql";
|
|
69
|
+
const DIR_APP_GRAPHQL = "app/graphql";
|
|
70
|
+
const DIR_CLIENT_GRAPHQL = "graphql";
|
|
71
|
+
const DIR_EXTERNAL = "external";
|
|
72
|
+
/**
|
|
73
|
+
* Windows-compatible server GraphQL directory
|
|
74
|
+
*/
|
|
75
|
+
const DIR_SERVER_GRAPHQL_WIN = "server\\graphql";
|
|
76
|
+
/**
|
|
77
|
+
* Build directory names
|
|
78
|
+
*/
|
|
79
|
+
const DIR_BUILD_NITRO = ".nitro";
|
|
80
|
+
const DIR_BUILD_NUXT = ".nuxt";
|
|
81
|
+
/**
|
|
82
|
+
* Default GraphQL endpoint paths
|
|
83
|
+
*/
|
|
84
|
+
const ENDPOINT_GRAPHQL = "/api/graphql";
|
|
85
|
+
const ENDPOINT_HEALTH = "/api/graphql/health";
|
|
86
|
+
const ENDPOINT_DEBUG = "/_nitro/graphql/debug";
|
|
87
|
+
/**
|
|
88
|
+
* Configuration and scaffold file names
|
|
89
|
+
*/
|
|
90
|
+
const FILE_GRAPHQL_CONFIG = "graphql.config.ts";
|
|
91
|
+
const FILE_SCHEMA_GRAPHQL = "schema.graphql";
|
|
92
|
+
const FILE_SCHEMA_TS = "schema.ts";
|
|
93
|
+
const FILE_CONFIG_TS = "config.ts";
|
|
94
|
+
const FILE_CONTEXT_DTS = "context.d.ts";
|
|
95
|
+
const FILE_CONTEXT_TS = "context.ts";
|
|
96
|
+
const FILE_INDEX_TS = "index.ts";
|
|
97
|
+
const FILE_OFETCH_TS = "ofetch.ts";
|
|
98
|
+
const FILE_SDK_TS = "sdk.ts";
|
|
99
|
+
const FILE_DIRECTIVES_GRAPHQL = "_directives.graphql";
|
|
100
|
+
/**
|
|
101
|
+
* Generated type definition file names
|
|
102
|
+
*/
|
|
103
|
+
const FILE_SERVER_TYPES = "nitro-graphql-server.d.ts";
|
|
104
|
+
const FILE_CLIENT_TYPES = "nitro-graphql-client.d.ts";
|
|
105
|
+
const FILE_GRAPHQL_DTS = "graphql.d.ts";
|
|
106
|
+
/**
|
|
107
|
+
* Generated type file name patterns with placeholders
|
|
108
|
+
*/
|
|
109
|
+
const PATTERN_CLIENT_EXTERNAL_TYPES = "nitro-graphql-client-{serviceName}.d.ts";
|
|
110
|
+
/**
|
|
111
|
+
* Rollup/Rolldown chunk output paths
|
|
112
|
+
*/
|
|
113
|
+
const CHUNK_PATH_GRAPHQL = "chunks/graphql/[name].mjs";
|
|
114
|
+
const CHUNK_PATH_UNKNOWN = "chunks/_/[name].mjs";
|
|
115
|
+
/**
|
|
116
|
+
* Default chunk names
|
|
117
|
+
*/
|
|
118
|
+
const CHUNK_NAME_SCHEMAS = "schemas";
|
|
119
|
+
const CHUNK_NAME_RESOLVERS = "resolvers";
|
|
120
|
+
/**
|
|
121
|
+
* Valid define function names for resolver exports
|
|
122
|
+
*/
|
|
123
|
+
const DEFINE_FUNCTIONS = [
|
|
124
|
+
"defineResolver",
|
|
125
|
+
"defineQuery",
|
|
126
|
+
"defineMutation",
|
|
127
|
+
"defineField",
|
|
128
|
+
"defineSubscription",
|
|
129
|
+
"defineDirective"
|
|
130
|
+
];
|
|
131
|
+
const DEFINE_RESOLVER = "defineResolver";
|
|
132
|
+
const DEFINE_QUERY = "defineQuery";
|
|
133
|
+
const DEFINE_MUTATION = "defineMutation";
|
|
134
|
+
const DEFINE_FIELD = "defineField";
|
|
135
|
+
const DEFINE_SUBSCRIPTION = "defineSubscription";
|
|
136
|
+
const DEFINE_DIRECTIVE = "defineDirective";
|
|
137
|
+
const DEFINE_GRAPHQL_CONFIG = "defineGraphQLConfig";
|
|
138
|
+
const DEFINE_SCHEMA = "defineSchema";
|
|
139
|
+
/**
|
|
140
|
+
* Built-in GraphQL scalar types (should not be flagged as duplicates)
|
|
141
|
+
*/
|
|
142
|
+
const BUILTIN_SCALARS = [
|
|
143
|
+
"String",
|
|
144
|
+
"Int",
|
|
145
|
+
"Float",
|
|
146
|
+
"Boolean",
|
|
147
|
+
"ID",
|
|
148
|
+
"DateTime",
|
|
149
|
+
"JSON"
|
|
150
|
+
];
|
|
151
|
+
/**
|
|
152
|
+
* Codegen parser dependencies (always external)
|
|
153
|
+
*/
|
|
154
|
+
const CODEGEN_EXTERNALS = ["oxc-parser", "@oxc-parser"];
|
|
155
|
+
/**
|
|
156
|
+
* Apollo Federation dependencies (external when federation disabled)
|
|
157
|
+
*/
|
|
158
|
+
const FEDERATION_EXTERNALS = [
|
|
159
|
+
"@apollo/subgraph",
|
|
160
|
+
"@apollo/federation-internals",
|
|
161
|
+
"@apollo/cache-control-types"
|
|
162
|
+
];
|
|
163
|
+
/**
|
|
164
|
+
* Supported HTTP methods for GraphQL endpoints
|
|
165
|
+
*/
|
|
166
|
+
const GRAPHQL_HTTP_METHODS = [
|
|
167
|
+
"GET",
|
|
168
|
+
"POST",
|
|
169
|
+
"OPTIONS"
|
|
170
|
+
];
|
|
171
|
+
/**
|
|
172
|
+
* Default paths for type generation (relative to buildDir)
|
|
173
|
+
*/
|
|
174
|
+
const DEFAULT_SERVER_TYPES_PATH = ".graphql/nitro-graphql-server.d.ts";
|
|
175
|
+
const DEFAULT_CLIENT_TYPES_PATH = ".graphql/nitro-graphql-client.d.ts";
|
|
176
|
+
/**
|
|
177
|
+
* Valid resolver export types detected from AST parsing
|
|
178
|
+
*/
|
|
179
|
+
const RESOLVER_TYPE_QUERY = "query";
|
|
180
|
+
const RESOLVER_TYPE_MUTATION = "mutation";
|
|
181
|
+
const RESOLVER_TYPE_RESOLVER = "resolver";
|
|
182
|
+
const RESOLVER_TYPE_TYPE = "type";
|
|
183
|
+
const RESOLVER_TYPE_SUBSCRIPTION = "subscription";
|
|
184
|
+
const RESOLVER_TYPE_DIRECTIVE = "directive";
|
|
185
|
+
/**
|
|
186
|
+
* Placeholder strings used in path resolution
|
|
187
|
+
*/
|
|
188
|
+
const PLACEHOLDER_SERVICE_NAME = "{serviceName}";
|
|
189
|
+
const PLACEHOLDER_BUILD_DIR = "{buildDir}";
|
|
190
|
+
const PLACEHOLDER_ROOT_DIR = "{rootDir}";
|
|
191
|
+
const PLACEHOLDER_FRAMEWORK = "{framework}";
|
|
192
|
+
const PLACEHOLDER_TYPES_DIR = "{typesDir}";
|
|
193
|
+
const PLACEHOLDER_SERVER_GRAPHQL = "{serverGraphql}";
|
|
194
|
+
const PLACEHOLDER_CLIENT_GRAPHQL = "{clientGraphql}";
|
|
195
|
+
/**
|
|
196
|
+
* Logger tag for nitro-graphql module
|
|
197
|
+
*/
|
|
198
|
+
const LOG_TAG = "nitro-graphql";
|
|
199
|
+
/**
|
|
200
|
+
* HTTP status codes for error handling
|
|
201
|
+
*/
|
|
202
|
+
const HTTP_STATUS_BAD_REQUEST = 400;
|
|
203
|
+
const HTTP_STATUS_INTERNAL_ERROR = 500;
|
|
204
|
+
/**
|
|
205
|
+
* Default service directory name for main service
|
|
206
|
+
*/
|
|
207
|
+
const SERVICE_DEFAULT = "default";
|
|
208
|
+
|
|
209
|
+
//#endregion
|
|
210
|
+
export { BUILTIN_SCALARS, CHUNK_NAME_RESOLVERS, CHUNK_NAME_SCHEMAS, CHUNK_PATH_GRAPHQL, CHUNK_PATH_UNKNOWN, CODEGEN_EXTERNALS, DEFAULT_CLIENT_TYPES_PATH, DEFAULT_GRAPHQL_SCALARS, DEFAULT_SERVER_TYPES_PATH, DEFINE_DIRECTIVE, DEFINE_FIELD, DEFINE_FUNCTIONS, DEFINE_GRAPHQL_CONFIG, DEFINE_MUTATION, DEFINE_QUERY, DEFINE_RESOLVER, DEFINE_SCHEMA, DEFINE_SUBSCRIPTION, DIRECTIVE_EXTENSIONS, DIRECTIVE_GLOB_PATTERN, DIR_APP_GRAPHQL, DIR_BUILD_NITRO, DIR_BUILD_NUXT, DIR_CLIENT_GRAPHQL, DIR_EXTERNAL, DIR_ROUTES_GRAPHQL, DIR_SERVER_GRAPHQL, DIR_SERVER_GRAPHQL_WIN, ENDPOINT_DEBUG, ENDPOINT_GRAPHQL, ENDPOINT_HEALTH, FEDERATION_EXTERNALS, FILE_CLIENT_TYPES, FILE_CONFIG_TS, FILE_CONTEXT_DTS, FILE_CONTEXT_TS, FILE_DIRECTIVES_GRAPHQL, FILE_GRAPHQL_CONFIG, FILE_GRAPHQL_DTS, FILE_INDEX_TS, FILE_OFETCH_TS, FILE_SCHEMA_GRAPHQL, FILE_SCHEMA_TS, FILE_SDK_TS, FILE_SERVER_TYPES, FRAMEWORK_NITRO, FRAMEWORK_NUXT, FRAMEWORK_STANDALONE, GLOB_SCAN_PATTERN, GRAPHQL_EXTENSIONS, GRAPHQL_FRAMEWORK_APOLLO, GRAPHQL_FRAMEWORK_YOGA, GRAPHQL_GLOB_PATTERN, GRAPHQL_HTTP_METHODS, HTTP_STATUS_BAD_REQUEST, HTTP_STATUS_INTERNAL_ERROR, LOG_TAG, PATTERN_CLIENT_EXTERNAL_TYPES, PLACEHOLDER_BUILD_DIR, PLACEHOLDER_CLIENT_GRAPHQL, PLACEHOLDER_FRAMEWORK, PLACEHOLDER_ROOT_DIR, PLACEHOLDER_SERVER_GRAPHQL, PLACEHOLDER_SERVICE_NAME, PLACEHOLDER_TYPES_DIR, RESOLVER_EXTENSIONS, RESOLVER_GLOB_PATTERN, RESOLVER_TYPE_DIRECTIVE, RESOLVER_TYPE_MUTATION, RESOLVER_TYPE_QUERY, RESOLVER_TYPE_RESOLVER, RESOLVER_TYPE_SUBSCRIPTION, RESOLVER_TYPE_TYPE, SERVICE_DEFAULT };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { BUILTIN_SCALARS, CHUNK_NAME_RESOLVERS, CHUNK_NAME_SCHEMAS, CHUNK_PATH_GRAPHQL, CHUNK_PATH_UNKNOWN, CODEGEN_EXTERNALS, DEFAULT_CLIENT_TYPES_PATH, DEFAULT_GRAPHQL_SCALARS, DEFAULT_SERVER_TYPES_PATH, DEFINE_DIRECTIVE, DEFINE_FIELD, DEFINE_FUNCTIONS, DEFINE_GRAPHQL_CONFIG, DEFINE_MUTATION, DEFINE_QUERY, DEFINE_RESOLVER, DEFINE_SCHEMA, DEFINE_SUBSCRIPTION, DIRECTIVE_EXTENSIONS, DIRECTIVE_GLOB_PATTERN, DIR_APP_GRAPHQL, DIR_BUILD_NITRO, DIR_BUILD_NUXT, DIR_CLIENT_GRAPHQL, DIR_EXTERNAL, DIR_ROUTES_GRAPHQL, DIR_SERVER_GRAPHQL, DIR_SERVER_GRAPHQL_WIN, DefineFunction, ENDPOINT_DEBUG, ENDPOINT_GRAPHQL, ENDPOINT_HEALTH, FEDERATION_EXTERNALS, FILE_CLIENT_TYPES, FILE_CONFIG_TS, FILE_CONTEXT_DTS, FILE_CONTEXT_TS, FILE_DIRECTIVES_GRAPHQL, FILE_GRAPHQL_CONFIG, FILE_GRAPHQL_DTS, FILE_INDEX_TS, FILE_OFETCH_TS, FILE_SCHEMA_GRAPHQL, FILE_SCHEMA_TS, FILE_SDK_TS, FILE_SERVER_TYPES, FRAMEWORK_NITRO, FRAMEWORK_NUXT, FRAMEWORK_STANDALONE, Framework, GLOB_SCAN_PATTERN, GRAPHQL_EXTENSIONS, GRAPHQL_FRAMEWORK_APOLLO, GRAPHQL_FRAMEWORK_YOGA, GRAPHQL_GLOB_PATTERN, GRAPHQL_HTTP_METHODS, GraphQLFramework, HTTP_STATUS_BAD_REQUEST, HTTP_STATUS_INTERNAL_ERROR, LOG_TAG, PATTERN_CLIENT_EXTERNAL_TYPES, PLACEHOLDER_BUILD_DIR, PLACEHOLDER_CLIENT_GRAPHQL, PLACEHOLDER_FRAMEWORK, PLACEHOLDER_ROOT_DIR, PLACEHOLDER_SERVER_GRAPHQL, PLACEHOLDER_SERVICE_NAME, PLACEHOLDER_TYPES_DIR, RESOLVER_EXTENSIONS, RESOLVER_GLOB_PATTERN, RESOLVER_TYPE_DIRECTIVE, RESOLVER_TYPE_MUTATION, RESOLVER_TYPE_QUERY, RESOLVER_TYPE_RESOLVER, RESOLVER_TYPE_SUBSCRIPTION, RESOLVER_TYPE_TYPE, ResolverType, SERVICE_DEFAULT } from "./constants.mjs";
|
|
2
|
+
import { ClientCodegenConfig, ClientCodegenInput, ClientCodegenResult, ExternalServiceCodegenConfig, ScalarType, SchemaLoadOptions, SdkCodegenConfig, ServerCodegenConfig, ServerCodegenInput, ServerCodegenResult } from "./types/codegen.mjs";
|
|
3
|
+
import { CoreClientUtilsConfig, CoreCodegenConfig, CoreConfig, CoreContext, CoreExternalService, CoreFederationConfig, CoreGraphQLOptions, CoreLogger, CorePathsConfig, CoreScaffoldConfig, CoreSdkConfig, CoreSecurityConfig, CoreTypesConfig } from "./types/config.mjs";
|
|
4
|
+
import { DefineDirectiveConfig, DirectiveArgument, DirectiveDefinition, Flatten, GraphQLArgumentType, GraphQLBaseType, GraphQLScalarType } from "./types/define.mjs";
|
|
5
|
+
import { ResolverImport, ScanContext, ScanResult, ScannedFile, ScannedResolver } from "./types/scanning.mjs";
|
|
6
|
+
import "./types/index.mjs";
|
|
7
|
+
import { loadGraphQLDocuments } from "./codegen/document-loader.mjs";
|
|
8
|
+
import { GraphQLLoadSchemaOptions, GraphQLTypeDefPointer, downloadAndSaveSchema, graphQLLoadSchemaSync, loadExternalSchema } from "./codegen/schema-loader.mjs";
|
|
9
|
+
import { DEFAULT_CLIENT_CODEGEN_CONFIG, generateClientTypesCore, generateExternalClientTypesCore } from "./codegen/client.mjs";
|
|
10
|
+
import { GENERATED_FILE_HEADER, pluginContent } from "./codegen/plugin.mjs";
|
|
11
|
+
import { generateResolverModule, generateRuntimeIndex, generateSchemaModule } from "./codegen/runtime.mjs";
|
|
12
|
+
import { DEFAULT_SERVER_CODEGEN_CONFIG, generateServerTypesCore, generateTypes } from "./codegen/server.mjs";
|
|
13
|
+
import { validateNoDuplicateTypes } from "./codegen/validation.mjs";
|
|
14
|
+
import "./codegen/index.mjs";
|
|
15
|
+
import { CreateCoreConfigOptions, createCoreConfig, createCoreContext, createScanContext, mergeGraphQLOptions } from "./config.mjs";
|
|
16
|
+
import { ASTScanConfig, scanWithAST } from "./scanning/ast-scanner.mjs";
|
|
17
|
+
import { deduplicateFiles, extractPaths, filterByExtension, scanDirectory } from "./scanning/common.mjs";
|
|
18
|
+
import { scanDirectivesCore } from "./scanning/directives.mjs";
|
|
19
|
+
import { ScanDocumentsOptions, scanDocumentsCore } from "./scanning/documents.mjs";
|
|
20
|
+
import { scanResolversCore } from "./scanning/resolvers.mjs";
|
|
21
|
+
import { scanGraphqlCore, scanSchemasCore } from "./scanning/schemas.mjs";
|
|
22
|
+
import { CreateMergedSchemaOptions, DirectiveWrapper, ModuleConfig, ResolverDefinition, SchemaDefinition, buildGraphQLSchema, createMergedSchema } from "./schema/builder.mjs";
|
|
23
|
+
import { loadFederationSupport, resetFederationCache, warnFederationUnavailable } from "./schema/federation.mjs";
|
|
24
|
+
import "./schema/index.mjs";
|
|
25
|
+
import { DirectiveFileRef, DirectiveParser, ParsedDirective, directiveParser, generateDirectiveSchema, generateDirectiveSchemas } from "./utils/directive-parser.mjs";
|
|
26
|
+
import { MaskErrorOptions, createDefaultMaskError } from "./utils/errors.mjs";
|
|
27
|
+
import { ensureDir, readFileSafe, writeFile, writeFileIfChanged } from "./utils/file-io.mjs";
|
|
28
|
+
import { getImportId, relativeWithDot } from "./utils/imports.mjs";
|
|
29
|
+
import { createLogger, createSilentLogger, defaultLogger } from "./utils/logger.mjs";
|
|
30
|
+
import { OfetchTemplateOptions, generateOfetchTemplate } from "./utils/ofetch-templates.mjs";
|
|
31
|
+
import { validateExternalServices } from "./validation/external-services.mjs";
|
|
32
|
+
export { ASTScanConfig, BUILTIN_SCALARS, CHUNK_NAME_RESOLVERS, CHUNK_NAME_SCHEMAS, CHUNK_PATH_GRAPHQL, CHUNK_PATH_UNKNOWN, CODEGEN_EXTERNALS, ClientCodegenConfig, ClientCodegenInput, ClientCodegenResult, CoreClientUtilsConfig, CoreCodegenConfig, CoreConfig, CoreContext, CoreExternalService, CoreFederationConfig, CoreGraphQLOptions, CoreLogger, CorePathsConfig, CoreScaffoldConfig, CoreSdkConfig, CoreSecurityConfig, CoreTypesConfig, CreateCoreConfigOptions, CreateMergedSchemaOptions, DEFAULT_CLIENT_CODEGEN_CONFIG, DEFAULT_CLIENT_TYPES_PATH, DEFAULT_GRAPHQL_SCALARS, DEFAULT_SERVER_CODEGEN_CONFIG, DEFAULT_SERVER_TYPES_PATH, DEFINE_DIRECTIVE, DEFINE_FIELD, DEFINE_FUNCTIONS, DEFINE_GRAPHQL_CONFIG, DEFINE_MUTATION, DEFINE_QUERY, DEFINE_RESOLVER, DEFINE_SCHEMA, DEFINE_SUBSCRIPTION, DIRECTIVE_EXTENSIONS, DIRECTIVE_GLOB_PATTERN, DIR_APP_GRAPHQL, DIR_BUILD_NITRO, DIR_BUILD_NUXT, DIR_CLIENT_GRAPHQL, DIR_EXTERNAL, DIR_ROUTES_GRAPHQL, DIR_SERVER_GRAPHQL, DIR_SERVER_GRAPHQL_WIN, DefineDirectiveConfig, DefineFunction, DirectiveArgument, DirectiveDefinition, DirectiveFileRef, DirectiveParser, DirectiveWrapper, ENDPOINT_DEBUG, ENDPOINT_GRAPHQL, ENDPOINT_HEALTH, ExternalServiceCodegenConfig, FEDERATION_EXTERNALS, FILE_CLIENT_TYPES, FILE_CONFIG_TS, FILE_CONTEXT_DTS, FILE_CONTEXT_TS, FILE_DIRECTIVES_GRAPHQL, FILE_GRAPHQL_CONFIG, FILE_GRAPHQL_DTS, FILE_INDEX_TS, FILE_OFETCH_TS, FILE_SCHEMA_GRAPHQL, FILE_SCHEMA_TS, FILE_SDK_TS, FILE_SERVER_TYPES, FRAMEWORK_NITRO, FRAMEWORK_NUXT, FRAMEWORK_STANDALONE, Flatten, Framework, GENERATED_FILE_HEADER, GLOB_SCAN_PATTERN, GRAPHQL_EXTENSIONS, GRAPHQL_FRAMEWORK_APOLLO, GRAPHQL_FRAMEWORK_YOGA, GRAPHQL_GLOB_PATTERN, GRAPHQL_HTTP_METHODS, GraphQLArgumentType, GraphQLBaseType, GraphQLFramework, GraphQLLoadSchemaOptions, GraphQLScalarType, GraphQLTypeDefPointer, HTTP_STATUS_BAD_REQUEST, HTTP_STATUS_INTERNAL_ERROR, LOG_TAG, MaskErrorOptions, ModuleConfig, OfetchTemplateOptions, PATTERN_CLIENT_EXTERNAL_TYPES, PLACEHOLDER_BUILD_DIR, PLACEHOLDER_CLIENT_GRAPHQL, PLACEHOLDER_FRAMEWORK, PLACEHOLDER_ROOT_DIR, PLACEHOLDER_SERVER_GRAPHQL, PLACEHOLDER_SERVICE_NAME, PLACEHOLDER_TYPES_DIR, ParsedDirective, RESOLVER_EXTENSIONS, RESOLVER_GLOB_PATTERN, RESOLVER_TYPE_DIRECTIVE, RESOLVER_TYPE_MUTATION, RESOLVER_TYPE_QUERY, RESOLVER_TYPE_RESOLVER, RESOLVER_TYPE_SUBSCRIPTION, RESOLVER_TYPE_TYPE, ResolverDefinition, ResolverImport, ResolverType, SERVICE_DEFAULT, ScalarType, ScanContext, ScanDocumentsOptions, ScanResult, ScannedFile, ScannedResolver, SchemaDefinition, SchemaLoadOptions, SdkCodegenConfig, ServerCodegenConfig, ServerCodegenInput, ServerCodegenResult, buildGraphQLSchema, createCoreConfig, createCoreContext, createDefaultMaskError, createLogger, createMergedSchema, createScanContext, createSilentLogger, deduplicateFiles, defaultLogger, directiveParser, downloadAndSaveSchema, ensureDir, extractPaths, filterByExtension, generateClientTypesCore, generateDirectiveSchema, generateDirectiveSchemas, generateExternalClientTypesCore, generateOfetchTemplate, generateResolverModule, generateRuntimeIndex, generateSchemaModule, generateServerTypesCore, generateTypes, getImportId, graphQLLoadSchemaSync, loadExternalSchema, loadFederationSupport, loadGraphQLDocuments, mergeGraphQLOptions, pluginContent, readFileSafe, relativeWithDot, resetFederationCache, scanDirectivesCore, scanDirectory, scanDocumentsCore, scanGraphqlCore, scanResolversCore, scanSchemasCore, scanWithAST, validateExternalServices, validateNoDuplicateTypes, warnFederationUnavailable, writeFile, writeFileIfChanged };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { BUILTIN_SCALARS, CHUNK_NAME_RESOLVERS, CHUNK_NAME_SCHEMAS, CHUNK_PATH_GRAPHQL, CHUNK_PATH_UNKNOWN, CODEGEN_EXTERNALS, DEFAULT_CLIENT_TYPES_PATH, DEFAULT_GRAPHQL_SCALARS, DEFAULT_SERVER_TYPES_PATH, DEFINE_DIRECTIVE, DEFINE_FIELD, DEFINE_FUNCTIONS, DEFINE_GRAPHQL_CONFIG, DEFINE_MUTATION, DEFINE_QUERY, DEFINE_RESOLVER, DEFINE_SCHEMA, DEFINE_SUBSCRIPTION, DIRECTIVE_EXTENSIONS, DIRECTIVE_GLOB_PATTERN, DIR_APP_GRAPHQL, DIR_BUILD_NITRO, DIR_BUILD_NUXT, DIR_CLIENT_GRAPHQL, DIR_EXTERNAL, DIR_ROUTES_GRAPHQL, DIR_SERVER_GRAPHQL, DIR_SERVER_GRAPHQL_WIN, ENDPOINT_DEBUG, ENDPOINT_GRAPHQL, ENDPOINT_HEALTH, FEDERATION_EXTERNALS, FILE_CLIENT_TYPES, FILE_CONFIG_TS, FILE_CONTEXT_DTS, FILE_CONTEXT_TS, FILE_DIRECTIVES_GRAPHQL, FILE_GRAPHQL_CONFIG, FILE_GRAPHQL_DTS, FILE_INDEX_TS, FILE_OFETCH_TS, FILE_SCHEMA_GRAPHQL, FILE_SCHEMA_TS, FILE_SDK_TS, FILE_SERVER_TYPES, FRAMEWORK_NITRO, FRAMEWORK_NUXT, FRAMEWORK_STANDALONE, GLOB_SCAN_PATTERN, GRAPHQL_EXTENSIONS, GRAPHQL_FRAMEWORK_APOLLO, GRAPHQL_FRAMEWORK_YOGA, GRAPHQL_GLOB_PATTERN, GRAPHQL_HTTP_METHODS, HTTP_STATUS_BAD_REQUEST, HTTP_STATUS_INTERNAL_ERROR, LOG_TAG, PATTERN_CLIENT_EXTERNAL_TYPES, PLACEHOLDER_BUILD_DIR, PLACEHOLDER_CLIENT_GRAPHQL, PLACEHOLDER_FRAMEWORK, PLACEHOLDER_ROOT_DIR, PLACEHOLDER_SERVER_GRAPHQL, PLACEHOLDER_SERVICE_NAME, PLACEHOLDER_TYPES_DIR, RESOLVER_EXTENSIONS, RESOLVER_GLOB_PATTERN, RESOLVER_TYPE_DIRECTIVE, RESOLVER_TYPE_MUTATION, RESOLVER_TYPE_QUERY, RESOLVER_TYPE_RESOLVER, RESOLVER_TYPE_SUBSCRIPTION, RESOLVER_TYPE_TYPE, SERVICE_DEFAULT } from "./constants.mjs";
|
|
2
|
+
import { GENERATED_FILE_HEADER, pluginContent } from "./codegen/plugin.mjs";
|
|
3
|
+
import { loadGraphQLDocuments } from "./codegen/document-loader.mjs";
|
|
4
|
+
import { ensureDir, readFileSafe, writeFile, writeFileIfChanged } from "./utils/file-io.mjs";
|
|
5
|
+
import { downloadAndSaveSchema, graphQLLoadSchemaSync, loadExternalSchema } from "./codegen/schema-loader.mjs";
|
|
6
|
+
import { DEFAULT_CLIENT_CODEGEN_CONFIG, generateClientTypesCore, generateExternalClientTypesCore } from "./codegen/client.mjs";
|
|
7
|
+
import { generateResolverModule, generateRuntimeIndex, generateSchemaModule } from "./codegen/runtime.mjs";
|
|
8
|
+
import { DEFAULT_SERVER_CODEGEN_CONFIG, generateServerTypesCore, generateTypes } from "./codegen/server.mjs";
|
|
9
|
+
import { validateNoDuplicateTypes } from "./codegen/validation.mjs";
|
|
10
|
+
import { createLogger, createSilentLogger, defaultLogger } from "./utils/logger.mjs";
|
|
11
|
+
import { createCoreConfig, createCoreContext, createScanContext, mergeGraphQLOptions } from "./config.mjs";
|
|
12
|
+
import { deduplicateFiles, extractPaths, filterByExtension, scanDirectory } from "./scanning/common.mjs";
|
|
13
|
+
import { scanWithAST } from "./scanning/ast-scanner.mjs";
|
|
14
|
+
import { scanDirectivesCore } from "./scanning/directives.mjs";
|
|
15
|
+
import { scanDocumentsCore } from "./scanning/documents.mjs";
|
|
16
|
+
import { scanResolversCore } from "./scanning/resolvers.mjs";
|
|
17
|
+
import { scanGraphqlCore, scanSchemasCore } from "./scanning/schemas.mjs";
|
|
18
|
+
import { loadFederationSupport, resetFederationCache, warnFederationUnavailable } from "./schema/federation.mjs";
|
|
19
|
+
import { buildGraphQLSchema, createMergedSchema } from "./schema/builder.mjs";
|
|
20
|
+
import { DirectiveParser, directiveParser, generateDirectiveSchema, generateDirectiveSchemas } from "./utils/directive-parser.mjs";
|
|
21
|
+
import { createDefaultMaskError } from "./utils/errors.mjs";
|
|
22
|
+
import { getImportId, relativeWithDot } from "./utils/imports.mjs";
|
|
23
|
+
import { generateOfetchTemplate } from "./utils/ofetch-templates.mjs";
|
|
24
|
+
import { validateExternalServices } from "./validation/external-services.mjs";
|
|
25
|
+
|
|
26
|
+
export { BUILTIN_SCALARS, CHUNK_NAME_RESOLVERS, CHUNK_NAME_SCHEMAS, CHUNK_PATH_GRAPHQL, CHUNK_PATH_UNKNOWN, CODEGEN_EXTERNALS, DEFAULT_CLIENT_CODEGEN_CONFIG, DEFAULT_CLIENT_TYPES_PATH, DEFAULT_GRAPHQL_SCALARS, DEFAULT_SERVER_CODEGEN_CONFIG, DEFAULT_SERVER_TYPES_PATH, DEFINE_DIRECTIVE, DEFINE_FIELD, DEFINE_FUNCTIONS, DEFINE_GRAPHQL_CONFIG, DEFINE_MUTATION, DEFINE_QUERY, DEFINE_RESOLVER, DEFINE_SCHEMA, DEFINE_SUBSCRIPTION, DIRECTIVE_EXTENSIONS, DIRECTIVE_GLOB_PATTERN, DIR_APP_GRAPHQL, DIR_BUILD_NITRO, DIR_BUILD_NUXT, DIR_CLIENT_GRAPHQL, DIR_EXTERNAL, DIR_ROUTES_GRAPHQL, DIR_SERVER_GRAPHQL, DIR_SERVER_GRAPHQL_WIN, DirectiveParser, ENDPOINT_DEBUG, ENDPOINT_GRAPHQL, ENDPOINT_HEALTH, FEDERATION_EXTERNALS, FILE_CLIENT_TYPES, FILE_CONFIG_TS, FILE_CONTEXT_DTS, FILE_CONTEXT_TS, FILE_DIRECTIVES_GRAPHQL, FILE_GRAPHQL_CONFIG, FILE_GRAPHQL_DTS, FILE_INDEX_TS, FILE_OFETCH_TS, FILE_SCHEMA_GRAPHQL, FILE_SCHEMA_TS, FILE_SDK_TS, FILE_SERVER_TYPES, FRAMEWORK_NITRO, FRAMEWORK_NUXT, FRAMEWORK_STANDALONE, GENERATED_FILE_HEADER, GLOB_SCAN_PATTERN, GRAPHQL_EXTENSIONS, GRAPHQL_FRAMEWORK_APOLLO, GRAPHQL_FRAMEWORK_YOGA, GRAPHQL_GLOB_PATTERN, GRAPHQL_HTTP_METHODS, HTTP_STATUS_BAD_REQUEST, HTTP_STATUS_INTERNAL_ERROR, LOG_TAG, PATTERN_CLIENT_EXTERNAL_TYPES, PLACEHOLDER_BUILD_DIR, PLACEHOLDER_CLIENT_GRAPHQL, PLACEHOLDER_FRAMEWORK, PLACEHOLDER_ROOT_DIR, PLACEHOLDER_SERVER_GRAPHQL, PLACEHOLDER_SERVICE_NAME, PLACEHOLDER_TYPES_DIR, RESOLVER_EXTENSIONS, RESOLVER_GLOB_PATTERN, RESOLVER_TYPE_DIRECTIVE, RESOLVER_TYPE_MUTATION, RESOLVER_TYPE_QUERY, RESOLVER_TYPE_RESOLVER, RESOLVER_TYPE_SUBSCRIPTION, RESOLVER_TYPE_TYPE, SERVICE_DEFAULT, buildGraphQLSchema, createCoreConfig, createCoreContext, createDefaultMaskError, createLogger, createMergedSchema, createScanContext, createSilentLogger, deduplicateFiles, defaultLogger, directiveParser, downloadAndSaveSchema, ensureDir, extractPaths, filterByExtension, generateClientTypesCore, generateDirectiveSchema, generateDirectiveSchemas, generateExternalClientTypesCore, generateOfetchTemplate, generateResolverModule, generateRuntimeIndex, generateSchemaModule, generateServerTypesCore, generateTypes, getImportId, graphQLLoadSchemaSync, loadExternalSchema, loadFederationSupport, loadGraphQLDocuments, mergeGraphQLOptions, pluginContent, readFileSafe, relativeWithDot, resetFederationCache, scanDirectivesCore, scanDirectory, scanDocumentsCore, scanGraphqlCore, scanResolversCore, scanSchemasCore, scanWithAST, validateExternalServices, validateNoDuplicateTypes, warnFederationUnavailable, writeFile, writeFileIfChanged };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ResolverImport, ScanContext, ScanResult, ScannedResolver } from "../types/scanning.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/core/scanning/ast-scanner.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Configuration for AST-based scanning
|
|
7
|
+
*/
|
|
8
|
+
interface ASTScanConfig {
|
|
9
|
+
/** Glob pattern for files to scan */
|
|
10
|
+
pattern: string;
|
|
11
|
+
/** Parse a function call and return import info, or null if not a valid export */
|
|
12
|
+
parseCall: (calleeName: string, exportName: string, filePath: string) => ResolverImport | null;
|
|
13
|
+
/** Whether to emit warnings for common issues (default: true for resolvers) */
|
|
14
|
+
emitWarnings?: boolean;
|
|
15
|
+
/** Valid function names for warning messages */
|
|
16
|
+
validFunctions?: readonly string[];
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Scan files matching a pattern and parse their exports using AST
|
|
20
|
+
*/
|
|
21
|
+
declare function scanWithAST(ctx: ScanContext, config: ASTScanConfig): Promise<ScanResult<ScannedResolver>>;
|
|
22
|
+
//#endregion
|
|
23
|
+
export { ASTScanConfig, scanWithAST };
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { scanWithLayers } from "./common.mjs";
|
|
2
|
+
import { readFile } from "node:fs/promises";
|
|
3
|
+
import { basename, relative } from "pathe";
|
|
4
|
+
import { parseSync } from "oxc-parser";
|
|
5
|
+
|
|
6
|
+
//#region src/core/scanning/ast-scanner.ts
|
|
7
|
+
/**
|
|
8
|
+
* Scan files matching a pattern and parse their exports using AST
|
|
9
|
+
*/
|
|
10
|
+
async function scanWithAST(ctx, config) {
|
|
11
|
+
const warnings = [];
|
|
12
|
+
const errors = [];
|
|
13
|
+
try {
|
|
14
|
+
const serverDirRelative = relative(ctx.rootDir, ctx.serverDir);
|
|
15
|
+
const files = await scanWithLayers(ctx, {
|
|
16
|
+
mainDir: ctx.rootDir,
|
|
17
|
+
mainSubDir: serverDirRelative,
|
|
18
|
+
layerDirs: ctx.layerServerDirs,
|
|
19
|
+
layerSubDir: "graphql",
|
|
20
|
+
pattern: config.pattern
|
|
21
|
+
});
|
|
22
|
+
const results = [];
|
|
23
|
+
for (const file of files) try {
|
|
24
|
+
const fileContent = await readFile(file.fullPath, "utf-8");
|
|
25
|
+
const parsed = parseSync(file.fullPath, fileContent);
|
|
26
|
+
if (parsed.errors && parsed.errors.length > 0) {
|
|
27
|
+
if (ctx.isDev) {
|
|
28
|
+
const fileName = basename(file.fullPath);
|
|
29
|
+
const firstError = parsed.errors[0];
|
|
30
|
+
const location = firstError?.labels?.[0];
|
|
31
|
+
const lineInfo = location ? `:${location.start}` : "";
|
|
32
|
+
const message = firstError?.message.split(",")[0] || "Syntax error";
|
|
33
|
+
errors.push(`${fileName}${lineInfo} - ${message}`);
|
|
34
|
+
}
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
const result = parseExports(file.fullPath, parsed.program, config);
|
|
38
|
+
if (ctx.isDev && config.emitWarnings && result.warnings.length > 0) {
|
|
39
|
+
const relPath = relative(ctx.rootDir, file.fullPath);
|
|
40
|
+
for (const warning of result.warnings) warnings.push(`${relPath}: ${warning}`);
|
|
41
|
+
}
|
|
42
|
+
if (result.resolver.imports.length > 0) results.push(result.resolver);
|
|
43
|
+
} catch (error) {
|
|
44
|
+
const relPath = relative(ctx.rootDir, file.fullPath);
|
|
45
|
+
errors.push(`Failed to parse file ${relPath}: ${error}`);
|
|
46
|
+
}
|
|
47
|
+
return {
|
|
48
|
+
items: results,
|
|
49
|
+
warnings,
|
|
50
|
+
errors
|
|
51
|
+
};
|
|
52
|
+
} catch (error) {
|
|
53
|
+
errors.push(`Scanning error: ${error}`);
|
|
54
|
+
return {
|
|
55
|
+
items: [],
|
|
56
|
+
warnings,
|
|
57
|
+
errors
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Parse exports from AST program
|
|
63
|
+
*/
|
|
64
|
+
function parseExports(filePath, program, config) {
|
|
65
|
+
const warnings = [];
|
|
66
|
+
const resolver = {
|
|
67
|
+
specifier: filePath,
|
|
68
|
+
imports: []
|
|
69
|
+
};
|
|
70
|
+
let hasDefaultExport = false;
|
|
71
|
+
let hasNamedExport = false;
|
|
72
|
+
const namedExports = [];
|
|
73
|
+
for (const node of program.body) {
|
|
74
|
+
if (node.type === "ExportDefaultDeclaration") hasDefaultExport = true;
|
|
75
|
+
if (node.type === "ExportNamedDeclaration" && node.declaration && node.declaration.type === "VariableDeclaration") {
|
|
76
|
+
for (const decl of node.declaration.declarations) if (decl.type === "VariableDeclarator" && decl.init && decl.id.type === "Identifier") {
|
|
77
|
+
hasNamedExport = true;
|
|
78
|
+
namedExports.push(decl.id.name);
|
|
79
|
+
if (decl.init && decl.init.type === "CallExpression") {
|
|
80
|
+
if (decl.init.callee.type === "Identifier") {
|
|
81
|
+
const imp = config.parseCall(decl.init.callee.name, decl.id.name, filePath);
|
|
82
|
+
if (imp) resolver.imports.push(imp);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
if (config.emitWarnings) {
|
|
89
|
+
if (hasDefaultExport && !hasNamedExport) warnings.push("Using default export instead of named export. Must use named exports like \"export const myResolver = defineQuery(...)\". Default exports are not detected.");
|
|
90
|
+
if (resolver.imports.length === 0 && hasNamedExport) {
|
|
91
|
+
const validFunctions = config.validFunctions?.join(", ") || "define* functions";
|
|
92
|
+
warnings.push(`File has named exports [${namedExports.join(", ")}] but none use the required define functions (${validFunctions}). Exports will not be registered.`);
|
|
93
|
+
}
|
|
94
|
+
if (!hasDefaultExport && !hasNamedExport) warnings.push("No exports found. Files must export using define* functions.");
|
|
95
|
+
}
|
|
96
|
+
return {
|
|
97
|
+
resolver,
|
|
98
|
+
warnings
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
//#endregion
|
|
103
|
+
export { scanWithAST };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { ScanContext, ScannedFile } from "../types/scanning.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/core/scanning/common.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Scan a directory for files matching a glob pattern
|
|
7
|
+
*/
|
|
8
|
+
declare function scanDirectory(ctx: ScanContext, baseDir: string, subDir: string, globPattern?: string): Promise<ScannedFile[]>;
|
|
9
|
+
/**
|
|
10
|
+
* Deduplicate files by fullPath
|
|
11
|
+
*/
|
|
12
|
+
declare function deduplicateFiles<T extends {
|
|
13
|
+
fullPath: string;
|
|
14
|
+
}>(files: T[]): T[];
|
|
15
|
+
/**
|
|
16
|
+
* Filter files by extension
|
|
17
|
+
*/
|
|
18
|
+
declare function filterByExtension<T extends {
|
|
19
|
+
fullPath: string;
|
|
20
|
+
}>(files: T[], extensions: readonly string[]): T[];
|
|
21
|
+
/**
|
|
22
|
+
* Extract file paths from scanned files
|
|
23
|
+
*/
|
|
24
|
+
declare function extractPaths(files: ScannedFile[]): string[];
|
|
25
|
+
/**
|
|
26
|
+
* Scan directory with layer support
|
|
27
|
+
* Encapsulates the common pattern of scanning main directory + layer directories
|
|
28
|
+
*/
|
|
29
|
+
declare function scanWithLayers(ctx: ScanContext, options: {
|
|
30
|
+
mainDir: string;
|
|
31
|
+
mainSubDir: string;
|
|
32
|
+
layerDirs: string[] | undefined;
|
|
33
|
+
layerSubDir: string;
|
|
34
|
+
pattern: string;
|
|
35
|
+
}): Promise<ScannedFile[]>;
|
|
36
|
+
//#endregion
|
|
37
|
+
export { deduplicateFiles, extractPaths, filterByExtension, scanDirectory, scanWithLayers };
|