nitro-graphql 2.0.0-beta.7 → 2.0.0-beta.70
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 +31 -1196
- package/dist/cli/adapter.d.mts +13 -0
- package/dist/cli/adapter.mjs +69 -0
- package/dist/cli/commands/build.d.mts +21 -0
- package/dist/cli/commands/build.mjs +52 -0
- package/dist/cli/commands/dev.d.mts +40 -0
- package/dist/cli/commands/dev.mjs +76 -0
- package/dist/cli/commands/generate.d.mts +25 -0
- package/dist/cli/commands/generate.mjs +198 -0
- package/dist/cli/commands/index.d.mts +5 -0
- package/dist/cli/commands/index.mjs +6 -0
- package/dist/cli/commands/init.d.mts +45 -0
- package/dist/cli/commands/init.mjs +195 -0
- package/dist/cli/commands/validate.d.mts +9 -0
- package/dist/cli/commands/validate.mjs +67 -0
- package/dist/cli/completions.d.mts +6 -0
- package/dist/cli/completions.mjs +34 -0
- package/dist/cli/config.d.mts +18 -0
- package/dist/cli/config.mjs +20 -0
- package/dist/cli/index.d.mts +26 -0
- package/dist/cli/index.mjs +317 -0
- package/dist/cli/server/debug-handler.d.mts +9 -0
- package/dist/cli/server/debug-handler.mjs +71 -0
- package/dist/cli/server/dev-server.d.mts +29 -0
- package/dist/cli/server/dev-server.mjs +64 -0
- package/dist/cli/server/graphql-handler.d.mts +21 -0
- package/dist/cli/server/graphql-handler.mjs +45 -0
- package/dist/cli/server/health-handler.d.mts +12 -0
- package/dist/cli/server/health-handler.mjs +30 -0
- package/dist/cli/server/loader.d.mts +33 -0
- package/dist/cli/server/loader.mjs +146 -0
- package/dist/cli/server/sandbox-handler.d.mts +12 -0
- package/dist/cli/server/sandbox-handler.mjs +19 -0
- package/dist/cli/server/watcher.d.mts +20 -0
- package/dist/cli/server/watcher.mjs +66 -0
- package/dist/cli/server/ws-handler.d.mts +28 -0
- package/dist/cli/server/ws-handler.mjs +50 -0
- package/dist/config.d.mts +2 -0
- package/dist/config.mjs +3 -0
- package/dist/core/codegen/client.d.mts +42 -0
- package/dist/core/codegen/client.mjs +553 -0
- package/dist/core/codegen/document-loader.d.mts +9 -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 +19 -0
- package/dist/core/codegen/plugin.mjs +30 -0
- package/dist/core/codegen/runtime.d.mts +19 -0
- package/dist/core/codegen/runtime.mjs +60 -0
- package/dist/core/codegen/schema-loader.d.mts +27 -0
- package/dist/core/codegen/schema-loader.mjs +128 -0
- package/dist/core/codegen/server.d.mts +27 -0
- package/dist/core/codegen/server.mjs +144 -0
- package/dist/core/codegen/validation.d.mts +17 -0
- package/dist/core/codegen/validation.mjs +35 -0
- package/dist/core/config.d.mts +45 -0
- package/dist/core/config.mjs +78 -0
- package/dist/core/constants.d.mts +188 -0
- package/dist/core/constants.mjs +210 -0
- package/dist/core/debug/index.d.mts +2 -0
- package/dist/core/debug/index.mjs +3 -0
- package/dist/core/debug/template.d.mts +52 -0
- package/dist/core/debug/template.mjs +383 -0
- package/dist/core/extend/index.d.mts +2 -0
- package/dist/core/extend/index.mjs +3 -0
- package/dist/core/extend/loader.d.mts +40 -0
- package/dist/core/extend/loader.mjs +198 -0
- package/dist/core/index.d.mts +37 -0
- package/dist/core/index.mjs +29 -0
- package/dist/core/manifest.d.mts +56 -0
- package/dist/core/manifest.mjs +102 -0
- package/dist/core/pubsub/index.d.mts +109 -0
- package/dist/core/pubsub/index.mjs +148 -0
- package/dist/core/scanning/ast-scanner.d.mts +27 -0
- package/dist/core/scanning/ast-scanner.mjs +116 -0
- package/dist/core/scanning/common.d.mts +25 -0
- package/dist/core/scanning/common.mjs +59 -0
- package/dist/core/scanning/directives.d.mts +13 -0
- package/dist/core/scanning/directives.mjs +29 -0
- package/dist/core/scanning/documents.d.mts +20 -0
- package/dist/core/scanning/documents.mjs +37 -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 +14 -0
- package/dist/core/scanning/resolvers.mjs +59 -0
- package/dist/core/scanning/schemas.d.mts +13 -0
- package/dist/core/scanning/schemas.mjs +52 -0
- package/dist/core/schema/builder.d.mts +59 -0
- package/dist/core/schema/builder.mjs +78 -0
- package/dist/core/schema/federation.d.mts +33 -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/server/index.d.mts +4 -0
- package/dist/core/server/index.mjs +4 -0
- package/dist/core/server/sandbox.d.mts +18 -0
- package/dist/core/server/sandbox.mjs +39 -0
- package/dist/core/server/types.d.mts +54 -0
- package/dist/core/server/yoga.d.mts +42 -0
- package/dist/core/server/yoga.mjs +89 -0
- package/dist/core/types/adapter.d.mts +57 -0
- package/dist/core/types/codegen.d.mts +136 -0
- package/dist/core/types/codegen.mjs +1 -0
- package/dist/core/types/config.d.mts +188 -0
- package/dist/core/types/config.mjs +1 -0
- package/dist/{utils/define.d.ts → core/types/define.d.mts} +2 -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 +64 -0
- package/dist/core/types/scanning.mjs +1 -0
- package/dist/{utils/directive-parser.d.ts → core/utils/directive-parser.d.mts} +18 -4
- package/dist/{utils/directive-parser.js → core/utils/directive-parser.mjs} +28 -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 +18 -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/utils/runtime.d.mts +74 -0
- package/dist/core/utils/runtime.mjs +111 -0
- package/dist/core/utils/subscribe-templates.d.mts +8 -0
- package/dist/core/utils/subscribe-templates.mjs +59 -0
- package/dist/core/validation/external-services.d.mts +11 -0
- package/dist/core/validation/external-services.mjs +33 -0
- package/dist/core/validation/index.d.mts +2 -0
- package/dist/core/validation/index.mjs +3 -0
- package/dist/core/watcher/index.d.mts +107 -0
- package/dist/core/watcher/index.mjs +141 -0
- package/dist/define.d.mts +294 -0
- package/dist/define.mjs +325 -0
- package/dist/index.d.mts +6 -0
- package/dist/index.mjs +6 -0
- package/dist/nitro/adapter.d.mts +29 -0
- package/dist/nitro/adapter.mjs +93 -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 +18 -0
- package/dist/nitro/codegen.mjs +173 -0
- package/dist/nitro/config.d.mts +50 -0
- package/dist/nitro/config.mjs +57 -0
- package/dist/nitro/index.d.mts +45 -0
- package/dist/nitro/index.mjs +65 -0
- package/dist/{utils/path-resolver.d.ts → nitro/paths.d.mts} +8 -25
- package/dist/{utils/path-resolver.js → nitro/paths.mjs} +14 -49
- package/dist/nitro/rollup.d.mts +6 -0
- package/dist/nitro/rollup.mjs +53 -0
- package/dist/nitro/routes/apollo-sandbox-script.d.mts +6 -0
- package/dist/nitro/routes/apollo-sandbox-script.mjs +14 -0
- package/dist/nitro/routes/apollo-server-ws.d.mts +15 -0
- package/dist/nitro/routes/apollo-server-ws.mjs +53 -0
- package/dist/nitro/routes/apollo-server.d.mts +6 -0
- package/dist/nitro/routes/apollo-server.mjs +71 -0
- package/dist/{routes/debug.d.ts → nitro/routes/debug.d.mts} +12 -19
- package/dist/nitro/routes/debug.mjs +102 -0
- package/dist/nitro/routes/graphql-yoga-ws.d.mts +12 -0
- package/dist/nitro/routes/graphql-yoga-ws.mjs +53 -0
- package/dist/nitro/routes/graphql-yoga.d.mts +12 -0
- package/dist/nitro/routes/graphql-yoga.mjs +41 -0
- package/dist/nitro/routes/health.d.mts +10 -0
- package/dist/{routes/health.js → nitro/routes/health.mjs} +4 -3
- package/dist/nitro/setup/extend-loader.d.mts +16 -0
- package/dist/nitro/setup/extend-loader.mjs +82 -0
- package/dist/nitro/setup/file-watcher.d.mts +18 -0
- package/dist/nitro/setup/file-watcher.mjs +63 -0
- package/dist/nitro/setup/logging.d.mts +16 -0
- package/dist/nitro/setup/logging.mjs +66 -0
- package/dist/nitro/setup/rollup-integration.d.mts +24 -0
- package/dist/nitro/setup/rollup-integration.mjs +63 -0
- package/dist/nitro/setup/routes.d.mts +13 -0
- package/dist/nitro/setup/routes.mjs +71 -0
- package/dist/nitro/setup/scanner.d.mts +59 -0
- package/dist/nitro/setup/scanner.mjs +120 -0
- package/dist/nitro/setup/ts-config.d.mts +10 -0
- package/dist/nitro/setup/ts-config.mjs +69 -0
- package/dist/nitro/setup.d.mts +11 -0
- package/dist/nitro/setup.mjs +191 -0
- package/dist/nitro/types.d.mts +549 -0
- package/dist/nitro/types.mjs +1 -0
- package/dist/nitro/virtual/generators.d.mts +38 -0
- package/dist/nitro/virtual/generators.mjs +192 -0
- package/dist/nitro/virtual/stubs.d.mts +21 -0
- package/dist/nitro/virtual/stubs.mjs +32 -0
- package/dist/{ecosystem/nuxt.d.ts → nuxt.d.mts} +1 -1
- package/dist/nuxt.mjs +112 -0
- package/dist/{graphql/server.d.ts → stubs/index.d.mts} +5 -1
- package/dist/stubs/index.mjs +1 -0
- package/dist/subscribe/index.d.mts +78 -0
- package/dist/subscribe/index.mjs +206 -0
- package/native/index.d.ts +20 -0
- package/native/index.js +585 -0
- package/package.json +201 -111
- 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 -318
- package/dist/rollup.js +0 -277
- package/dist/routes/apollo-server.d.ts +0 -6
- package/dist/routes/apollo-server.js +0 -89
- package/dist/routes/debug.js +0 -449
- package/dist/routes/graphql-yoga.d.ts +0 -6
- package/dist/routes/graphql-yoga.js +0 -91
- package/dist/routes/health.d.ts +0 -10
- package/dist/types/index.d.ts +0 -246
- 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/file-generator.d.ts +0 -37
- package/dist/utils/file-generator.js +0 -72
- package/dist/utils/index.d.ts +0 -39
- package/dist/utils/index.js +0 -278
- 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 -360
- package/dist/virtual/debug-info.d.ts +0 -9
- package/dist/virtual/debug-info.js +0 -26
- package/dist/virtual/graphql-config.d.ts +0 -9
- package/dist/virtual/graphql-config.js +0 -10
- package/dist/virtual/module-config.d.ts +0 -9
- package/dist/virtual/module-config.js +0 -10
- package/dist/virtual/server-directives.d.ts +0 -11
- package/dist/virtual/server-directives.js +0 -10
- package/dist/virtual/server-resolvers.d.ts +0 -11
- package/dist/virtual/server-resolvers.js +0 -10
- package/dist/virtual/server-schemas.d.ts +0 -11
- package/dist/virtual/server-schemas.js +0 -10
- package/dist/vite.d.ts +0 -25
- package/dist/vite.js +0 -40
- /package/dist/{graphql/index.js → core/server/types.mjs} +0 -0
- /package/dist/{graphql/server.js → core/types/adapter.mjs} +0 -0
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { GLOB_SCAN_PATTERN } from "../constants.mjs";
|
|
2
|
+
import { join, relative } from "pathe";
|
|
3
|
+
import { glob } from "tinyglobby";
|
|
4
|
+
|
|
5
|
+
//#region src/core/scanning/common.ts
|
|
6
|
+
const DEFAULT_IGNORE_PATTERNS = [
|
|
7
|
+
"**/node_modules/**",
|
|
8
|
+
"**/.git/**",
|
|
9
|
+
"**/.output/**",
|
|
10
|
+
"**/.nitro/**",
|
|
11
|
+
"**/.nuxt/**",
|
|
12
|
+
"**/.graphql/**"
|
|
13
|
+
];
|
|
14
|
+
/**
|
|
15
|
+
* Scan a directory for files matching a glob pattern
|
|
16
|
+
*/
|
|
17
|
+
async function scanDirectory(ctx, baseDir, subDir, globPattern = GLOB_SCAN_PATTERN) {
|
|
18
|
+
return (await glob(join(subDir, globPattern), {
|
|
19
|
+
cwd: baseDir,
|
|
20
|
+
dot: true,
|
|
21
|
+
ignore: [...DEFAULT_IGNORE_PATTERNS, ...ctx.ignorePatterns],
|
|
22
|
+
absolute: true
|
|
23
|
+
}).catch((error) => {
|
|
24
|
+
if (error?.code === "ENOTDIR") {
|
|
25
|
+
ctx.logger.warn(`Ignoring \`${join(baseDir, subDir)}\`. It must be a directory.`);
|
|
26
|
+
return [];
|
|
27
|
+
}
|
|
28
|
+
throw error;
|
|
29
|
+
})).map((fullPath) => ({
|
|
30
|
+
fullPath,
|
|
31
|
+
path: relative(join(baseDir, subDir), fullPath)
|
|
32
|
+
})).sort((a, b) => a.path.localeCompare(b.path));
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Deduplicate files by fullPath
|
|
36
|
+
*/
|
|
37
|
+
function deduplicateFiles(files) {
|
|
38
|
+
const seenPaths = /* @__PURE__ */ new Set();
|
|
39
|
+
return files.filter((file) => {
|
|
40
|
+
if (seenPaths.has(file.fullPath)) return false;
|
|
41
|
+
seenPaths.add(file.fullPath);
|
|
42
|
+
return true;
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Filter files by extension
|
|
47
|
+
*/
|
|
48
|
+
function filterByExtension(files, extensions) {
|
|
49
|
+
return files.filter((file) => extensions.some((ext) => file.fullPath.endsWith(ext)));
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Extract file paths from scanned files
|
|
53
|
+
*/
|
|
54
|
+
function extractPaths(files) {
|
|
55
|
+
return files.map((f) => f.fullPath);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
//#endregion
|
|
59
|
+
export { deduplicateFiles, extractPaths, filterByExtension, scanDirectory };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ResolverImport, ScanContext, ScanResult, ScannedResolver } from "../types/scanning.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/core/scanning/directives.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Parse a defineDirective call and return the import info
|
|
6
|
+
*/
|
|
7
|
+
declare function parseDirectiveCall(calleeName: string, exportName: string, filePath: string): ResolverImport | null;
|
|
8
|
+
/**
|
|
9
|
+
* Scan for directive files (.directive.ts/.js)
|
|
10
|
+
*/
|
|
11
|
+
declare function scanDirectivesCore(ctx: ScanContext): Promise<ScanResult<ScannedResolver>>;
|
|
12
|
+
//#endregion
|
|
13
|
+
export { parseDirectiveCall, scanDirectivesCore };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { DIRECTIVE_GLOB_PATTERN } from "../constants.mjs";
|
|
2
|
+
import { scanWithAST } from "./ast-scanner.mjs";
|
|
3
|
+
import { hash } from "ohash";
|
|
4
|
+
|
|
5
|
+
//#region src/core/scanning/directives.ts
|
|
6
|
+
/**
|
|
7
|
+
* Parse a defineDirective call and return the import info
|
|
8
|
+
*/
|
|
9
|
+
function parseDirectiveCall(calleeName, exportName, filePath) {
|
|
10
|
+
if (calleeName !== "defineDirective") return null;
|
|
11
|
+
return {
|
|
12
|
+
name: exportName,
|
|
13
|
+
type: "directive",
|
|
14
|
+
as: `_${hash(exportName + filePath).replace(/-/g, "").slice(0, 6)}`
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Scan for directive files (.directive.ts/.js)
|
|
19
|
+
*/
|
|
20
|
+
function scanDirectivesCore(ctx) {
|
|
21
|
+
return scanWithAST(ctx, {
|
|
22
|
+
pattern: DIRECTIVE_GLOB_PATTERN,
|
|
23
|
+
parseCall: parseDirectiveCall,
|
|
24
|
+
emitWarnings: false
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
//#endregion
|
|
29
|
+
export { parseDirectiveCall, scanDirectivesCore };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { CoreExternalService } from "../types/config.mjs";
|
|
2
|
+
import { ScanContext, ScanResult } from "../types/scanning.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/core/scanning/documents.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Options for scanning documents
|
|
7
|
+
*/
|
|
8
|
+
interface ScanDocumentsOptions {
|
|
9
|
+
/** External services to exclude from main scan */
|
|
10
|
+
externalServices?: CoreExternalService[];
|
|
11
|
+
/** Client directory relative path */
|
|
12
|
+
clientDirRelative?: string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Scan for GraphQL client documents (.graphql, .gql) in client directory
|
|
16
|
+
* Excludes files from external service directories
|
|
17
|
+
*/
|
|
18
|
+
declare function scanDocumentsCore(ctx: ScanContext, options?: ScanDocumentsOptions): Promise<ScanResult<string>>;
|
|
19
|
+
//#endregion
|
|
20
|
+
export { ScanDocumentsOptions, scanDocumentsCore };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { GRAPHQL_GLOB_PATTERN } from "../constants.mjs";
|
|
2
|
+
import { scanDirectory } from "./common.mjs";
|
|
3
|
+
import { relative } from "pathe";
|
|
4
|
+
|
|
5
|
+
//#region src/core/scanning/documents.ts
|
|
6
|
+
/**
|
|
7
|
+
* Scan for GraphQL client documents (.graphql, .gql) in client directory
|
|
8
|
+
* Excludes files from external service directories
|
|
9
|
+
*/
|
|
10
|
+
async function scanDocumentsCore(ctx, options = {}) {
|
|
11
|
+
const warnings = [];
|
|
12
|
+
const errors = [];
|
|
13
|
+
try {
|
|
14
|
+
const clientDirRelative = options.clientDirRelative || relative(ctx.rootDir, ctx.clientDir);
|
|
15
|
+
const allFiles = await scanDirectory(ctx, ctx.rootDir, clientDirRelative, GRAPHQL_GLOB_PATTERN);
|
|
16
|
+
const externalPatterns = (options.externalServices || []).flatMap((service) => service.documents || []);
|
|
17
|
+
return {
|
|
18
|
+
items: allFiles.filter((f) => !f.path.startsWith("external/")).filter((f) => {
|
|
19
|
+
const relativePath = f.path;
|
|
20
|
+
for (const pattern of externalPatterns) if (pattern.replace(new RegExp(`^${clientDirRelative.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}/`), "").split("/")[0] === relativePath.split("/")[0]) return false;
|
|
21
|
+
return true;
|
|
22
|
+
}).map((f) => f.fullPath),
|
|
23
|
+
warnings,
|
|
24
|
+
errors
|
|
25
|
+
};
|
|
26
|
+
} catch (error) {
|
|
27
|
+
errors.push(`Document scanning error: ${error}`);
|
|
28
|
+
return {
|
|
29
|
+
items: [],
|
|
30
|
+
warnings,
|
|
31
|
+
errors
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
//#endregion
|
|
37
|
+
export { scanDocumentsCore };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ASTScanConfig, parseSingleFile, scanWithAST } from "./ast-scanner.mjs";
|
|
2
|
+
import { deduplicateFiles, extractPaths, filterByExtension, scanDirectory } from "./common.mjs";
|
|
3
|
+
import { parseDirectiveCall, scanDirectivesCore } from "./directives.mjs";
|
|
4
|
+
import { ScanDocumentsOptions, scanDocumentsCore } from "./documents.mjs";
|
|
5
|
+
import { parseResolverCall, scanResolversCore } from "./resolvers.mjs";
|
|
6
|
+
import { scanGraphqlCore, scanSchemasCore } from "./schemas.mjs";
|
|
7
|
+
export { type ASTScanConfig, type ScanDocumentsOptions, deduplicateFiles, extractPaths, filterByExtension, parseDirectiveCall, parseResolverCall, parseSingleFile, scanDirectivesCore, scanDirectory, scanDocumentsCore, scanGraphqlCore, scanResolversCore, scanSchemasCore, scanWithAST };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { deduplicateFiles, extractPaths, filterByExtension, scanDirectory } from "./common.mjs";
|
|
2
|
+
import { parseSingleFile, scanWithAST } from "./ast-scanner.mjs";
|
|
3
|
+
import { parseDirectiveCall, scanDirectivesCore } from "./directives.mjs";
|
|
4
|
+
import { scanDocumentsCore } from "./documents.mjs";
|
|
5
|
+
import { parseResolverCall, scanResolversCore } from "./resolvers.mjs";
|
|
6
|
+
import { scanGraphqlCore, scanSchemasCore } from "./schemas.mjs";
|
|
7
|
+
|
|
8
|
+
export { deduplicateFiles, extractPaths, filterByExtension, parseDirectiveCall, parseResolverCall, parseSingleFile, scanDirectivesCore, scanDirectory, scanDocumentsCore, scanGraphqlCore, scanResolversCore, scanSchemasCore, scanWithAST };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ResolverImport, ScanContext, ScanResult, ScannedResolver } from "../types/scanning.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/core/scanning/resolvers.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Parse a define* function call and return the import info
|
|
6
|
+
* Exported for use by manifest loader
|
|
7
|
+
*/
|
|
8
|
+
declare function parseResolverCall(calleeName: string, exportName: string, filePath: string): ResolverImport | null;
|
|
9
|
+
/**
|
|
10
|
+
* Scan for resolver files and parse their exports
|
|
11
|
+
*/
|
|
12
|
+
declare function scanResolversCore(ctx: ScanContext): Promise<ScanResult<ScannedResolver>>;
|
|
13
|
+
//#endregion
|
|
14
|
+
export { parseResolverCall, scanResolversCore };
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { DEFINE_FUNCTIONS, RESOLVER_GLOB_PATTERN } from "../constants.mjs";
|
|
2
|
+
import { scanWithAST } from "./ast-scanner.mjs";
|
|
3
|
+
import { hash } from "ohash";
|
|
4
|
+
|
|
5
|
+
//#region src/core/scanning/resolvers.ts
|
|
6
|
+
/**
|
|
7
|
+
* Parse a define* function call and return the import info
|
|
8
|
+
* Exported for use by manifest loader
|
|
9
|
+
*/
|
|
10
|
+
function parseResolverCall(calleeName, exportName, filePath) {
|
|
11
|
+
const aliasHash = `_${hash(exportName + filePath).replace(/-/g, "").slice(0, 6)}`;
|
|
12
|
+
switch (calleeName) {
|
|
13
|
+
case "defineResolver": return {
|
|
14
|
+
name: exportName,
|
|
15
|
+
type: "resolver",
|
|
16
|
+
as: aliasHash
|
|
17
|
+
};
|
|
18
|
+
case "defineQuery": return {
|
|
19
|
+
name: exportName,
|
|
20
|
+
type: "query",
|
|
21
|
+
as: aliasHash
|
|
22
|
+
};
|
|
23
|
+
case "defineMutation": return {
|
|
24
|
+
name: exportName,
|
|
25
|
+
type: "mutation",
|
|
26
|
+
as: aliasHash
|
|
27
|
+
};
|
|
28
|
+
case "defineField": return {
|
|
29
|
+
name: exportName,
|
|
30
|
+
type: "type",
|
|
31
|
+
as: aliasHash
|
|
32
|
+
};
|
|
33
|
+
case "defineSubscription": return {
|
|
34
|
+
name: exportName,
|
|
35
|
+
type: "subscription",
|
|
36
|
+
as: aliasHash
|
|
37
|
+
};
|
|
38
|
+
case "defineDirective": return {
|
|
39
|
+
name: exportName,
|
|
40
|
+
type: "directive",
|
|
41
|
+
as: aliasHash
|
|
42
|
+
};
|
|
43
|
+
default: return null;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Scan for resolver files and parse their exports
|
|
48
|
+
*/
|
|
49
|
+
function scanResolversCore(ctx) {
|
|
50
|
+
return scanWithAST(ctx, {
|
|
51
|
+
pattern: RESOLVER_GLOB_PATTERN,
|
|
52
|
+
parseCall: parseResolverCall,
|
|
53
|
+
emitWarnings: true,
|
|
54
|
+
validFunctions: DEFINE_FUNCTIONS
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
//#endregion
|
|
59
|
+
export { parseResolverCall, scanResolversCore };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ScanContext, ScanResult } from "../types/scanning.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/core/scanning/schemas.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Scan for GraphQL schema files (.graphql, .gql) in server directory
|
|
6
|
+
*/
|
|
7
|
+
declare function scanSchemasCore(ctx: ScanContext): Promise<ScanResult<string>>;
|
|
8
|
+
/**
|
|
9
|
+
* Scan for GraphQL files (.graphql, .gql) in server directory
|
|
10
|
+
*/
|
|
11
|
+
declare function scanGraphqlCore(ctx: ScanContext): Promise<ScanResult<string>>;
|
|
12
|
+
//#endregion
|
|
13
|
+
export { scanGraphqlCore, scanSchemasCore };
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { GRAPHQL_GLOB_PATTERN } from "../constants.mjs";
|
|
2
|
+
import { extractPaths, scanDirectory } from "./common.mjs";
|
|
3
|
+
import { relative } from "pathe";
|
|
4
|
+
|
|
5
|
+
//#region src/core/scanning/schemas.ts
|
|
6
|
+
/**
|
|
7
|
+
* Scan for GraphQL schema files (.graphql, .gql) in server directory
|
|
8
|
+
*/
|
|
9
|
+
async function scanSchemasCore(ctx) {
|
|
10
|
+
const warnings = [];
|
|
11
|
+
const errors = [];
|
|
12
|
+
try {
|
|
13
|
+
const serverDirRelative = relative(ctx.rootDir, ctx.serverDir);
|
|
14
|
+
return {
|
|
15
|
+
items: extractPaths(await scanDirectory(ctx, ctx.rootDir, serverDirRelative, GRAPHQL_GLOB_PATTERN)),
|
|
16
|
+
warnings,
|
|
17
|
+
errors
|
|
18
|
+
};
|
|
19
|
+
} catch (error) {
|
|
20
|
+
errors.push(`Schema scanning error: ${error}`);
|
|
21
|
+
return {
|
|
22
|
+
items: [],
|
|
23
|
+
warnings,
|
|
24
|
+
errors
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Scan for GraphQL files (.graphql, .gql) in server directory
|
|
30
|
+
*/
|
|
31
|
+
async function scanGraphqlCore(ctx) {
|
|
32
|
+
const warnings = [];
|
|
33
|
+
const errors = [];
|
|
34
|
+
try {
|
|
35
|
+
const serverDirRelative = relative(ctx.rootDir, ctx.serverDir);
|
|
36
|
+
return {
|
|
37
|
+
items: extractPaths(await scanDirectory(ctx, ctx.rootDir, serverDirRelative, "**/*.{graphql,gql}")),
|
|
38
|
+
warnings,
|
|
39
|
+
errors
|
|
40
|
+
};
|
|
41
|
+
} catch (error) {
|
|
42
|
+
errors.push(`GraphQL scanning error: ${error}`);
|
|
43
|
+
return {
|
|
44
|
+
items: [],
|
|
45
|
+
warnings,
|
|
46
|
+
errors
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
//#endregion
|
|
52
|
+
export { scanGraphqlCore, scanSchemasCore };
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { DirectiveDefinition } from "../types/define.mjs";
|
|
2
|
+
import { GraphQLSchema, parse, subscribe, validate } from "graphql";
|
|
3
|
+
|
|
4
|
+
//#region src/core/schema/builder.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Schema definition from virtual module
|
|
7
|
+
*/
|
|
8
|
+
interface SchemaDefinition {
|
|
9
|
+
def: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Resolver definition from virtual module
|
|
13
|
+
*/
|
|
14
|
+
interface ResolverDefinition {
|
|
15
|
+
resolver: Record<string, unknown>;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Directive wrapper from virtual module
|
|
19
|
+
*/
|
|
20
|
+
interface DirectiveWrapper {
|
|
21
|
+
directive: DirectiveDefinition;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Module configuration for federation
|
|
25
|
+
*/
|
|
26
|
+
interface ModuleConfig {
|
|
27
|
+
federation?: {
|
|
28
|
+
enabled?: boolean;
|
|
29
|
+
serviceName?: string;
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Options for creating a merged schema
|
|
34
|
+
*/
|
|
35
|
+
interface CreateMergedSchemaOptions {
|
|
36
|
+
schemas: SchemaDefinition[];
|
|
37
|
+
resolvers: ResolverDefinition[];
|
|
38
|
+
directives?: DirectiveWrapper[];
|
|
39
|
+
moduleConfig: ModuleConfig;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Create a merged GraphQL schema from schemas, resolvers, and directives
|
|
43
|
+
* Supports Apollo Federation when enabled
|
|
44
|
+
*/
|
|
45
|
+
declare function createMergedSchema(options: CreateMergedSchemaOptions): Promise<GraphQLSchema>;
|
|
46
|
+
/**
|
|
47
|
+
* Base schema with empty Query and Mutation types.
|
|
48
|
+
* Required for 'extend type Query' syntax to work.
|
|
49
|
+
* Shared between CLI and Nitro.
|
|
50
|
+
*/
|
|
51
|
+
declare const BASE_SCHEMA = "type Query { _empty: String }\ntype Mutation { _empty: String }";
|
|
52
|
+
/**
|
|
53
|
+
* Build a GraphQL schema from file paths (CLI usage)
|
|
54
|
+
* Reads schema files, merges them, and builds an executable schema
|
|
55
|
+
* Includes BASE_SCHEMA for extend type support
|
|
56
|
+
*/
|
|
57
|
+
declare function buildGraphQLSchema(schemaPaths: string[]): Promise<GraphQLSchema | null>;
|
|
58
|
+
//#endregion
|
|
59
|
+
export { BASE_SCHEMA, CreateMergedSchemaOptions, DirectiveWrapper, ModuleConfig, ResolverDefinition, SchemaDefinition, buildGraphQLSchema, createMergedSchema, parse, subscribe, validate };
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { loadFederationSupport, warnFederationUnavailable } from "./federation.mjs";
|
|
2
|
+
import { consola as consola$1 } from "consola";
|
|
3
|
+
import { buildSchema, parse, parse as parse$1, print, subscribe, validate } from "graphql";
|
|
4
|
+
import { readFileSync } from "node:fs";
|
|
5
|
+
import { mergeResolvers, mergeTypeDefs } from "@graphql-tools/merge";
|
|
6
|
+
import { makeExecutableSchema } from "@graphql-tools/schema";
|
|
7
|
+
|
|
8
|
+
//#region src/core/schema/builder.ts
|
|
9
|
+
/**
|
|
10
|
+
* Create a merged GraphQL schema from schemas, resolvers, and directives
|
|
11
|
+
* Supports Apollo Federation when enabled
|
|
12
|
+
*/
|
|
13
|
+
async function createMergedSchema(options) {
|
|
14
|
+
const { schemas, resolvers, directives, moduleConfig } = options;
|
|
15
|
+
try {
|
|
16
|
+
const typeDefs = mergeTypeDefs([schemas.map((schema) => schema.def).join("\n\n")], {
|
|
17
|
+
throwOnConflict: true,
|
|
18
|
+
commentDescriptions: true,
|
|
19
|
+
sort: true
|
|
20
|
+
});
|
|
21
|
+
const mergedResolvers = mergeResolvers(resolvers.map((r) => r.resolver));
|
|
22
|
+
const federationEnabled = moduleConfig.federation?.enabled;
|
|
23
|
+
let schema;
|
|
24
|
+
if (federationEnabled) {
|
|
25
|
+
const buildSubgraph = await loadFederationSupport();
|
|
26
|
+
if (buildSubgraph) schema = buildSubgraph({
|
|
27
|
+
typeDefs: typeof typeDefs === "string" ? parse$1(typeDefs) : typeDefs,
|
|
28
|
+
resolvers: mergedResolvers
|
|
29
|
+
});
|
|
30
|
+
else {
|
|
31
|
+
warnFederationUnavailable();
|
|
32
|
+
schema = makeExecutableSchema({
|
|
33
|
+
typeDefs,
|
|
34
|
+
resolvers: mergedResolvers
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
} else schema = makeExecutableSchema({
|
|
38
|
+
typeDefs,
|
|
39
|
+
resolvers: mergedResolvers
|
|
40
|
+
});
|
|
41
|
+
if (directives && directives.length > 0) {
|
|
42
|
+
for (const { directive } of directives) if (directive.transformer) schema = directive.transformer(schema);
|
|
43
|
+
}
|
|
44
|
+
return schema;
|
|
45
|
+
} catch (error) {
|
|
46
|
+
consola$1.error("Schema merge error:", error);
|
|
47
|
+
throw error;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Base schema with empty Query and Mutation types.
|
|
52
|
+
* Required for 'extend type Query' syntax to work.
|
|
53
|
+
* Shared between CLI and Nitro.
|
|
54
|
+
*/
|
|
55
|
+
const BASE_SCHEMA = `type Query { _empty: String }
|
|
56
|
+
type Mutation { _empty: String }`;
|
|
57
|
+
/**
|
|
58
|
+
* Build a GraphQL schema from file paths (CLI usage)
|
|
59
|
+
* Reads schema files, merges them, and builds an executable schema
|
|
60
|
+
* Includes BASE_SCHEMA for extend type support
|
|
61
|
+
*/
|
|
62
|
+
async function buildGraphQLSchema(schemaPaths) {
|
|
63
|
+
if (schemaPaths.length === 0) return null;
|
|
64
|
+
try {
|
|
65
|
+
const mergedTypeDefs = mergeTypeDefs([BASE_SCHEMA, ...schemaPaths.map((path) => readFileSync(path, "utf-8"))], {
|
|
66
|
+
throwOnConflict: true,
|
|
67
|
+
commentDescriptions: true,
|
|
68
|
+
sort: true
|
|
69
|
+
});
|
|
70
|
+
return buildSchema(typeof mergedTypeDefs === "string" ? mergedTypeDefs : print(mergedTypeDefs));
|
|
71
|
+
} catch (error) {
|
|
72
|
+
consola$1.error("Failed to build GraphQL schema:", error);
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
//#endregion
|
|
78
|
+
export { BASE_SCHEMA, buildGraphQLSchema, createMergedSchema, parse, subscribe, validate };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { DocumentNode, GraphQLSchema } from "graphql";
|
|
2
|
+
|
|
3
|
+
//#region src/core/schema/federation.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Module type for buildSubgraphSchema
|
|
6
|
+
*/
|
|
7
|
+
interface SubgraphModule {
|
|
8
|
+
typeDefs: DocumentNode;
|
|
9
|
+
resolvers?: Record<string, unknown>;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Type for buildSubgraphSchema function from @apollo/subgraph
|
|
13
|
+
* Accepts either an array of modules or a single options object
|
|
14
|
+
*/
|
|
15
|
+
type BuildSubgraphSchemaFn = (modulesOrOptions: SubgraphModule[] | SubgraphModule) => GraphQLSchema;
|
|
16
|
+
/**
|
|
17
|
+
* Dynamically load @apollo/subgraph for federation support.
|
|
18
|
+
* Returns the buildSubgraphSchema function if available, or false if the package is not installed.
|
|
19
|
+
* Result is cached for subsequent calls.
|
|
20
|
+
*/
|
|
21
|
+
declare function loadFederationSupport(): Promise<BuildSubgraphSchemaFn | false>;
|
|
22
|
+
/**
|
|
23
|
+
* Log a warning when federation is enabled but @apollo/subgraph is not available.
|
|
24
|
+
* Uses consola logger instead of console.warn for consistent logging.
|
|
25
|
+
*/
|
|
26
|
+
declare function warnFederationUnavailable(): void;
|
|
27
|
+
/**
|
|
28
|
+
* Reset the federation support cache.
|
|
29
|
+
* Useful for testing or when the module needs to be reloaded.
|
|
30
|
+
*/
|
|
31
|
+
declare function resetFederationCache(): void;
|
|
32
|
+
//#endregion
|
|
33
|
+
export { loadFederationSupport, resetFederationCache, warnFederationUnavailable };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { LOG_TAG } from "../constants.mjs";
|
|
2
|
+
import { consola as consola$1 } from "consola";
|
|
3
|
+
|
|
4
|
+
//#region src/core/schema/federation.ts
|
|
5
|
+
const logger = consola$1.withTag(LOG_TAG);
|
|
6
|
+
/**
|
|
7
|
+
* Cached result: function if available, false if not available, null if not checked yet
|
|
8
|
+
*/
|
|
9
|
+
let buildSubgraphSchemaCache = null;
|
|
10
|
+
/**
|
|
11
|
+
* Dynamically load @apollo/subgraph for federation support.
|
|
12
|
+
* Returns the buildSubgraphSchema function if available, or false if the package is not installed.
|
|
13
|
+
* Result is cached for subsequent calls.
|
|
14
|
+
*/
|
|
15
|
+
async function loadFederationSupport() {
|
|
16
|
+
if (buildSubgraphSchemaCache !== null) return buildSubgraphSchemaCache;
|
|
17
|
+
try {
|
|
18
|
+
buildSubgraphSchemaCache = (await import("@apollo/subgraph")).buildSubgraphSchema;
|
|
19
|
+
} catch {
|
|
20
|
+
buildSubgraphSchemaCache = false;
|
|
21
|
+
}
|
|
22
|
+
return buildSubgraphSchemaCache;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Log a warning when federation is enabled but @apollo/subgraph is not available.
|
|
26
|
+
* Uses consola logger instead of console.warn for consistent logging.
|
|
27
|
+
*/
|
|
28
|
+
function warnFederationUnavailable() {
|
|
29
|
+
logger.warn("Federation enabled but @apollo/subgraph not available, falling back to regular schema");
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Reset the federation support cache.
|
|
33
|
+
* Useful for testing or when the module needs to be reloaded.
|
|
34
|
+
*/
|
|
35
|
+
function resetFederationCache() {
|
|
36
|
+
buildSubgraphSchemaCache = null;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
//#endregion
|
|
40
|
+
export { loadFederationSupport, resetFederationCache, warnFederationUnavailable };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { BASE_SCHEMA, CreateMergedSchemaOptions, DirectiveWrapper, ModuleConfig, ResolverDefinition, SchemaDefinition, buildGraphQLSchema, createMergedSchema, parse, subscribe, validate } from "./builder.mjs";
|
|
2
|
+
import { loadFederationSupport, resetFederationCache, warnFederationUnavailable } from "./federation.mjs";
|
|
3
|
+
export { BASE_SCHEMA, CreateMergedSchemaOptions, DirectiveWrapper, ModuleConfig, ResolverDefinition, SchemaDefinition, buildGraphQLSchema, createMergedSchema, loadFederationSupport, parse, resetFederationCache, subscribe, validate, warnFederationUnavailable };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { loadFederationSupport, resetFederationCache, warnFederationUnavailable } from "./federation.mjs";
|
|
2
|
+
import { BASE_SCHEMA, buildGraphQLSchema, createMergedSchema, parse, subscribe, validate } from "./builder.mjs";
|
|
3
|
+
|
|
4
|
+
export { BASE_SCHEMA, buildGraphQLSchema, createMergedSchema, loadFederationSupport, parse, resetFederationCache, subscribe, validate, warnFederationUnavailable };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { CoreServerInstance, CoreServerOptions, ServerFactory } from "./types.mjs";
|
|
2
|
+
import { APOLLO_SANDBOX_CDN, createSandboxResponse, fetchSandboxScript } from "./sandbox.mjs";
|
|
3
|
+
import { BASE_SCHEMA, apolloSandboxHtml, createYogaServer } from "./yoga.mjs";
|
|
4
|
+
export { APOLLO_SANDBOX_CDN, type CoreServerInstance, type CoreServerOptions, type ServerFactory, BASE_SCHEMA as YOGA_BASE_SCHEMA, apolloSandboxHtml, createSandboxResponse, createYogaServer, fetchSandboxScript };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { APOLLO_SANDBOX_CDN, createSandboxResponse, fetchSandboxScript } from "./sandbox.mjs";
|
|
2
|
+
import { BASE_SCHEMA, apolloSandboxHtml, createYogaServer } from "./yoga.mjs";
|
|
3
|
+
|
|
4
|
+
export { APOLLO_SANDBOX_CDN, BASE_SCHEMA as YOGA_BASE_SCHEMA, apolloSandboxHtml, createSandboxResponse, createYogaServer, fetchSandboxScript };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
//#region src/core/server/sandbox.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Core Sandbox Script Handler
|
|
4
|
+
*
|
|
5
|
+
* Proxies Apollo Sandbox script from CDN with caching.
|
|
6
|
+
* Used by both CLI and Nitro.
|
|
7
|
+
*/
|
|
8
|
+
declare const APOLLO_SANDBOX_CDN = "https://embeddable-sandbox.cdn.apollographql.com/_latest/embeddable-sandbox.umd.production.min.js";
|
|
9
|
+
/**
|
|
10
|
+
* Fetch and cache the Apollo Sandbox script
|
|
11
|
+
*/
|
|
12
|
+
declare function fetchSandboxScript(): Promise<string>;
|
|
13
|
+
/**
|
|
14
|
+
* Create a Response with the sandbox script
|
|
15
|
+
*/
|
|
16
|
+
declare function createSandboxResponse(): Promise<Response>;
|
|
17
|
+
//#endregion
|
|
18
|
+
export { APOLLO_SANDBOX_CDN, createSandboxResponse, fetchSandboxScript };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
//#region src/core/server/sandbox.ts
|
|
2
|
+
/**
|
|
3
|
+
* Core Sandbox Script Handler
|
|
4
|
+
*
|
|
5
|
+
* Proxies Apollo Sandbox script from CDN with caching.
|
|
6
|
+
* Used by both CLI and Nitro.
|
|
7
|
+
*/
|
|
8
|
+
const APOLLO_SANDBOX_CDN = "https://embeddable-sandbox.cdn.apollographql.com/_latest/embeddable-sandbox.umd.production.min.js";
|
|
9
|
+
let cachedScript = null;
|
|
10
|
+
/**
|
|
11
|
+
* Fetch and cache the Apollo Sandbox script
|
|
12
|
+
*/
|
|
13
|
+
async function fetchSandboxScript() {
|
|
14
|
+
if (cachedScript) return cachedScript;
|
|
15
|
+
const response = await fetch(APOLLO_SANDBOX_CDN);
|
|
16
|
+
if (!response.ok) throw new Error(`Failed to fetch Apollo Sandbox script: ${response.status}`);
|
|
17
|
+
cachedScript = await response.text();
|
|
18
|
+
return cachedScript;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Create a Response with the sandbox script
|
|
22
|
+
*/
|
|
23
|
+
async function createSandboxResponse() {
|
|
24
|
+
try {
|
|
25
|
+
const script = await fetchSandboxScript();
|
|
26
|
+
return new Response(script, { headers: {
|
|
27
|
+
"content-type": "text/javascript; charset=utf-8",
|
|
28
|
+
"cache-control": "public, max-age=2592000, immutable"
|
|
29
|
+
} });
|
|
30
|
+
} catch (error) {
|
|
31
|
+
return new Response(`// Error loading Apollo Sandbox: ${error}`, {
|
|
32
|
+
status: 500,
|
|
33
|
+
headers: { "content-type": "text/javascript; charset=utf-8" }
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
//#endregion
|
|
39
|
+
export { APOLLO_SANDBOX_CDN, createSandboxResponse, fetchSandboxScript };
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { DirectiveWrapper, ModuleConfig, ResolverDefinition, SchemaDefinition } from "../schema/builder.mjs";
|
|
2
|
+
import { GraphQLSchema } from "graphql";
|
|
3
|
+
|
|
4
|
+
//#region src/core/server/types.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Security configuration for GraphQL server
|
|
7
|
+
*/
|
|
8
|
+
interface CoreSecurityConfig {
|
|
9
|
+
/** Enable GraphQL introspection (default: true in dev, false in prod) */
|
|
10
|
+
introspection?: boolean;
|
|
11
|
+
/** Enable GraphQL playground/sandbox (default: true in dev, false in prod) */
|
|
12
|
+
playground?: boolean;
|
|
13
|
+
/** Mask error messages in responses (default: false in dev, true in prod) */
|
|
14
|
+
maskErrors?: boolean;
|
|
15
|
+
/** Disable field suggestions in error messages */
|
|
16
|
+
disableSuggestions?: boolean;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Options for creating a GraphQL server instance
|
|
20
|
+
*/
|
|
21
|
+
interface CoreServerOptions {
|
|
22
|
+
/** Schema definitions (GraphQL SDL strings) */
|
|
23
|
+
schemas: SchemaDefinition[];
|
|
24
|
+
/** Resolver definitions */
|
|
25
|
+
resolvers: ResolverDefinition[];
|
|
26
|
+
/** Directive definitions (optional) */
|
|
27
|
+
directives?: DirectiveWrapper[];
|
|
28
|
+
/** Module configuration (federation, etc.) */
|
|
29
|
+
moduleConfig: ModuleConfig;
|
|
30
|
+
/** GraphQL endpoint path (default: /api/graphql) */
|
|
31
|
+
endpoint?: string;
|
|
32
|
+
/** Security configuration */
|
|
33
|
+
security?: CoreSecurityConfig;
|
|
34
|
+
/** User's imported GraphQL config (from defineGraphQLConfig) */
|
|
35
|
+
importedConfig?: Record<string, unknown>;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* GraphQL server instance returned by server factories
|
|
39
|
+
*/
|
|
40
|
+
interface CoreServerInstance {
|
|
41
|
+
/**
|
|
42
|
+
* Handle a request using the web standard fetch API
|
|
43
|
+
* Compatible with srvx, Bun, Deno, and Node.js
|
|
44
|
+
*/
|
|
45
|
+
fetch: (request: Request, context?: Record<string, unknown>) => Promise<Response>;
|
|
46
|
+
/** The compiled GraphQL schema */
|
|
47
|
+
schema: GraphQLSchema;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Factory function type for creating GraphQL servers
|
|
51
|
+
*/
|
|
52
|
+
type ServerFactory = (options: CoreServerOptions) => Promise<CoreServerInstance>;
|
|
53
|
+
//#endregion
|
|
54
|
+
export { CoreSecurityConfig, CoreServerInstance, CoreServerOptions, ServerFactory };
|