nitro-graphql 2.0.0-beta.72 → 2.0.0-beta.73
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 +1 -1
- package/dist/cli/adapter.d.mts +0 -3
- package/dist/cli/adapter.mjs +6 -29
- package/dist/cli/commands/generate.mjs +2 -2
- package/dist/cli/config.d.mts +4 -5
- package/dist/cli/config.mjs +3 -1
- package/dist/cli/index.d.mts +3 -6
- package/dist/cli/index.mjs +1 -1
- package/dist/cli/server/graphql-handler.mjs +2 -1
- package/dist/cli/server/watcher.mjs +1 -1
- package/dist/core/codegen/client.d.mts +4 -27
- package/dist/core/codegen/client.mjs +26 -445
- package/dist/core/codegen/file-header.d.mts +7 -0
- package/dist/core/codegen/file-header.mjs +12 -0
- package/dist/core/codegen/index.d.mts +7 -5
- package/dist/core/codegen/index.mjs +7 -5
- package/dist/core/codegen/{runtime.d.mts → runtime-generator.d.mts} +1 -1
- package/dist/core/codegen/{runtime.mjs → runtime-generator.mjs} +1 -1
- package/dist/core/codegen/schema-loader.d.mts +2 -7
- package/dist/core/codegen/schema-loader.mjs +65 -70
- package/dist/core/codegen/server-type-helpers.d.mts +14 -0
- package/dist/core/codegen/server-type-helpers.mjs +76 -0
- package/dist/core/codegen/server.d.mts +1 -15
- package/dist/core/codegen/server.mjs +15 -105
- package/dist/core/codegen/subscription-extractor.d.mts +20 -0
- package/dist/core/codegen/subscription-extractor.mjs +30 -0
- package/dist/core/codegen/vue-subscription-builder.d.mts +10 -0
- package/dist/core/codegen/vue-subscription-builder.mjs +351 -0
- package/dist/core/constants.d.mts +5 -53
- package/dist/core/constants.mjs +13 -54
- package/dist/core/create-config.d.mts +31 -0
- package/dist/core/create-config.mjs +42 -0
- package/dist/core/debug/index.d.mts +2 -2
- package/dist/core/debug/index.mjs +2 -2
- package/dist/core/debug/template.d.mts +1 -5
- package/dist/core/debug/template.mjs +1 -1
- package/dist/core/extend/loader.d.mts +0 -1
- package/dist/core/extend/loader.mjs +59 -89
- package/dist/core/index.d.mts +22 -17
- package/dist/core/index.mjs +19 -15
- package/dist/core/manifest.mjs +3 -1
- package/dist/core/pubsub/index.d.mts +2 -109
- package/dist/core/pubsub/index.mjs +1 -145
- package/dist/core/pubsub/memory-pubsub.d.mts +109 -0
- package/dist/core/pubsub/memory-pubsub.mjs +146 -0
- package/dist/core/scanning/ast-scanner.mjs +4 -2
- package/dist/core/scanning/directives.mjs +2 -3
- package/dist/core/scanning/documents.d.mts +4 -3
- package/dist/core/scanning/documents.mjs +1 -1
- package/dist/core/scanning/{common.d.mts → file-scanner.d.mts} +1 -1
- package/dist/core/scanning/{common.mjs → file-scanner.mjs} +2 -10
- package/dist/core/scanning/index.d.mts +3 -3
- package/dist/core/scanning/index.mjs +3 -3
- package/dist/core/scanning/resolvers.mjs +8 -9
- package/dist/core/scanning/schemas.d.mts +1 -5
- package/dist/core/scanning/schemas.mjs +2 -24
- package/dist/core/schema/builder.d.mts +4 -2
- package/dist/core/schema/builder.mjs +4 -2
- package/dist/core/schema/index.d.mts +2 -2
- package/dist/core/schema/index.mjs +2 -2
- package/dist/core/server/apollo.d.mts +20 -0
- package/dist/core/server/apollo.mjs +54 -0
- package/dist/core/server/index.d.mts +4 -2
- package/dist/core/server/index.mjs +3 -2
- package/dist/core/server/types.d.mts +7 -14
- package/dist/core/server/types.mjs +15 -1
- package/dist/core/server/yoga.d.mts +1 -7
- package/dist/core/server/yoga.mjs +4 -13
- package/dist/core/types/adapter.d.mts +4 -39
- package/dist/core/types/codegen.d.mts +22 -45
- package/dist/core/types/config.d.mts +33 -121
- package/dist/core/types/define.d.mts +8 -5
- package/dist/core/types/index.d.mts +5 -4
- package/dist/core/types/scanning.d.mts +4 -1
- package/dist/core/types/standard-schema.d.mts +64 -0
- package/dist/core/utils/directive-parser.d.mts +8 -63
- package/dist/core/utils/directive-parser.mjs +114 -166
- package/dist/core/utils/file-io.d.mts +1 -5
- package/dist/core/utils/file-io.mjs +1 -11
- package/dist/core/utils/index.d.mts +5 -4
- package/dist/core/utils/index.mjs +6 -5
- package/dist/core/utils/logger.d.mts +1 -10
- package/dist/core/utils/logger.mjs +1 -19
- package/dist/core/utils/ofetch-templates.mjs +3 -4
- package/dist/core/utils/runtime.d.mts +1 -30
- package/dist/core/utils/runtime.mjs +2 -44
- package/dist/core/utils/string.d.mts +10 -0
- package/dist/core/utils/string.mjs +12 -0
- package/dist/core/watcher/create-watcher.d.mts +103 -0
- package/dist/core/watcher/create-watcher.mjs +143 -0
- package/dist/core/watcher/index.d.mts +2 -107
- package/dist/core/watcher/index.mjs +1 -139
- package/dist/define.d.mts +4 -2
- package/dist/define.mjs +7 -6
- package/dist/index.d.mts +4 -3
- package/dist/index.mjs +1 -1
- package/dist/nitro/adapter.d.mts +6 -10
- package/dist/nitro/adapter.mjs +12 -42
- package/dist/nitro/codegen/client-types.d.mts +12 -0
- package/dist/nitro/codegen/client-types.mjs +73 -0
- package/dist/nitro/codegen/external-types.d.mts +8 -0
- package/dist/nitro/codegen/external-types.mjs +47 -0
- package/dist/nitro/codegen/index.d.mts +4 -0
- package/dist/nitro/codegen/index.mjs +4 -0
- package/dist/nitro/codegen/server-types.d.mts +12 -0
- package/dist/nitro/codegen/server-types.mjs +81 -0
- package/dist/nitro/defaults.d.mts +28 -0
- package/dist/nitro/defaults.mjs +34 -0
- package/dist/nitro/index.d.mts +11 -3
- package/dist/nitro/index.mjs +1 -1
- package/dist/nitro/paths.d.mts +3 -2
- package/dist/nitro/paths.mjs +13 -9
- package/dist/nitro/rollup.mjs +4 -3
- package/dist/nitro/routes/_ws-handler.d.mts +6 -0
- package/dist/nitro/routes/_ws-handler.mjs +49 -0
- package/dist/nitro/routes/apollo-server-ws.d.mts +1 -1
- package/dist/nitro/routes/apollo-server-ws.mjs +9 -44
- package/dist/nitro/routes/apollo-server.d.mts +1 -1
- package/dist/nitro/routes/apollo-server.mjs +16 -55
- package/dist/nitro/routes/debug.d.mts +1 -1
- package/dist/nitro/routes/debug.mjs +1 -0
- package/dist/nitro/routes/graphql-yoga-ws.d.mts +1 -1
- package/dist/nitro/routes/graphql-yoga-ws.mjs +6 -44
- package/dist/nitro/routes/graphql-yoga.mjs +7 -5
- package/dist/nitro/routes/health.mjs +22 -24
- package/dist/nitro/setup/extend-loader.d.mts +6 -5
- package/dist/nitro/setup/extend-loader.mjs +30 -58
- package/dist/nitro/setup/file-watcher.mjs +6 -4
- package/dist/nitro/setup/logging.d.mts +1 -8
- package/dist/nitro/setup/logging.mjs +7 -22
- package/dist/nitro/setup/rollup-integration.mjs +32 -1
- package/dist/nitro/setup/scanner.d.mts +8 -43
- package/dist/nitro/setup/scanner.mjs +56 -58
- package/dist/nitro/setup/security.d.mts +10 -0
- package/dist/nitro/setup/security.mjs +17 -0
- package/dist/nitro/setup/type-generation.d.mts +13 -0
- package/dist/nitro/setup/type-generation.mjs +16 -0
- package/dist/nitro/setup.d.mts +4 -3
- package/dist/nitro/setup.mjs +87 -74
- package/dist/nitro/state.d.mts +32 -0
- package/dist/nitro/state.mjs +58 -0
- package/dist/nitro/types/augmentation.d.mts +59 -0
- package/dist/nitro/types/augmentation.mjs +1 -0
- package/dist/nitro/types/config.d.mts +327 -0
- package/dist/nitro/types/config.mjs +1 -0
- package/dist/nitro/types/define.d.mts +13 -0
- package/dist/nitro/types/define.mjs +1 -0
- package/dist/nitro/types/index.d.mts +10 -0
- package/dist/nitro/types/index.mjs +1 -0
- package/dist/nitro/virtual/debug-info.d.mts +9 -0
- package/dist/nitro/virtual/debug-info.mjs +35 -0
- package/dist/nitro/virtual/graphql-config.d.mts +9 -0
- package/dist/nitro/virtual/graphql-config.mjs +33 -0
- package/dist/nitro/virtual/index.d.mts +25 -0
- package/dist/nitro/virtual/index.mjs +45 -0
- package/dist/nitro/virtual/module-config.d.mts +9 -0
- package/dist/nitro/virtual/module-config.mjs +10 -0
- package/dist/nitro/virtual/pubsub.d.mts +9 -0
- package/dist/nitro/virtual/pubsub.mjs +17 -0
- package/dist/nitro/virtual/server-directives.d.mts +9 -0
- package/dist/nitro/virtual/server-directives.mjs +12 -0
- package/dist/nitro/virtual/server-resolvers.d.mts +9 -0
- package/dist/nitro/virtual/server-resolvers.mjs +17 -0
- package/dist/nitro/virtual/server-schemas.d.mts +9 -0
- package/dist/nitro/virtual/server-schemas.mjs +31 -0
- package/dist/nitro/virtual/stubs.d.mts +42 -10
- package/dist/nitro/virtual/stubs.mjs +0 -5
- package/dist/nitro/virtual/utils.d.mts +15 -0
- package/dist/nitro/virtual/utils.mjs +26 -0
- package/dist/nitro/virtual/validation-schemas.d.mts +9 -0
- package/dist/nitro/virtual/validation-schemas.mjs +33 -0
- package/native/index.js +52 -52
- package/package.json +15 -15
- package/dist/cli/commands/index.d.mts +0 -5
- package/dist/cli/commands/index.mjs +0 -5
- package/dist/core/codegen/plugin.d.mts +0 -19
- package/dist/core/codegen/plugin.mjs +0 -29
- package/dist/core/config.d.mts +0 -45
- package/dist/core/config.mjs +0 -76
- package/dist/nitro/codegen.d.mts +0 -18
- package/dist/nitro/codegen.mjs +0 -171
- package/dist/nitro/config.d.mts +0 -50
- package/dist/nitro/config.mjs +0 -55
- package/dist/nitro/types.d.mts +0 -549
- package/dist/nitro/virtual/generators.d.mts +0 -38
- package/dist/nitro/virtual/generators.mjs +0 -190
- /package/dist/{nitro/types.mjs → core/types/standard-schema.mjs} +0 -0
|
@@ -1,190 +0,0 @@
|
|
|
1
|
-
import { resolve } from "pathe";
|
|
2
|
-
import { existsSync, readFileSync } from "node:fs";
|
|
3
|
-
import { genImport } from "knitwork";
|
|
4
|
-
//#region src/nitro/virtual/generators.ts
|
|
5
|
-
function generateImportModule(items, exportName, wrapperKey) {
|
|
6
|
-
if (!items.length) return `export const ${exportName} = []`;
|
|
7
|
-
const imports = items.flatMap(({ specifier, imports: list, options }) => list?.length ? [genImport(specifier, list, options)] : []);
|
|
8
|
-
const data = items.flatMap(({ imports: list }) => list.map((i) => `{ ${wrapperKey}: ${i.as || i.name} }`));
|
|
9
|
-
return `${imports.join("\n")}\n\nexport const ${exportName} = [\n${data.join(",\n")}\n]`;
|
|
10
|
-
}
|
|
11
|
-
function safeGenerateModuleCode(nitro, moduleName) {
|
|
12
|
-
try {
|
|
13
|
-
const generator = nitro.options.virtual?.[moduleName];
|
|
14
|
-
if (generator && typeof generator === "function") return generator();
|
|
15
|
-
return "// Module not found";
|
|
16
|
-
} catch (error) {
|
|
17
|
-
return `// Error: ${error instanceof Error ? error.message : String(error)}`;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
const serverSchemas = {
|
|
21
|
-
id: "#nitro-graphql/server-schemas",
|
|
22
|
-
getCode: (nitro) => {
|
|
23
|
-
const schemas = [...nitro.scanSchemas, ...nitro.options.graphql?.typedefs ?? []];
|
|
24
|
-
const directiveSchemas = nitro.graphql.directiveSchemas;
|
|
25
|
-
if (!schemas.length && !directiveSchemas) {
|
|
26
|
-
if (nitro.options.dev) nitro.logger.warn(`[nitro-graphql] No schemas found. Using demo schema. Add .graphql files to ${nitro.graphql.serverDir}`);
|
|
27
|
-
return `export const schemas = [
|
|
28
|
-
{ def: \`type Query {
|
|
29
|
-
hello: String!
|
|
30
|
-
}
|
|
31
|
-
\` }
|
|
32
|
-
]`;
|
|
33
|
-
}
|
|
34
|
-
const schemaArray = schemas.map((schemaPath) => {
|
|
35
|
-
try {
|
|
36
|
-
const content = readFileSync(schemaPath, "utf-8");
|
|
37
|
-
return `{ def: ${JSON.stringify(content)} }`;
|
|
38
|
-
} catch {
|
|
39
|
-
return `{ def: '' }`;
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
if (directiveSchemas) schemaArray.push(`{ def: ${JSON.stringify(directiveSchemas)} }`);
|
|
43
|
-
return `export const schemas = [\n${schemaArray.join(",\n")}\n];`;
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
const serverResolvers = {
|
|
47
|
-
id: "#nitro-graphql/server-resolvers",
|
|
48
|
-
getCode: (nitro) => {
|
|
49
|
-
const imports = [...nitro.scanResolvers];
|
|
50
|
-
if (!imports.length) {
|
|
51
|
-
if (nitro.options.dev) nitro.logger.warn(`[nitro-graphql] No resolvers found. Using demo resolver. Add .resolver.ts files to ${nitro.graphql.serverDir}`);
|
|
52
|
-
return `export const resolvers = [
|
|
53
|
-
{ resolver: { Query: { hello: () => 'Hello from nitro-graphql!' } } }
|
|
54
|
-
]`;
|
|
55
|
-
}
|
|
56
|
-
return generateImportModule(imports, "resolvers", "resolver");
|
|
57
|
-
}
|
|
58
|
-
};
|
|
59
|
-
const serverDirectives = {
|
|
60
|
-
id: "#nitro-graphql/server-directives",
|
|
61
|
-
getCode: (nitro) => {
|
|
62
|
-
const imports = nitro.scanDirectives || [];
|
|
63
|
-
if (!imports.length) return "export const directives = []";
|
|
64
|
-
return generateImportModule(imports, "directives", "directive");
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
const graphqlConfig = {
|
|
68
|
-
id: "#nitro-graphql/graphql-config",
|
|
69
|
-
getCode: (nitro) => {
|
|
70
|
-
const localConfigPath = resolve(nitro.graphql.serverDir, "config.ts");
|
|
71
|
-
const extendConfigs = nitro.graphql.extendConfigs || [];
|
|
72
|
-
const hasLocalConfig = existsSync(localConfigPath);
|
|
73
|
-
if (!hasLocalConfig && extendConfigs.length === 0) return `const importedConfig = {}
|
|
74
|
-
export { importedConfig }
|
|
75
|
-
`;
|
|
76
|
-
const imports = ["import { defu } from 'defu'"];
|
|
77
|
-
const configNames = [];
|
|
78
|
-
extendConfigs.forEach((configPath, index) => {
|
|
79
|
-
const configName = `extendConfig${index}`;
|
|
80
|
-
imports.push(`import ${configName} from '${configPath}'`);
|
|
81
|
-
configNames.push(configName);
|
|
82
|
-
});
|
|
83
|
-
if (hasLocalConfig) {
|
|
84
|
-
imports.push(`import localConfig from '${localConfigPath}'`);
|
|
85
|
-
configNames.push("localConfig");
|
|
86
|
-
}
|
|
87
|
-
const mergeArgs = configNames.reverse().join(", ");
|
|
88
|
-
return `${imports.join("\n")}
|
|
89
|
-
|
|
90
|
-
const importedConfig = defu(${mergeArgs})
|
|
91
|
-
export { importedConfig }
|
|
92
|
-
`;
|
|
93
|
-
}
|
|
94
|
-
};
|
|
95
|
-
const moduleConfig = {
|
|
96
|
-
id: "#nitro-graphql/module-config",
|
|
97
|
-
getCode: (nitro) => {
|
|
98
|
-
const config = nitro.options.graphql || {};
|
|
99
|
-
return `export const moduleConfig = ${JSON.stringify(config, null, 2)};`;
|
|
100
|
-
}
|
|
101
|
-
};
|
|
102
|
-
const validationSchemas = {
|
|
103
|
-
id: "#nitro-graphql/validation-schemas",
|
|
104
|
-
getCode: (nitro) => {
|
|
105
|
-
const localSchemaPath = resolve(nitro.graphql.serverDir, "schema.ts");
|
|
106
|
-
const extendSchemas = nitro.graphql.extendSchemas || [];
|
|
107
|
-
const hasLocalSchema = existsSync(localSchemaPath);
|
|
108
|
-
if (!hasLocalSchema && extendSchemas.length === 0) return `const mergedSchemas = {}
|
|
109
|
-
export default mergedSchemas
|
|
110
|
-
`;
|
|
111
|
-
const imports = [];
|
|
112
|
-
const schemaNames = [];
|
|
113
|
-
extendSchemas.forEach((schemaPath, index) => {
|
|
114
|
-
const schemaName = `extendSchema${index}`;
|
|
115
|
-
imports.push(`import ${schemaName} from '${schemaPath}'`);
|
|
116
|
-
schemaNames.push(schemaName);
|
|
117
|
-
});
|
|
118
|
-
if (hasLocalSchema) {
|
|
119
|
-
imports.push(`import localSchema from '${localSchemaPath}'`);
|
|
120
|
-
schemaNames.push("localSchema");
|
|
121
|
-
}
|
|
122
|
-
const mergeExpression = schemaNames.length === 1 ? schemaNames[0] : `{ ${schemaNames.map((name) => `...${name}`).join(", ")} }`;
|
|
123
|
-
return `${imports.join("\n")}
|
|
124
|
-
|
|
125
|
-
const mergedSchemas = ${mergeExpression}
|
|
126
|
-
export default mergedSchemas
|
|
127
|
-
`;
|
|
128
|
-
}
|
|
129
|
-
};
|
|
130
|
-
const pubsub = {
|
|
131
|
-
id: "#nitro-graphql/pubsub",
|
|
132
|
-
getCode: (nitro) => {
|
|
133
|
-
const subscriptions = nitro.options.graphql?.subscriptions;
|
|
134
|
-
const pubsubConfig = subscriptions?.pubsub;
|
|
135
|
-
if (!subscriptions?.enabled) return `export const pubsub = null`;
|
|
136
|
-
if (pubsubConfig?.customPath) return `import customPubSub from '${pubsubConfig.customPath}'
|
|
137
|
-
export const pubsub = customPubSub
|
|
138
|
-
`;
|
|
139
|
-
return `import { createPubSub } from 'nitro-graphql/pubsub'
|
|
140
|
-
export const pubsub = createPubSub()
|
|
141
|
-
`;
|
|
142
|
-
}
|
|
143
|
-
};
|
|
144
|
-
const debugInfo = {
|
|
145
|
-
id: "#nitro-graphql/debug-info",
|
|
146
|
-
getCode: (nitro) => {
|
|
147
|
-
const virtualModuleCodes = {
|
|
148
|
-
"server-schemas": safeGenerateModuleCode(nitro, "#nitro-graphql/server-schemas"),
|
|
149
|
-
"server-resolvers": safeGenerateModuleCode(nitro, "#nitro-graphql/server-resolvers"),
|
|
150
|
-
"server-directives": safeGenerateModuleCode(nitro, "#nitro-graphql/server-directives"),
|
|
151
|
-
"module-config": safeGenerateModuleCode(nitro, "#nitro-graphql/module-config"),
|
|
152
|
-
"graphql-config": safeGenerateModuleCode(nitro, "#nitro-graphql/graphql-config"),
|
|
153
|
-
"pubsub": safeGenerateModuleCode(nitro, "#nitro-graphql/pubsub")
|
|
154
|
-
};
|
|
155
|
-
const info = {
|
|
156
|
-
isDev: nitro.options.dev,
|
|
157
|
-
framework: nitro.options.framework.name,
|
|
158
|
-
graphqlFramework: nitro.options.graphql?.framework,
|
|
159
|
-
federation: nitro.options.graphql?.federation,
|
|
160
|
-
scanned: {
|
|
161
|
-
schemas: nitro.scanSchemas?.length || 0,
|
|
162
|
-
schemaFiles: nitro.scanSchemas || [],
|
|
163
|
-
resolvers: nitro.scanResolvers?.length || 0,
|
|
164
|
-
resolverFiles: nitro.scanResolvers || [],
|
|
165
|
-
directives: nitro.scanDirectives?.length || 0,
|
|
166
|
-
directiveFiles: nitro.scanDirectives || [],
|
|
167
|
-
documents: nitro.scanDocuments?.length || 0,
|
|
168
|
-
documentFiles: nitro.scanDocuments || []
|
|
169
|
-
},
|
|
170
|
-
virtualModules: virtualModuleCodes
|
|
171
|
-
};
|
|
172
|
-
return `export const debugInfo = ${JSON.stringify(info, null, 2)};`;
|
|
173
|
-
}
|
|
174
|
-
};
|
|
175
|
-
const allModules = [
|
|
176
|
-
serverSchemas,
|
|
177
|
-
serverResolvers,
|
|
178
|
-
serverDirectives,
|
|
179
|
-
graphqlConfig,
|
|
180
|
-
moduleConfig,
|
|
181
|
-
validationSchemas,
|
|
182
|
-
pubsub,
|
|
183
|
-
debugInfo
|
|
184
|
-
];
|
|
185
|
-
function registerAllVirtualModules(nitro) {
|
|
186
|
-
nitro.options.virtual ??= {};
|
|
187
|
-
for (const mod of allModules) nitro.options.virtual[mod.id] = () => mod.getCode(nitro);
|
|
188
|
-
}
|
|
189
|
-
//#endregion
|
|
190
|
-
export { debugInfo, graphqlConfig, moduleConfig, pubsub, registerAllVirtualModules, serverDirectives, serverResolvers, serverSchemas, validationSchemas };
|
|
File without changes
|