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,9 @@
|
|
|
1
|
+
import { CLIContext } from "../index.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/cli/server/debug-handler.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Create a debug handler for the CLI dev server
|
|
6
|
+
*/
|
|
7
|
+
declare function createDebugHandler(ctx: CLIContext): (request: Request) => Promise<Response>;
|
|
8
|
+
//#endregion
|
|
9
|
+
export { createDebugHandler };
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { scanDirectivesCore } from "../../core/scanning/directives.mjs";
|
|
2
|
+
import { scanDocumentsCore } from "../../core/scanning/documents.mjs";
|
|
3
|
+
import { scanResolversCore } from "../../core/scanning/resolvers.mjs";
|
|
4
|
+
import { scanSchemasCore } from "../../core/scanning/schemas.mjs";
|
|
5
|
+
import { CLIAdapter } from "../adapter.mjs";
|
|
6
|
+
import { generateDebugHtml } from "../../core/debug/template.mjs";
|
|
7
|
+
|
|
8
|
+
//#region src/cli/server/debug-handler.ts
|
|
9
|
+
/**
|
|
10
|
+
* Create a debug handler for the CLI dev server
|
|
11
|
+
*/
|
|
12
|
+
function createDebugHandler(ctx) {
|
|
13
|
+
return async (request) => {
|
|
14
|
+
const debugInfo = await collectDebugInfo(ctx);
|
|
15
|
+
if (new URL(request.url).searchParams.get("format") === "json") return Response.json(debugInfo);
|
|
16
|
+
return new Response(generateDebugHtml(debugInfo), { headers: { "Content-Type": "text/html" } });
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Collect debug information from CLI context
|
|
21
|
+
*/
|
|
22
|
+
async function collectDebugInfo(ctx) {
|
|
23
|
+
const scanCtx = CLIAdapter.createScanContext(ctx);
|
|
24
|
+
const [schemasResult, resolversResult, directivesResult, documentsResult] = await Promise.all([
|
|
25
|
+
scanSchemasCore(scanCtx),
|
|
26
|
+
scanResolversCore(scanCtx),
|
|
27
|
+
scanDirectivesCore(scanCtx),
|
|
28
|
+
scanDocumentsCore(scanCtx, { externalServices: ctx.config.externalServices })
|
|
29
|
+
]);
|
|
30
|
+
const resolverFiles = resolversResult.items.map((r) => {
|
|
31
|
+
const parts = r.specifier.split("/");
|
|
32
|
+
return {
|
|
33
|
+
file: parts[parts.length - 1] || r.specifier,
|
|
34
|
+
exports: r.imports.map((i) => ({
|
|
35
|
+
name: i.name,
|
|
36
|
+
type: i.type
|
|
37
|
+
}))
|
|
38
|
+
};
|
|
39
|
+
});
|
|
40
|
+
const schemaFiles = schemasResult.items.map((s) => {
|
|
41
|
+
return s.split("/").slice(-3).join("/");
|
|
42
|
+
});
|
|
43
|
+
const documentFiles = documentsResult.items.map((d) => {
|
|
44
|
+
return d.split("/").slice(-3).join("/");
|
|
45
|
+
});
|
|
46
|
+
return {
|
|
47
|
+
environment: {
|
|
48
|
+
dev: true,
|
|
49
|
+
framework: "cli"
|
|
50
|
+
},
|
|
51
|
+
graphql: { framework: ctx.config.framework || "graphql-yoga" },
|
|
52
|
+
scanned: {
|
|
53
|
+
schemas: schemasResult.items.length,
|
|
54
|
+
resolvers: resolversResult.items.length,
|
|
55
|
+
directives: directivesResult.items.length,
|
|
56
|
+
documents: documentsResult.items.length,
|
|
57
|
+
schemaFiles,
|
|
58
|
+
resolverFiles,
|
|
59
|
+
documentFiles
|
|
60
|
+
},
|
|
61
|
+
runtime: {
|
|
62
|
+
loadedResolvers: resolversResult.items.length,
|
|
63
|
+
loadedSchemas: schemasResult.items.length,
|
|
64
|
+
loadedDirectives: directivesResult.items.length
|
|
65
|
+
},
|
|
66
|
+
virtualModules: { "cli-config": JSON.stringify(ctx.config, null, 2) }
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
//#endregion
|
|
71
|
+
export { createDebugHandler };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { CLIContext } from "../index.mjs";
|
|
2
|
+
import { serve } from "srvx";
|
|
3
|
+
|
|
4
|
+
//#region src/cli/server/dev-server.d.ts
|
|
5
|
+
interface DevServerOptions {
|
|
6
|
+
/** Server port (default: 4000) */
|
|
7
|
+
port?: number;
|
|
8
|
+
/** Server hostname (default: localhost) */
|
|
9
|
+
hostname?: string;
|
|
10
|
+
/** Open browser after start */
|
|
11
|
+
open?: boolean;
|
|
12
|
+
}
|
|
13
|
+
interface DevServerInstance {
|
|
14
|
+
/** The srvx server instance */
|
|
15
|
+
server: ReturnType<typeof serve>;
|
|
16
|
+
/** Reload the GraphQL schema (for hot reload) */
|
|
17
|
+
reload: () => Promise<void>;
|
|
18
|
+
/** Stop the server */
|
|
19
|
+
close: () => Promise<void>;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Start the CLI development server
|
|
23
|
+
*
|
|
24
|
+
* Uses srvx for runtime-agnostic HTTP server.
|
|
25
|
+
* GraphQL handled by the same core factory that Nitro uses.
|
|
26
|
+
*/
|
|
27
|
+
declare function startDevServer(ctx: CLIContext, options?: DevServerOptions): Promise<DevServerInstance>;
|
|
28
|
+
//#endregion
|
|
29
|
+
export { DevServerInstance, DevServerOptions, startDevServer };
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { createDebugHandler } from "./debug-handler.mjs";
|
|
2
|
+
import { createGraphQLHandler, getServerInstance, reloadGraphQLHandler } from "./graphql-handler.mjs";
|
|
3
|
+
import { createHealthHandler } from "./health-handler.mjs";
|
|
4
|
+
import { createSandboxHandler } from "./sandbox-handler.mjs";
|
|
5
|
+
import { createWebSocketPlugin } from "./ws-handler.mjs";
|
|
6
|
+
import consola from "consola";
|
|
7
|
+
import { plugin } from "crossws/server";
|
|
8
|
+
import { serve } from "srvx";
|
|
9
|
+
|
|
10
|
+
//#region src/cli/server/dev-server.ts
|
|
11
|
+
const logger = consola.withTag("nitro-graphql");
|
|
12
|
+
/**
|
|
13
|
+
* Start the CLI development server
|
|
14
|
+
*
|
|
15
|
+
* Uses srvx for runtime-agnostic HTTP server.
|
|
16
|
+
* GraphQL handled by the same core factory that Nitro uses.
|
|
17
|
+
*/
|
|
18
|
+
async function startDevServer(ctx, options = {}) {
|
|
19
|
+
const port = options.port || 4e3;
|
|
20
|
+
const hostname = options.hostname || "localhost";
|
|
21
|
+
const endpoint = ctx.config.endpoint?.graphql || "/graphql";
|
|
22
|
+
logger.info("Starting GraphQL dev server...");
|
|
23
|
+
let graphqlHandler = await createGraphQLHandler(ctx);
|
|
24
|
+
const healthHandler = createHealthHandler();
|
|
25
|
+
const sandboxHandler = createSandboxHandler();
|
|
26
|
+
const debugHandler = createDebugHandler(ctx);
|
|
27
|
+
const server = serve({
|
|
28
|
+
port,
|
|
29
|
+
hostname,
|
|
30
|
+
plugins: [plugin(createWebSocketPlugin(() => {
|
|
31
|
+
const instance = getServerInstance();
|
|
32
|
+
if (!instance) throw new Error("GraphQL server not initialized");
|
|
33
|
+
return instance.schema;
|
|
34
|
+
}))],
|
|
35
|
+
async fetch(request) {
|
|
36
|
+
const path = new URL(request.url).pathname;
|
|
37
|
+
if (path === endpoint || path === "/api/graphql") return graphqlHandler(request);
|
|
38
|
+
if (path === "/api/graphql/sandbox.js" || path === `${endpoint}/sandbox.js`) return sandboxHandler(request);
|
|
39
|
+
if (path === "/health" || path === "/api/graphql/health") return healthHandler(request);
|
|
40
|
+
if (path === "/_nitro/graphql/debug") return debugHandler(request);
|
|
41
|
+
return new Response("Not Found", { status: 404 });
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
await server.ready();
|
|
45
|
+
logger.success(`GraphQL server running at http://${hostname}:${port}${endpoint}`);
|
|
46
|
+
logger.info(`Health check at http://${hostname}:${port}/health`);
|
|
47
|
+
logger.info(`Debug dashboard at http://${hostname}:${port}/_nitro/graphql/debug`);
|
|
48
|
+
return {
|
|
49
|
+
server,
|
|
50
|
+
async reload() {
|
|
51
|
+
logger.info("Reloading GraphQL schema...");
|
|
52
|
+
graphqlHandler = await reloadGraphQLHandler(ctx);
|
|
53
|
+
logger.success("Schema reloaded!");
|
|
54
|
+
},
|
|
55
|
+
async close() {
|
|
56
|
+
logger.info("Shutting down server...");
|
|
57
|
+
await server.close();
|
|
58
|
+
logger.success("Server stopped");
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
//#endregion
|
|
64
|
+
export { startDevServer };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { CLIContext } from "../index.mjs";
|
|
2
|
+
import { CoreServerInstance } from "../../core/server/types.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/cli/server/graphql-handler.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Create the GraphQL request handler
|
|
7
|
+
*
|
|
8
|
+
* Uses the same createYogaServer() from core that Nitro uses,
|
|
9
|
+
* ensuring 100% consistent behavior between CLI and Nitro module.
|
|
10
|
+
*/
|
|
11
|
+
declare function createGraphQLHandler(ctx: CLIContext): Promise<(request: Request) => Promise<Response>>;
|
|
12
|
+
/**
|
|
13
|
+
* Reload the GraphQL handler (for hot reload)
|
|
14
|
+
*/
|
|
15
|
+
declare function reloadGraphQLHandler(ctx: CLIContext): Promise<(request: Request) => Promise<Response>>;
|
|
16
|
+
/**
|
|
17
|
+
* Get the current server instance (for WebSocket setup, etc.)
|
|
18
|
+
*/
|
|
19
|
+
declare function getServerInstance(): CoreServerInstance | null;
|
|
20
|
+
//#endregion
|
|
21
|
+
export { createGraphQLHandler, getServerInstance, reloadGraphQLHandler };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { BASE_SCHEMA, createYogaServer } from "../../core/server/yoga.mjs";
|
|
2
|
+
import { loadDirectiveDefinitions, loadResolverDefinitions, loadSchemaDefinitions } from "./loader.mjs";
|
|
3
|
+
import consola from "consola";
|
|
4
|
+
|
|
5
|
+
//#region src/cli/server/graphql-handler.ts
|
|
6
|
+
const logger = consola.withTag("nitro-graphql");
|
|
7
|
+
let serverInstance = null;
|
|
8
|
+
/**
|
|
9
|
+
* Create the GraphQL request handler
|
|
10
|
+
*
|
|
11
|
+
* Uses the same createYogaServer() from core that Nitro uses,
|
|
12
|
+
* ensuring 100% consistent behavior between CLI and Nitro module.
|
|
13
|
+
*/
|
|
14
|
+
async function createGraphQLHandler(ctx) {
|
|
15
|
+
const loadedSchemas = await loadSchemaDefinitions(ctx);
|
|
16
|
+
const resolvers = await loadResolverDefinitions(ctx);
|
|
17
|
+
const directives = await loadDirectiveDefinitions(ctx);
|
|
18
|
+
const schemas = [BASE_SCHEMA, ...loadedSchemas];
|
|
19
|
+
serverInstance = await createYogaServer({
|
|
20
|
+
schemas,
|
|
21
|
+
resolvers,
|
|
22
|
+
directives,
|
|
23
|
+
moduleConfig: { federation: ctx.config.federation },
|
|
24
|
+
endpoint: ctx.config.endpoint?.graphql || "/graphql",
|
|
25
|
+
security: ctx.config.security
|
|
26
|
+
});
|
|
27
|
+
logger.success(`GraphQL server created with ${schemas.length} schema(s) and ${resolvers.length} resolver(s)`);
|
|
28
|
+
return (request) => serverInstance.fetch(request);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Reload the GraphQL handler (for hot reload)
|
|
32
|
+
*/
|
|
33
|
+
async function reloadGraphQLHandler(ctx) {
|
|
34
|
+
serverInstance = null;
|
|
35
|
+
return createGraphQLHandler(ctx);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Get the current server instance (for WebSocket setup, etc.)
|
|
39
|
+
*/
|
|
40
|
+
function getServerInstance() {
|
|
41
|
+
return serverInstance;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
//#endregion
|
|
45
|
+
export { createGraphQLHandler, getServerInstance, reloadGraphQLHandler };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
//#region src/cli/server/health-handler.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* CLI Health Handler
|
|
4
|
+
*
|
|
5
|
+
* Simple health check endpoint for the CLI dev server.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Create a health check handler
|
|
9
|
+
*/
|
|
10
|
+
declare function createHealthHandler(): (request: Request) => Response;
|
|
11
|
+
//#endregion
|
|
12
|
+
export { createHealthHandler };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
//#region src/cli/server/health-handler.ts
|
|
2
|
+
/**
|
|
3
|
+
* CLI Health Handler
|
|
4
|
+
*
|
|
5
|
+
* Simple health check endpoint for the CLI dev server.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Create a health check handler
|
|
9
|
+
*/
|
|
10
|
+
function createHealthHandler() {
|
|
11
|
+
return (_request) => {
|
|
12
|
+
return Response.json({
|
|
13
|
+
status: "ok",
|
|
14
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
15
|
+
runtime: detectRuntime()
|
|
16
|
+
});
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Detect the current JavaScript runtime
|
|
21
|
+
*/
|
|
22
|
+
function detectRuntime() {
|
|
23
|
+
if (typeof Bun !== "undefined") return "bun";
|
|
24
|
+
if (typeof Deno !== "undefined") return "deno";
|
|
25
|
+
if (typeof process !== "undefined" && process.versions?.node) return `node/${process.versions.node}`;
|
|
26
|
+
return "unknown";
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
//#endregion
|
|
30
|
+
export { createHealthHandler };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { CLIContext } from "../index.mjs";
|
|
2
|
+
import { DirectiveWrapper, ResolverDefinition, SchemaDefinition } from "../../core/schema/builder.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/cli/server/loader.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Clear extend cache (for hot reload)
|
|
7
|
+
*/
|
|
8
|
+
declare function clearExtendCache(): void;
|
|
9
|
+
/**
|
|
10
|
+
* Load schema definitions from GraphQL files
|
|
11
|
+
* Includes schemas from extend sources
|
|
12
|
+
*/
|
|
13
|
+
declare function loadSchemaDefinitions(ctx: CLIContext): Promise<SchemaDefinition[]>;
|
|
14
|
+
/**
|
|
15
|
+
* Load resolver definitions by dynamically importing resolver modules
|
|
16
|
+
* Includes resolvers from extend sources
|
|
17
|
+
*/
|
|
18
|
+
declare function loadResolverDefinitions(ctx: CLIContext): Promise<ResolverDefinition[]>;
|
|
19
|
+
/**
|
|
20
|
+
* Load directive definitions by dynamically importing directive modules
|
|
21
|
+
* Includes directives from extend sources
|
|
22
|
+
*/
|
|
23
|
+
declare function loadDirectiveDefinitions(ctx: CLIContext): Promise<DirectiveWrapper[]>;
|
|
24
|
+
/**
|
|
25
|
+
* Load all GraphQL components (schemas, resolvers, directives)
|
|
26
|
+
*/
|
|
27
|
+
declare function loadAllComponents(ctx: CLIContext): Promise<{
|
|
28
|
+
schemas: SchemaDefinition[];
|
|
29
|
+
resolvers: ResolverDefinition[];
|
|
30
|
+
directives: DirectiveWrapper[];
|
|
31
|
+
}>;
|
|
32
|
+
//#endregion
|
|
33
|
+
export { clearExtendCache, loadAllComponents, loadDirectiveDefinitions, loadResolverDefinitions, loadSchemaDefinitions };
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { scanDirectivesCore } from "../../core/scanning/directives.mjs";
|
|
2
|
+
import { scanResolversCore } from "../../core/scanning/resolvers.mjs";
|
|
3
|
+
import { scanSchemasCore } from "../../core/scanning/schemas.mjs";
|
|
4
|
+
import { pathToFileURL, readFileSync_ } from "../../core/utils/runtime.mjs";
|
|
5
|
+
import { scanAllExtendSources } from "../../core/extend/loader.mjs";
|
|
6
|
+
import { CLIAdapter } from "../adapter.mjs";
|
|
7
|
+
import consola from "consola";
|
|
8
|
+
|
|
9
|
+
//#region src/cli/server/loader.ts
|
|
10
|
+
const logger = consola.withTag("nitro-graphql");
|
|
11
|
+
let cachedExtendResult = null;
|
|
12
|
+
/**
|
|
13
|
+
* Get extend scan result (cached)
|
|
14
|
+
*/
|
|
15
|
+
async function getExtendResult(ctx) {
|
|
16
|
+
if (!cachedExtendResult) cachedExtendResult = await scanAllExtendSources(ctx.config.extend, ctx.config.rootDir);
|
|
17
|
+
return cachedExtendResult;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Clear extend cache (for hot reload)
|
|
21
|
+
*/
|
|
22
|
+
function clearExtendCache() {
|
|
23
|
+
cachedExtendResult = null;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Load schema definitions from GraphQL files
|
|
27
|
+
* Includes schemas from extend sources
|
|
28
|
+
*/
|
|
29
|
+
async function loadSchemaDefinitions(ctx) {
|
|
30
|
+
const result = await scanSchemasCore(CLIAdapter.createScanContext(ctx));
|
|
31
|
+
const extendResult = await getExtendResult(ctx);
|
|
32
|
+
const allSchemas = [...result.items, ...extendResult.schemas];
|
|
33
|
+
if (allSchemas.length === 0) {
|
|
34
|
+
logger.warn("No GraphQL schema files found");
|
|
35
|
+
return [];
|
|
36
|
+
}
|
|
37
|
+
logger.debug(`Found ${allSchemas.length} schema file(s)`);
|
|
38
|
+
return allSchemas.map((schemaPath) => ({ def: readFileSync_(schemaPath) }));
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Load resolver from a scanned item
|
|
42
|
+
*/
|
|
43
|
+
async function loadResolverFromItem(item) {
|
|
44
|
+
const filePath = item.specifier;
|
|
45
|
+
if (!filePath) {
|
|
46
|
+
logger.warn("Resolver item has no specifier, skipping");
|
|
47
|
+
return [];
|
|
48
|
+
}
|
|
49
|
+
const resolvers = [];
|
|
50
|
+
try {
|
|
51
|
+
const module = await import(`${pathToFileURL(filePath).href}?t=${Date.now()}`);
|
|
52
|
+
for (const imp of item.imports) {
|
|
53
|
+
const exported = module[imp.name];
|
|
54
|
+
if (exported && typeof exported === "object") {
|
|
55
|
+
resolvers.push({ resolver: exported });
|
|
56
|
+
logger.debug(`Loaded resolver: ${imp.name} from ${filePath}`);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
} catch (error) {
|
|
60
|
+
logger.error(`Failed to load resolver from ${filePath}:`, error);
|
|
61
|
+
}
|
|
62
|
+
return resolvers;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Load resolver definitions by dynamically importing resolver modules
|
|
66
|
+
* Includes resolvers from extend sources
|
|
67
|
+
*/
|
|
68
|
+
async function loadResolverDefinitions(ctx) {
|
|
69
|
+
const result = await scanResolversCore(CLIAdapter.createScanContext(ctx));
|
|
70
|
+
const extendResult = await getExtendResult(ctx);
|
|
71
|
+
const allItems = [...result.items, ...extendResult.resolvers];
|
|
72
|
+
if (allItems.length === 0) {
|
|
73
|
+
logger.warn("No resolver files found");
|
|
74
|
+
return [];
|
|
75
|
+
}
|
|
76
|
+
logger.debug(`Found ${allItems.length} resolver file(s)`);
|
|
77
|
+
const resolvers = [];
|
|
78
|
+
for (const item of allItems) {
|
|
79
|
+
const loaded = await loadResolverFromItem(item);
|
|
80
|
+
resolvers.push(...loaded);
|
|
81
|
+
}
|
|
82
|
+
return resolvers;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Load directive from a scanned item
|
|
86
|
+
*/
|
|
87
|
+
async function loadDirectiveFromItem(item) {
|
|
88
|
+
const filePath = item.specifier;
|
|
89
|
+
if (!filePath) {
|
|
90
|
+
logger.warn("Directive item has no specifier, skipping");
|
|
91
|
+
return [];
|
|
92
|
+
}
|
|
93
|
+
const directives = [];
|
|
94
|
+
try {
|
|
95
|
+
const module = await import(`${pathToFileURL(filePath).href}?t=${Date.now()}`);
|
|
96
|
+
for (const imp of item.imports) {
|
|
97
|
+
const exported = module[imp.name];
|
|
98
|
+
if (exported && typeof exported === "object") {
|
|
99
|
+
directives.push({ directive: exported });
|
|
100
|
+
logger.debug(`Loaded directive: ${imp.name} from ${filePath}`);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
} catch (error) {
|
|
104
|
+
logger.error(`Failed to load directive from ${filePath}:`, error);
|
|
105
|
+
}
|
|
106
|
+
return directives;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Load directive definitions by dynamically importing directive modules
|
|
110
|
+
* Includes directives from extend sources
|
|
111
|
+
*/
|
|
112
|
+
async function loadDirectiveDefinitions(ctx) {
|
|
113
|
+
const result = await scanDirectivesCore(CLIAdapter.createScanContext(ctx));
|
|
114
|
+
const extendResult = await getExtendResult(ctx);
|
|
115
|
+
const allItems = [...result.items, ...extendResult.directives];
|
|
116
|
+
if (allItems.length === 0) {
|
|
117
|
+
logger.debug("No directive files found");
|
|
118
|
+
return [];
|
|
119
|
+
}
|
|
120
|
+
logger.debug(`Found ${allItems.length} directive file(s)`);
|
|
121
|
+
const directives = [];
|
|
122
|
+
for (const item of allItems) {
|
|
123
|
+
const loaded = await loadDirectiveFromItem(item);
|
|
124
|
+
directives.push(...loaded);
|
|
125
|
+
}
|
|
126
|
+
return directives;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Load all GraphQL components (schemas, resolvers, directives)
|
|
130
|
+
*/
|
|
131
|
+
async function loadAllComponents(ctx) {
|
|
132
|
+
clearExtendCache();
|
|
133
|
+
const [schemas, resolvers, directives] = await Promise.all([
|
|
134
|
+
loadSchemaDefinitions(ctx),
|
|
135
|
+
loadResolverDefinitions(ctx),
|
|
136
|
+
loadDirectiveDefinitions(ctx)
|
|
137
|
+
]);
|
|
138
|
+
return {
|
|
139
|
+
schemas,
|
|
140
|
+
resolvers,
|
|
141
|
+
directives
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
//#endregion
|
|
146
|
+
export { clearExtendCache, loadAllComponents, loadDirectiveDefinitions, loadResolverDefinitions, loadSchemaDefinitions };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
//#region src/cli/server/sandbox-handler.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* CLI Sandbox Script Handler
|
|
4
|
+
*
|
|
5
|
+
* Uses core sandbox handler.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Create a handler that serves the Apollo Sandbox script
|
|
9
|
+
*/
|
|
10
|
+
declare function createSandboxHandler(): (request: Request) => Promise<Response>;
|
|
11
|
+
//#endregion
|
|
12
|
+
export { createSandboxHandler };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { createSandboxResponse } from "../../core/server/sandbox.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/cli/server/sandbox-handler.ts
|
|
4
|
+
/**
|
|
5
|
+
* CLI Sandbox Script Handler
|
|
6
|
+
*
|
|
7
|
+
* Uses core sandbox handler.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Create a handler that serves the Apollo Sandbox script
|
|
11
|
+
*/
|
|
12
|
+
function createSandboxHandler() {
|
|
13
|
+
return async (_request) => {
|
|
14
|
+
return createSandboxResponse();
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
//#endregion
|
|
19
|
+
export { createSandboxHandler };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { CLIContext } from "../index.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/cli/server/watcher.d.ts
|
|
4
|
+
interface WatcherInstance {
|
|
5
|
+
/** Close the watcher */
|
|
6
|
+
close: () => Promise<void>;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Create a file watcher for the dev server
|
|
10
|
+
*
|
|
11
|
+
* Uses core watcher module with CLI-specific callbacks.
|
|
12
|
+
* Watches for changes in:
|
|
13
|
+
* - GraphQL schema files (*.graphql)
|
|
14
|
+
* - Resolver files (*.resolver.ts)
|
|
15
|
+
* - Directive files (*.directive.ts)
|
|
16
|
+
* - Client documents (*.graphql in client dir)
|
|
17
|
+
*/
|
|
18
|
+
declare function createDevWatcher(ctx: CLIContext, onReload: () => Promise<void>): WatcherInstance;
|
|
19
|
+
//#endregion
|
|
20
|
+
export { WatcherInstance, createDevWatcher };
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { LOG_TAG } from "../../core/constants.mjs";
|
|
2
|
+
import { closeWatcher, createCoreWatcher } from "../../core/watcher/index.mjs";
|
|
3
|
+
import { generateAll } from "../commands/generate.mjs";
|
|
4
|
+
import consola from "consola";
|
|
5
|
+
|
|
6
|
+
//#region src/cli/server/watcher.ts
|
|
7
|
+
const logger = consola.withTag(LOG_TAG);
|
|
8
|
+
/**
|
|
9
|
+
* Create a file watcher for the dev server
|
|
10
|
+
*
|
|
11
|
+
* Uses core watcher module with CLI-specific callbacks.
|
|
12
|
+
* Watches for changes in:
|
|
13
|
+
* - GraphQL schema files (*.graphql)
|
|
14
|
+
* - Resolver files (*.resolver.ts)
|
|
15
|
+
* - Directive files (*.directive.ts)
|
|
16
|
+
* - Client documents (*.graphql in client dir)
|
|
17
|
+
*/
|
|
18
|
+
function createDevWatcher(ctx, onReload) {
|
|
19
|
+
const serverDir = ctx.config.serverDir;
|
|
20
|
+
const clientDir = ctx.config.clientDir;
|
|
21
|
+
const watchDirs = [serverDir];
|
|
22
|
+
if (clientDir !== serverDir) watchDirs.push(clientDir);
|
|
23
|
+
logger.info("Watching for changes in:", watchDirs.join(", "));
|
|
24
|
+
const watcher = createCoreWatcher({
|
|
25
|
+
watchDirs,
|
|
26
|
+
serverDir,
|
|
27
|
+
debounceMs: 150
|
|
28
|
+
}, {
|
|
29
|
+
onServerChange: async () => {
|
|
30
|
+
logger.info("Server files changed, regenerating...");
|
|
31
|
+
try {
|
|
32
|
+
await generateAll(ctx, {
|
|
33
|
+
silent: true,
|
|
34
|
+
runtime: false
|
|
35
|
+
});
|
|
36
|
+
await onReload();
|
|
37
|
+
} catch (error) {
|
|
38
|
+
logger.error("Hot reload failed:", error);
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
onClientChange: async () => {
|
|
42
|
+
logger.info("Client files changed, regenerating...");
|
|
43
|
+
try {
|
|
44
|
+
await generateAll(ctx, {
|
|
45
|
+
silent: true,
|
|
46
|
+
runtime: false
|
|
47
|
+
});
|
|
48
|
+
} catch (error) {
|
|
49
|
+
logger.error("Client type generation failed:", error);
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
onReady: () => {
|
|
53
|
+
logger.success("File watcher ready");
|
|
54
|
+
},
|
|
55
|
+
onError: (error) => {
|
|
56
|
+
logger.error("Watcher error:", error);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
return { async close() {
|
|
60
|
+
await closeWatcher(watcher);
|
|
61
|
+
logger.debug("File watcher closed");
|
|
62
|
+
} };
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
//#endregion
|
|
66
|
+
export { createDevWatcher };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { GraphQLSchema } from "graphql";
|
|
2
|
+
import { Hooks } from "crossws";
|
|
3
|
+
|
|
4
|
+
//#region src/cli/server/ws-handler.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Create WebSocket hooks for GraphQL subscriptions
|
|
7
|
+
*
|
|
8
|
+
* @param getSchema - Function to get the GraphQL schema
|
|
9
|
+
* @param context - Optional context to pass to resolvers
|
|
10
|
+
*/
|
|
11
|
+
declare function createGraphQLWebSocketHooks(getSchema: () => Promise<GraphQLSchema> | GraphQLSchema, context?: Record<string, unknown>): Partial<Hooks>;
|
|
12
|
+
/**
|
|
13
|
+
* Create crossws plugin configuration for srvx
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* import { plugin as ws } from 'crossws/server'
|
|
18
|
+
* import { createWebSocketPlugin } from './ws-handler'
|
|
19
|
+
*
|
|
20
|
+
* const server = serve({
|
|
21
|
+
* plugins: [ws(createWebSocketPlugin(getSchema))],
|
|
22
|
+
* fetch(req) { ... }
|
|
23
|
+
* })
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
declare function createWebSocketPlugin(getSchema: () => Promise<GraphQLSchema> | GraphQLSchema, context?: Record<string, unknown>): Partial<Hooks>;
|
|
27
|
+
//#endregion
|
|
28
|
+
export { createGraphQLWebSocketHooks, createWebSocketPlugin };
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { handleProtocols } from "graphql-ws";
|
|
2
|
+
import { makeHooks } from "graphql-ws/use/crossws";
|
|
3
|
+
|
|
4
|
+
//#region src/cli/server/ws-handler.ts
|
|
5
|
+
/**
|
|
6
|
+
* Create WebSocket hooks for GraphQL subscriptions
|
|
7
|
+
*
|
|
8
|
+
* @param getSchema - Function to get the GraphQL schema
|
|
9
|
+
* @param context - Optional context to pass to resolvers
|
|
10
|
+
*/
|
|
11
|
+
function createGraphQLWebSocketHooks(getSchema, context) {
|
|
12
|
+
return {
|
|
13
|
+
upgrade(request) {
|
|
14
|
+
const selected = handleProtocols(request.headers.get("sec-websocket-protocol") || "");
|
|
15
|
+
if (selected) return { headers: { "Sec-WebSocket-Protocol": selected } };
|
|
16
|
+
return {};
|
|
17
|
+
},
|
|
18
|
+
...makeHooks({
|
|
19
|
+
schema: getSchema,
|
|
20
|
+
context: async (ctx) => {
|
|
21
|
+
const baseContext = { connectionParams: ctx.connectionParams };
|
|
22
|
+
if (context) return {
|
|
23
|
+
...baseContext,
|
|
24
|
+
...context
|
|
25
|
+
};
|
|
26
|
+
return baseContext;
|
|
27
|
+
}
|
|
28
|
+
})
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Create crossws plugin configuration for srvx
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```typescript
|
|
36
|
+
* import { plugin as ws } from 'crossws/server'
|
|
37
|
+
* import { createWebSocketPlugin } from './ws-handler'
|
|
38
|
+
*
|
|
39
|
+
* const server = serve({
|
|
40
|
+
* plugins: [ws(createWebSocketPlugin(getSchema))],
|
|
41
|
+
* fetch(req) { ... }
|
|
42
|
+
* })
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
function createWebSocketPlugin(getSchema, context) {
|
|
46
|
+
return createGraphQLWebSocketHooks(getSchema, context);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
//#endregion
|
|
50
|
+
export { createGraphQLWebSocketHooks, createWebSocketPlugin };
|
package/dist/config.mjs
ADDED