@powerhousedao/reactor-api 6.2.3-dev.64 → 6.2.3-dev.65
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/dist/{adapter-gateway-apollo-DwAmdCYz.mjs → adapter-gateway-apollo-D-EdZ4e-.mjs} +10 -12
- package/dist/adapter-gateway-apollo-D-EdZ4e-.mjs.map +1 -0
- package/dist/{adapter-gateway-mercurius-BhO0nwH_.mjs → adapter-gateway-mercurius-CdxLge5p.mjs} +3 -11
- package/dist/adapter-gateway-mercurius-CdxLge5p.mjs.map +1 -0
- package/dist/{base-document-models-69WRTSfH.mjs → base-document-models-uUQKgXcf.mjs} +176 -4
- package/dist/base-document-models-uUQKgXcf.mjs.map +1 -0
- package/dist/{create-schema-DLTPkNpK.d.mts → create-schema-BUk-IQCT.d.mts} +16 -10
- package/dist/create-schema-BUk-IQCT.d.mts.map +1 -0
- package/dist/index.d.mts +15 -14
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +832 -361
- package/dist/index.mjs.map +1 -1
- package/dist/package-subgraph-check-CsTPajAN.mjs +137 -0
- package/dist/package-subgraph-check-CsTPajAN.mjs.map +1 -0
- package/dist/{pglite-node-Ow9i5Rb4.mjs → pglite-node-C-UQXrjU.mjs} +8 -5
- package/dist/{pglite-node-Ow9i5Rb4.mjs.map → pglite-node-C-UQXrjU.mjs.map} +1 -1
- package/dist/src/graphql/subgraph-types.d.mts +17 -11
- package/dist/src/graphql/subgraph-types.d.mts.map +1 -1
- package/dist/src/graphql/subgraph-types.mjs +8 -99
- package/dist/src/graphql/subgraph-types.mjs.map +1 -1
- package/dist/src/packages/vite-loader.d.mts +1 -1
- package/dist/src/packages/vite-loader.d.mts.map +1 -1
- package/dist/src/packages/vite-loader.mjs +34 -44
- package/dist/src/packages/vite-loader.mjs.map +1 -1
- package/dist/src/pglite/pglite-node.d.mts.map +1 -1
- package/dist/src/pglite/pglite-node.mjs +3 -3
- package/dist/{subgraph-extraction-CcgWd0De.mjs → subgraph-extraction-cSpPp3Hq.mjs} +5 -4
- package/dist/{subgraph-extraction-CcgWd0De.mjs.map → subgraph-extraction-cSpPp3Hq.mjs.map} +1 -1
- package/dist/subgraph-schema-owner-BEjuk2Xv.mjs +10 -0
- package/dist/subgraph-schema-owner-BEjuk2Xv.mjs.map +1 -0
- package/dist/{types-D3pD6fvQ.d.mts → types-CCI5IDgT.d.mts} +4 -5
- package/dist/{types-D3pD6fvQ.d.mts.map → types-CCI5IDgT.d.mts.map} +1 -1
- package/package.json +13 -13
- package/dist/adapter-gateway-apollo-DTcAJpfN.mjs +0 -4
- package/dist/adapter-gateway-apollo-DwAmdCYz.mjs.map +0 -1
- package/dist/adapter-gateway-mercurius-BhO0nwH_.mjs.map +0 -1
- package/dist/adapter-gateway-stitching-969ZPot-.mjs +0 -4
- package/dist/adapter-gateway-stitching-ClVkjojb.mjs +0 -333
- package/dist/adapter-gateway-stitching-ClVkjojb.mjs.map +0 -1
- package/dist/base-document-models-69WRTSfH.mjs.map +0 -1
- package/dist/create-schema-DLTPkNpK.d.mts.map +0 -1
- package/dist/websocket-_SH5aBcy.mjs +0 -18
- package/dist/websocket-_SH5aBcy.mjs.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
|
|
2
|
-
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="
|
|
3
|
-
import { t as
|
|
2
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="003e98f1-d3bf-5110-8cd0-ad52856c302b")}catch(e){}}();
|
|
3
|
+
import { t as __exportAll } from "./rolldown-runtime-8H4AJuhK.mjs";
|
|
4
4
|
import { buildSubgraphSchema } from "@apollo/subgraph";
|
|
5
5
|
import { ApolloServer, HeaderMap } from "@apollo/server";
|
|
6
6
|
import { ApolloServerPluginInlineTraceDisabled } from "@apollo/server/plugin/disabled";
|
|
@@ -8,6 +8,11 @@ import { ApolloServerPluginLandingPageLocalDefault } from "@apollo/server/plugin
|
|
|
8
8
|
import { ApolloGateway, LocalCompose, RemoteGraphQLDataSource } from "@apollo/gateway";
|
|
9
9
|
import { ApolloServerPluginDrainHttpServer } from "@apollo/server/plugin/drainHttpServer";
|
|
10
10
|
//#region src/graphql/gateway/adapter-gateway-apollo.ts
|
|
11
|
+
var adapter_gateway_apollo_exports = /* @__PURE__ */ __exportAll({
|
|
12
|
+
ApolloGatewayAdapter: () => ApolloGatewayAdapter,
|
|
13
|
+
createApolloFetchHandler: () => createApolloFetchHandler,
|
|
14
|
+
filterComposableSubgraphs: () => filterComposableSubgraphs
|
|
15
|
+
});
|
|
11
16
|
/**
|
|
12
17
|
* Drop subgraphs whose typeDefs cannot be built into a valid subgraph schema in
|
|
13
18
|
* isolation — e.g. a duplicate type definition within a single subgraph (Sentry
|
|
@@ -101,13 +106,6 @@ var ApolloGatewayAdapter = class {
|
|
|
101
106
|
})), this.#logger);
|
|
102
107
|
return new LocalCompose({ localServiceList: composableServiceList }).initialize(this.#gatewayOptions);
|
|
103
108
|
}
|
|
104
|
-
attachWebSocket(wsServer, schema, handlers) {
|
|
105
|
-
return useServer({
|
|
106
|
-
schema,
|
|
107
|
-
onConnect: (ctx) => handlers.onConnect(ctx.connectionParams ?? {}, ctx.extra),
|
|
108
|
-
context: (ctx) => handlers.context(ctx.connectionParams ?? {}, ctx.extra)
|
|
109
|
-
}, wsServer);
|
|
110
|
-
}
|
|
111
109
|
async stop() {
|
|
112
110
|
await Promise.all(this.#servers.map((s) => s.stop()));
|
|
113
111
|
this.#servers.length = 0;
|
|
@@ -157,7 +155,7 @@ function createApolloFetchHandler(server, contextFactory) {
|
|
|
157
155
|
};
|
|
158
156
|
}
|
|
159
157
|
//#endregion
|
|
160
|
-
export { createApolloFetchHandler as n,
|
|
158
|
+
export { createApolloFetchHandler as n, adapter_gateway_apollo_exports as t };
|
|
161
159
|
|
|
162
|
-
//# sourceMappingURL=adapter-gateway-apollo-
|
|
163
|
-
//# debugId=
|
|
160
|
+
//# sourceMappingURL=adapter-gateway-apollo-D-EdZ4e-.mjs.map
|
|
161
|
+
//# debugId=003e98f1-d3bf-5110-8cd0-ad52856c302b
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter-gateway-apollo-D-EdZ4e-.mjs","sources":["../src/graphql/gateway/adapter-gateway-apollo.ts"],"sourcesContent":["import type {\n GetDataSourceFunction,\n GraphQLDataSourceProcessOptions,\n ServiceDefinition,\n SubgraphHealthCheckFunction,\n SupergraphSdlUpdateFunction,\n} from \"@apollo/gateway\";\nimport {\n ApolloGateway,\n LocalCompose,\n RemoteGraphQLDataSource,\n} from \"@apollo/gateway\";\nimport { ApolloServer, HeaderMap } from \"@apollo/server\";\nimport { ApolloServerPluginInlineTraceDisabled } from \"@apollo/server/plugin/disabled\";\nimport { ApolloServerPluginDrainHttpServer } from \"@apollo/server/plugin/drainHttpServer\";\nimport { ApolloServerPluginLandingPageLocalDefault } from \"@apollo/server/plugin/landingPage/default\";\nimport { buildSubgraphSchema } from \"@apollo/subgraph\";\nimport type { ILogger } from \"document-model\";\nimport type { GraphQLSchema } from \"graphql\";\nimport type http from \"node:http\";\nimport type { Context } from \"../types.js\";\nimport type {\n FetchHandler,\n GatewayContextFactory,\n IGatewayAdapter,\n SubgraphDefinition,\n} from \"./types.js\";\n\n/**\n * Drop subgraphs whose typeDefs cannot be built into a valid subgraph schema in\n * isolation — e.g. a duplicate type definition within a single subgraph (Sentry\n * #917) — so one broken subgraph is excluded instead of failing the build for\n * everyone. Each excluded subgraph is logged; the rest are composed.\n *\n * Scope: this only catches per-subgraph build failures. Errors that surface only\n * when subgraphs are composed together (cross-subgraph type or `@key` conflicts)\n * are still thrown by `LocalCompose.initialize()` and are NOT handled here.\n */\nexport function filterComposableSubgraphs(\n serviceList: ServiceDefinition[],\n logger?: Pick<ILogger, \"error\">,\n): ServiceDefinition[] {\n return serviceList.filter((service) => {\n try {\n // Array form: @apollo/subgraph 2.15 dropped the bare-module overload.\n buildSubgraphSchema([{ typeDefs: service.typeDefs }]);\n return true;\n } catch (error) {\n logger?.error(\n `Excluding subgraph \"${service.name}\" from supergraph composition: ${\n error instanceof Error ? error.message : String(error)\n }`,\n );\n return false;\n }\n });\n}\n\n// Forwards the incoming authorization header to federated subgraph requests.\nclass AuthenticatedDataSource extends RemoteGraphQLDataSource {\n constructor(\n config?: ConstructorParameters<typeof RemoteGraphQLDataSource>[0],\n ) {\n // Node's fetch retires a pooled connection before the subgraph server's advertised keep-alive\n // timeout; Apollo's default make-fetch-happen agent holds it until the server closes it under us.\n super({\n fetcher: fetch as RemoteGraphQLDataSource[\"fetcher\"],\n ...config,\n });\n }\n\n willSendRequest(options: GraphQLDataSourceProcessOptions) {\n const { authorization } = options.context.headers as {\n authorization: string;\n };\n if (authorization && options?.request.http) {\n options.request.http.headers.set(\"authorization\", authorization);\n }\n }\n}\n\nexport class ApolloGatewayAdapter implements IGatewayAdapter<Context> {\n readonly #logger: ILogger;\n readonly #servers: ApolloServer<Context>[] = [];\n\n #supergraphServer: ApolloServer<Context> | null = null;\n #gatewayOptions: {\n update: SupergraphSdlUpdateFunction;\n healthCheck: SubgraphHealthCheckFunction;\n getDataSource: GetDataSourceFunction;\n } | null = null;\n #getSubgraphs: (() => SubgraphDefinition[]) | null = null;\n\n constructor(logger: ILogger) {\n this.#logger = logger;\n }\n\n async start(_httpServer: http.Server): Promise<void> {\n // Per-subgraph Apollo servers start lazily in createHandler.\n // Nothing to do here.\n }\n\n async createHandler(\n schema: GraphQLSchema,\n contextFactory: GatewayContextFactory<Context>,\n ): Promise<FetchHandler> {\n const server = new ApolloServer<Context>({\n schema,\n logger: this.#logger,\n introspection: true,\n // Each ApolloServer otherwise registers its own SIGINT/SIGTERM handler\n // that re-emits the signal via process.kill after server.stop() resolves.\n // With many subgraph servers that re-emit lands while the reactor's\n // graceful-shutdown chain is mid-flight, looking like a \"second SIGINT\"\n // to the reactor and aborting cleanup. The reactor drives our shutdown\n // end-to-end (see ReactorBuilder.attachSignalHandlers), so opt out.\n stopOnTerminationSignals: false,\n plugins: [\n ApolloServerPluginInlineTraceDisabled(),\n ApolloServerPluginLandingPageLocalDefault(),\n ],\n });\n await server.start();\n this.#servers.push(server);\n return createApolloFetchHandler(server, contextFactory);\n }\n\n async createSupergraphHandler(\n getSubgraphs: () => SubgraphDefinition[],\n httpServer: http.Server,\n contextFactory: GatewayContextFactory<Context>,\n ): Promise<FetchHandler> {\n if (this.#supergraphServer) {\n throw new Error(\"Supergraph server is already running\");\n }\n\n this.#getSubgraphs = getSubgraphs;\n\n const gateway = new ApolloGateway({\n supergraphSdl: async (options) => {\n this.#gatewayOptions = options;\n return await this.#buildSupergraphSdl();\n },\n buildService: (serviceConfig) =>\n new AuthenticatedDataSource(serviceConfig),\n });\n\n this.#supergraphServer = new ApolloServer<Context>({\n gateway,\n logger: this.#logger,\n introspection: true,\n stopOnTerminationSignals: false,\n plugins: [\n ApolloServerPluginDrainHttpServer({ httpServer }),\n ApolloServerPluginInlineTraceDisabled(),\n ApolloServerPluginLandingPageLocalDefault(),\n ],\n });\n\n await this.#supergraphServer.start();\n return createApolloFetchHandler(this.#supergraphServer, contextFactory);\n }\n\n async updateSupergraph(): Promise<void> {\n if (!this.#gatewayOptions || !this.#getSubgraphs) {\n // Not yet initialized - no-op.\n return;\n }\n const { supergraphSdl } = await this.#buildSupergraphSdl();\n this.#gatewayOptions.update(supergraphSdl);\n }\n\n async #buildSupergraphSdl() {\n if (!this.#gatewayOptions || !this.#getSubgraphs) {\n throw new Error(\"Gateway is not ready\");\n }\n const serviceList: ServiceDefinition[] = this.#getSubgraphs().map((s) => ({\n name: s.name,\n typeDefs: s.typeDefs,\n url: s.url,\n }));\n const composableServiceList = filterComposableSubgraphs(\n serviceList,\n this.#logger,\n );\n const localCompose = new LocalCompose({\n localServiceList: composableServiceList,\n });\n return localCompose.initialize(this.#gatewayOptions);\n }\n\n async stop(): Promise<void> {\n await Promise.all(this.#servers.map((s) => s.stop()));\n this.#servers.length = 0;\n\n if (this.#supergraphServer) {\n await this.#supergraphServer.stop();\n this.#supergraphServer = null;\n }\n this.#gatewayOptions = null;\n this.#getSubgraphs = null;\n }\n}\n\n/**\n * Wrap an existing ApolloServer as a Fetch API handler.\n * Does not manage server lifecycle; caller is responsible for start/stop.\n */\nexport function createApolloFetchHandler(\n server: ApolloServer<Context>,\n contextFactory: GatewayContextFactory<Context>,\n): FetchHandler {\n return async (request: Request): Promise<Response> => {\n const url = new URL(request.url);\n const headers = new HeaderMap();\n request.headers.forEach((value, key) => headers.set(key, value));\n\n let body: unknown = undefined;\n if (request.method !== \"GET\" && request.method !== \"HEAD\") {\n try {\n body = (await request.json()) as unknown;\n } catch {\n // body may be empty for some requests\n }\n }\n\n const result = await server.executeHTTPGraphQLRequest({\n httpGraphQLRequest: {\n method: request.method.toUpperCase(),\n headers,\n search: url.search,\n body,\n },\n context: () => contextFactory(request),\n });\n\n const responseHeaders = new Headers();\n for (const [key, value] of result.headers) {\n responseHeaders.set(key, value);\n }\n\n let responseBody: string;\n if (result.body.kind === \"complete\") {\n responseBody = result.body.string;\n } else {\n const chunks: string[] = [];\n for await (const chunk of result.body.asyncIterator) {\n chunks.push(chunk);\n }\n responseBody = chunks.join(\"\");\n }\n\n return new Response(responseBody, {\n status: result.status ?? 200,\n headers: responseHeaders,\n });\n };\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAsCA,SAAgB,0BACd,aACA,QACqB;CACrB,OAAO,YAAY,QAAQ,YAAY;EACrC,IAAI;GAEF,oBAAoB,CAAC,EAAE,UAAU,QAAQ,SAAS,CAAC,CAAC;GACpD,OAAO;EACT,SAA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AAO,0BAA0B;GACpD,oBAAoB;IAClB,QAAQ,QAAQ,OAAO,YAAY;IACnC;IACA,QAAQ,IAAI;IACZ;GACF;GACA,eAAe,eAAe,OAAO;EACvC,CAAC;EAED,MAAM,kBAAkB,IAAI,QAAQ;EACpC,KAAK,MAAM,CAAC,KAAK,UAAU,OAAO,SAChC,gBAAgB,IAAI,KAAK,KAAK;EAGhC,IAAI;EACJ,IAAI,OAAO,KAAK,SAAS,YACvB,eAAe,OAAO,KAAK;OACtB;GACL,MAAM,SAAmB,CAAC;GAC1B,WAAW,MAAM,SAAS,OAAO,KAAK,eACpC,OAAO,KAAK,KAAK;GAEnB,eAAe,OAAO,KAAK,EAAE;EAC/B;EAEA,OAAO,IAAI,SAAS,cAAc;GAChC,QAAQ,OAAO,UAAU;GACzB,SAAS;EACX,CAAC;CACH;AACF","debug_id":"003e98f1-d3bf-5110-8cd0-ad52856c302b"}
|
package/dist/{adapter-gateway-mercurius-BhO0nwH_.mjs → adapter-gateway-mercurius-CdxLge5p.mjs}
RENAMED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="
|
|
3
|
-
import { t as useServer } from "./websocket-_SH5aBcy.mjs";
|
|
2
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="5f791eb2-83b0-5fbd-a834-cc764eb2823a")}catch(e){}}();
|
|
4
3
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
5
4
|
import mercuriusGateway from "@mercuriusjs/gateway";
|
|
6
5
|
import Fastify from "fastify";
|
|
@@ -47,13 +46,6 @@ var MercuriusGatewayAdapter = class {
|
|
|
47
46
|
this.#supergraphApp = newApp;
|
|
48
47
|
if (oldApp) await oldApp.close();
|
|
49
48
|
}
|
|
50
|
-
attachWebSocket(wsServer, schema, handlers) {
|
|
51
|
-
return useServer({
|
|
52
|
-
schema,
|
|
53
|
-
onConnect: (ctx) => handlers.onConnect(ctx.connectionParams ?? {}, ctx.extra),
|
|
54
|
-
context: (ctx) => handlers.context(ctx.connectionParams ?? {}, ctx.extra)
|
|
55
|
-
}, wsServer);
|
|
56
|
-
}
|
|
57
49
|
async stop() {
|
|
58
50
|
await Promise.all(this.#subgraphApps.map((app) => app.close()));
|
|
59
51
|
this.#subgraphApps.length = 0;
|
|
@@ -129,5 +121,5 @@ async function injectRequest(app, request) {
|
|
|
129
121
|
//#endregion
|
|
130
122
|
export { MercuriusGatewayAdapter };
|
|
131
123
|
|
|
132
|
-
//# sourceMappingURL=adapter-gateway-mercurius-
|
|
133
|
-
//# debugId=
|
|
124
|
+
//# sourceMappingURL=adapter-gateway-mercurius-CdxLge5p.mjs.map
|
|
125
|
+
//# debugId=5f791eb2-83b0-5fbd-a834-cc764eb2823a
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter-gateway-mercurius-CdxLge5p.mjs","sources":["../src/graphql/gateway/adapter-gateway-mercurius.ts"],"sourcesContent":["import type { MercuriusGatewayOptions } from \"@mercuriusjs/gateway\";\nimport mercuriusGateway from \"@mercuriusjs/gateway\";\nimport Fastify from \"fastify\";\nimport type {\n FastifyInstance,\n FastifyPluginCallback,\n FastifyReply,\n FastifyRequest,\n} from \"fastify\";\nimport mercurius from \"mercurius\";\nimport type { MercuriusOptions } from \"mercurius\";\nimport type { ILogger } from \"document-model\";\nimport type { GraphQLSchema } from \"graphql\";\nimport type http from \"node:http\";\nimport { AsyncLocalStorage } from \"node:async_hooks\";\nimport type { Context } from \"../types.js\";\nimport type {\n FetchHandler,\n GatewayContextFactory,\n IGatewayAdapter,\n SubgraphDefinition,\n} from \"./types.js\";\n\n/**\n * Threads the original Fetch API Request through Mercurius's internal\n * fastify.inject() call so that contextFactory (which uses the auth WeakMap\n * from auth-middleware.ts) receives the same Request object that auth\n * middleware populated before calling the handler.\n */\nconst requestAls = new AsyncLocalStorage<Request>();\n\n// @mercuriusjs/gateway exports a plain `(instance, opts) => void` rather than\n// a typed FastifyPluginCallback — cast once here.\n// The gateway plugin's accepted options are the intersection of the base\n// MercuriusOptions and MercuriusGatewayOptions (mirroring the unexported\n// MercuriusFederationOptions type in the package).\ntype GatewayPluginOptions = MercuriusOptions & MercuriusGatewayOptions;\nconst mercuriusGatewayPlugin =\n mercuriusGateway as unknown as FastifyPluginCallback<GatewayPluginOptions>;\n\nexport class MercuriusGatewayAdapter implements IGatewayAdapter<Context> {\n readonly #logger: ILogger;\n readonly #subgraphApps: FastifyInstance[] = [];\n\n #supergraphApp: FastifyInstance | null = null;\n #getSubgraphs: (() => SubgraphDefinition[]) | null = null;\n #supergraphContextFactory: GatewayContextFactory<Context> | null = null;\n\n constructor(logger: ILogger) {\n this.#logger = logger;\n }\n\n async start(_httpServer: http.Server): Promise<void> {\n // Mercurius instances are started lazily in createHandler /\n // createSupergraphHandler — nothing to do here.\n }\n\n async createHandler(\n schema: GraphQLSchema,\n contextFactory: GatewayContextFactory<Context>,\n ): Promise<FetchHandler> {\n const app = await buildMercuriusApp(schema, contextFactory, this.#logger);\n this.#subgraphApps.push(app);\n return buildFetchHandler(app);\n }\n\n async createSupergraphHandler(\n getSubgraphs: () => SubgraphDefinition[],\n _httpServer: http.Server,\n contextFactory: GatewayContextFactory<Context>,\n ): Promise<FetchHandler> {\n if (this.#supergraphApp) {\n throw new Error(\"Supergraph is already running\");\n }\n this.#getSubgraphs = getSubgraphs;\n this.#supergraphContextFactory = contextFactory;\n this.#supergraphApp = await buildGatewayApp(\n getSubgraphs(),\n contextFactory,\n this.#logger,\n );\n\n // Capture `this` so the returned handler always delegates to the *current*\n // #supergraphApp, allowing updateSupergraph() to swap it atomically.\n // eslint-disable-next-line @typescript-eslint/no-this-alias\n const adapter = this;\n return (request: Request): Promise<Response> => {\n if (!adapter.#supergraphApp) {\n return Promise.resolve(\n new Response(\"Gateway not ready\", { status: 503 }),\n );\n }\n return requestAls.run(request, () =>\n injectRequest(adapter.#supergraphApp!, request),\n );\n };\n }\n\n async updateSupergraph(): Promise<void> {\n if (!this.#getSubgraphs || !this.#supergraphContextFactory) return;\n const newApp = await buildGatewayApp(\n this.#getSubgraphs(),\n this.#supergraphContextFactory,\n this.#logger,\n );\n const oldApp = this.#supergraphApp;\n // Swap atomically — in-flight requests on the old app finish normally.\n this.#supergraphApp = newApp;\n if (oldApp) await oldApp.close();\n }\n\n async stop(): Promise<void> {\n await Promise.all(this.#subgraphApps.map((app) => app.close()));\n this.#subgraphApps.length = 0;\n if (this.#supergraphApp) {\n await this.#supergraphApp.close();\n this.#supergraphApp = null;\n }\n this.#getSubgraphs = null;\n this.#supergraphContextFactory = null;\n }\n}\n\n// ── Fastify instance factories ────────────────────────────────────────────────\n\nfunction makeContextFn(\n contextFactory: GatewayContextFactory<Context>,\n logger: ILogger,\n) {\n return (_req: FastifyRequest, _reply: FastifyReply) => {\n const request = requestAls.getStore();\n if (!request) {\n logger.error(\"[mercurius] No Fetch Request in AsyncLocalStorage\");\n throw new Error(\"No Fetch Request in AsyncLocalStorage\");\n }\n return contextFactory(request);\n };\n}\n\nasync function buildMercuriusApp(\n schema: GraphQLSchema,\n contextFactory: GatewayContextFactory<Context>,\n logger: ILogger,\n): Promise<FastifyInstance> {\n const app = Fastify({ logger: false });\n\n await app.register(mercurius, {\n schema,\n graphiql: false,\n context: makeContextFn(contextFactory, logger),\n // Override _Service.sdl to rewrite \"type Query/Mutation/Subscription {\"\n // as \"extend type … {\" so that @mercuriusjs/gateway v5 (which follows the\n // Federation v1 convention of using extensionTypeMap) correctly maps root\n // operation fields to this service during query planning.\n resolvers: {\n _Service: {\n sdl: (parent: { sdl?: string }) =>\n (parent.sdl ?? \"\").replace(\n /\\btype\\s+(Query|Mutation|Subscription)\\s*\\{/g,\n \"extend type $1 {\",\n ),\n },\n },\n } satisfies MercuriusOptions);\n\n await app.ready();\n return app;\n}\n\n/**\n * Builds a Mercurius federation gateway that composes the given subgraph\n * services. Each service URL must be reachable so that the gateway can fetch\n * its SDL via `_service { sdl }` (Apollo Federation protocol).\n */\nasync function buildGatewayApp(\n subgraphs: SubgraphDefinition[],\n contextFactory: GatewayContextFactory<Context>,\n logger: ILogger,\n): Promise<FastifyInstance> {\n const app = Fastify({ logger: false });\n\n await app.register(mercuriusGatewayPlugin, {\n gateway: {\n services: subgraphs.map((s) => ({ name: s.name, url: s.url })),\n },\n graphiql: false,\n context: makeContextFn(contextFactory, logger),\n });\n\n await app.ready();\n return app;\n}\n\n// ── Fetch API bridge ──────────────────────────────────────────────────────────\n\nfunction buildFetchHandler(app: FastifyInstance): FetchHandler {\n return (request: Request): Promise<Response> =>\n requestAls.run(request, () => injectRequest(app, request));\n}\n\nasync function injectRequest(\n app: FastifyInstance,\n request: Request,\n): Promise<Response> {\n const body =\n request.method !== \"GET\" && request.method !== \"HEAD\"\n ? await request.text()\n : undefined;\n\n const headers: Record<string, string> = {};\n request.headers.forEach((value, key) => {\n headers[key] = value;\n });\n\n const response = await app.inject({\n method: request.method as\n | \"DELETE\"\n | \"GET\"\n | \"HEAD\"\n | \"OPTIONS\"\n | \"PATCH\"\n | \"POST\"\n | \"PUT\",\n url: \"/graphql\",\n headers,\n payload: body,\n });\n\n const responseHeaders: Record<string, string> = {};\n for (const [key, value] of Object.entries(response.headers)) {\n if (value !== undefined) responseHeaders[key] = String(value);\n }\n\n return new Response(response.payload, {\n status: response.statusCode,\n headers: responseHeaders,\n });\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;AA6BA,MAAM,aAAa,IAAI,kBAA2B;AAQlD,MAAM,yBACJ;AAEF,IAAa,0BAAb,MAAyE;CACvE;CACA,gBAA4C,CAAC;CAE7C,iBAAyC;CACzC,gBAA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,SAAS,OAAO,GACxD,IAAI,UAAU,KAAA,GAAW,gBAAgB,OAAO,OAAO,KAAK;CAG9D,OAAO,IAAI,SAAS,SAAS,SAAS;EACpC,QAAQ,SAAS;EACjB,SAAS;CACX,CAAC;AACH","debug_id":"5f791eb2-83b0-5fbd-a834-cc764eb2823a"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="
|
|
2
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="0edd0828-ed3d-530e-80b6-70d8678af1f3")}catch(e){}}();
|
|
3
3
|
import { gql } from "graphql-tag";
|
|
4
4
|
import { Kind, Lexer, Source, TokenKind, isTypeDefinitionNode, isTypeExtensionNode, parse, print, visit } from "graphql";
|
|
5
5
|
import { childLogger, documentModelDocumentModelModule } from "document-model";
|
|
@@ -985,6 +985,178 @@ function describeOwnershipConflicts(conflicts) {
|
|
|
985
985
|
return `claims owned by another subgraph: ${conflicts.map(({ claim, owner }) => `${claim} (owned by "${owner}")`).join(", ")}`;
|
|
986
986
|
}
|
|
987
987
|
//#endregion
|
|
988
|
+
//#region src/graphql/subgraph-admission.ts
|
|
989
|
+
/** Where a subgraph came from; a package origin is the package name. */
|
|
990
|
+
const CORE_ORIGIN = Symbol("core");
|
|
991
|
+
const DOCUMENT_MODEL_ORIGIN = Symbol("document-models");
|
|
992
|
+
const HOST_ORIGIN = Symbol("host");
|
|
993
|
+
function describeOrigin(origin) {
|
|
994
|
+
if (origin === CORE_ORIGIN) return "core";
|
|
995
|
+
if (origin === DOCUMENT_MODEL_ORIGIN) return "document models";
|
|
996
|
+
if (origin === HOST_ORIGIN) return "the host";
|
|
997
|
+
return `package ${origin}`;
|
|
998
|
+
}
|
|
999
|
+
function rank(origin) {
|
|
1000
|
+
if (origin === CORE_ORIGIN) return 3;
|
|
1001
|
+
if (origin === HOST_ORIGIN) return 2;
|
|
1002
|
+
if (origin === DOCUMENT_MODEL_ORIGIN) return 1;
|
|
1003
|
+
return 0;
|
|
1004
|
+
}
|
|
1005
|
+
/** Usable models; a refused latest version refuses every version of its model. */
|
|
1006
|
+
function admitDocumentModels(resolved, reserved) {
|
|
1007
|
+
const latest = new Set(filterLatestDocumentModelVersions(resolved.map(({ model }) => model)));
|
|
1008
|
+
const candidates = [];
|
|
1009
|
+
for (const { model, key, schema, error } of resolved) {
|
|
1010
|
+
if (!schema) {
|
|
1011
|
+
const reason = `has an unusable schema: ${error.message}`;
|
|
1012
|
+
candidates.push({
|
|
1013
|
+
model,
|
|
1014
|
+
key,
|
|
1015
|
+
refusal: {
|
|
1016
|
+
reason,
|
|
1017
|
+
subgraphOnly: false
|
|
1018
|
+
}
|
|
1019
|
+
});
|
|
1020
|
+
continue;
|
|
1021
|
+
}
|
|
1022
|
+
const taken = reservedTypeNamesTaken(model, reserved, schema.generated);
|
|
1023
|
+
if (taken.length > 0) {
|
|
1024
|
+
const reason = `generates reserved type names: ${taken.join(", ")}`;
|
|
1025
|
+
candidates.push({
|
|
1026
|
+
model,
|
|
1027
|
+
key,
|
|
1028
|
+
refusal: {
|
|
1029
|
+
reason,
|
|
1030
|
+
subgraphOnly: false
|
|
1031
|
+
}
|
|
1032
|
+
});
|
|
1033
|
+
continue;
|
|
1034
|
+
}
|
|
1035
|
+
const refusal = schema.subgraphError && {
|
|
1036
|
+
reason: `has an unusable subgraph schema: ${schema.subgraphError.message}`,
|
|
1037
|
+
subgraphOnly: true
|
|
1038
|
+
};
|
|
1039
|
+
candidates.push({
|
|
1040
|
+
model,
|
|
1041
|
+
key,
|
|
1042
|
+
schema,
|
|
1043
|
+
refusal
|
|
1044
|
+
});
|
|
1045
|
+
}
|
|
1046
|
+
const refusedModels = new Set(candidates.filter(({ model, refusal }) => refusal && latest.has(model)).map(({ model }) => model.documentModel.global.name));
|
|
1047
|
+
const admission = {
|
|
1048
|
+
admitted: [],
|
|
1049
|
+
schemas: /* @__PURE__ */ new Map(),
|
|
1050
|
+
refusals: []
|
|
1051
|
+
};
|
|
1052
|
+
for (const { model, key, schema, refusal } of candidates) {
|
|
1053
|
+
const everyVersion = latest.has(model);
|
|
1054
|
+
if (!everyVersion && refusedModels.has(model.documentModel.global.name)) continue;
|
|
1055
|
+
if (refusal) admission.refusals.push({
|
|
1056
|
+
model,
|
|
1057
|
+
key,
|
|
1058
|
+
version: specVersion(model),
|
|
1059
|
+
everyVersion,
|
|
1060
|
+
...refusal
|
|
1061
|
+
});
|
|
1062
|
+
if (schema) {
|
|
1063
|
+
admission.schemas.set(model, schema);
|
|
1064
|
+
admission.admitted.push(model);
|
|
1065
|
+
}
|
|
1066
|
+
}
|
|
1067
|
+
return admission;
|
|
1068
|
+
}
|
|
1069
|
+
const DOCUMENT_MODELS_TO_EXCLUDE = [];
|
|
1070
|
+
const specVersion = (model) => model.documentModel.global.specifications.at(-1)?.version ?? 0;
|
|
1071
|
+
/** The latest version of each document model. */
|
|
1072
|
+
function filterLatestDocumentModelVersions(documentModels) {
|
|
1073
|
+
const latestByName = /* @__PURE__ */ new Map();
|
|
1074
|
+
for (const documentModel of documentModels) {
|
|
1075
|
+
const name = documentModel.documentModel.global.name;
|
|
1076
|
+
const existing = latestByName.get(name);
|
|
1077
|
+
if (!existing || specVersion(documentModel) > specVersion(existing)) latestByName.set(name, documentModel);
|
|
1078
|
+
}
|
|
1079
|
+
return Array.from(latestByName.values());
|
|
1080
|
+
}
|
|
1081
|
+
/** The admitted models that serve a subgraph of their own, with its types. */
|
|
1082
|
+
function documentModelSubgraphSources(admitted, schemas) {
|
|
1083
|
+
const sources = [];
|
|
1084
|
+
for (const model of filterLatestDocumentModelVersions(admitted)) {
|
|
1085
|
+
if (DOCUMENT_MODELS_TO_EXCLUDE.includes(model.documentModel.global.id)) continue;
|
|
1086
|
+
const types = schemas.get(model)?.subgraph;
|
|
1087
|
+
if (types) sources.push({
|
|
1088
|
+
model,
|
|
1089
|
+
types
|
|
1090
|
+
});
|
|
1091
|
+
}
|
|
1092
|
+
return sources;
|
|
1093
|
+
}
|
|
1094
|
+
/** Same origin replaces, higher rank evicts, else refused; core names never move (#2972). */
|
|
1095
|
+
function decideAdmission(candidate, origin, holders, collisions) {
|
|
1096
|
+
if (origin !== CORE_ORIGIN && holders.some((holder) => holder.origin === CORE_ORIGIN)) return {
|
|
1097
|
+
action: "reject",
|
|
1098
|
+
reason: "core name"
|
|
1099
|
+
};
|
|
1100
|
+
if (holders.some(({ holder }) => holder === candidate)) return { action: "skip" };
|
|
1101
|
+
const rivals = holders.filter((holder) => holder.origin !== origin);
|
|
1102
|
+
for (const rival of rivals) if (rank(origin) <= rank(rival.origin)) return {
|
|
1103
|
+
action: "reject",
|
|
1104
|
+
reason: "rank",
|
|
1105
|
+
holderOrigin: rival.origin
|
|
1106
|
+
};
|
|
1107
|
+
const found = origin === CORE_ORIGIN ? [] : collisions();
|
|
1108
|
+
if (found.length > 0) return {
|
|
1109
|
+
action: "reject",
|
|
1110
|
+
reason: "collision",
|
|
1111
|
+
collisions: found
|
|
1112
|
+
};
|
|
1113
|
+
return {
|
|
1114
|
+
action: "add",
|
|
1115
|
+
replaces: holders.filter((holder) => holder.origin === origin).map(({ holder }) => holder),
|
|
1116
|
+
evicts: rivals.map(({ holder }) => holder)
|
|
1117
|
+
};
|
|
1118
|
+
}
|
|
1119
|
+
/** The order origins first registered in, and names within each. */
|
|
1120
|
+
var RegistrationOrder = class {
|
|
1121
|
+
#origins = /* @__PURE__ */ new Map();
|
|
1122
|
+
record(origin, name) {
|
|
1123
|
+
let entry = this.#origins.get(origin);
|
|
1124
|
+
if (!entry) {
|
|
1125
|
+
entry = {
|
|
1126
|
+
order: this.#origins.size,
|
|
1127
|
+
names: /* @__PURE__ */ new Map()
|
|
1128
|
+
};
|
|
1129
|
+
this.#origins.set(origin, entry);
|
|
1130
|
+
}
|
|
1131
|
+
if (!entry.names.has(name)) entry.names.set(name, entry.names.size);
|
|
1132
|
+
}
|
|
1133
|
+
of(origin, name) {
|
|
1134
|
+
const entry = this.#origins.get(origin);
|
|
1135
|
+
return [entry?.order ?? Infinity, entry?.names.get(name) ?? Infinity];
|
|
1136
|
+
}
|
|
1137
|
+
};
|
|
1138
|
+
/** Rank, then first registration. */
|
|
1139
|
+
function byClaimPriority(members, originOf, nameOf, order) {
|
|
1140
|
+
return Array.from(members, (member) => {
|
|
1141
|
+
const origin = originOf(member);
|
|
1142
|
+
return {
|
|
1143
|
+
member,
|
|
1144
|
+
priority: [-rank(origin), ...order.of(origin, nameOf(member))]
|
|
1145
|
+
};
|
|
1146
|
+
}).sort((a, b) => {
|
|
1147
|
+
const i = a.priority.findIndex((value, j) => value !== b.priority[j]);
|
|
1148
|
+
return i === -1 ? 0 : a.priority[i] - b.priority[i];
|
|
1149
|
+
}).map(({ member }) => member);
|
|
1150
|
+
}
|
|
1151
|
+
/** Members that lose a claim: claims go by byClaimPriority. */
|
|
1152
|
+
function supergraphClaimLosers(members, order) {
|
|
1153
|
+
return resolveClaimOwnership(byClaimPriority(members, (member) => member.origin, (member) => member.name, order).map((member) => ({
|
|
1154
|
+
candidate: member.member,
|
|
1155
|
+
name: member.name,
|
|
1156
|
+
claims: member.claims
|
|
1157
|
+
})));
|
|
1158
|
+
}
|
|
1159
|
+
//#endregion
|
|
988
1160
|
//#region src/graphql/inspection/schema.ts
|
|
989
1161
|
const inspectionTypeDefs = gql`
|
|
990
1162
|
type ReactorStorageFacts {
|
|
@@ -1237,7 +1409,7 @@ const baseDocumentModels = [
|
|
|
1237
1409
|
["reactor-group", ReactorGroupV1]
|
|
1238
1410
|
];
|
|
1239
1411
|
//#endregion
|
|
1240
|
-
export {
|
|
1412
|
+
export { getDocumentModelTypeDefs as A, createSchema as C, generatedTypesOf as D, generateDocumentModelSchema as E, typeDefinitionNames as F, schema_default$1 as I, hasOperationSchemas as M, reservedTypeNames as N, getDocumentModelSchemaName as O, reservedTypeNamesTaken as P, createMergedSchema as S, findSubgraphTypeCollisions as T, DocumentModelSchemaCache as _, CORE_ORIGIN as a, buildDocumentModelSchema as b, RegistrationOrder as c, decideAdmission as d, describeOrigin as f, describeOwnershipConflicts as g, collectSubgraphClaims as h, inspectionTypeDefs as i, getGeneratedDocumentModelTypes as j, getDocumentModelSubgraphName as k, admitDocumentModels as l, supergraphClaimLosers as m, systemTypeDefs as n, DOCUMENT_MODEL_ORIGIN as o, documentModelSubgraphSources as p, schema_default as r, HOST_ORIGIN as s, baseDocumentModels as t, byClaimPriority as u, SubgraphTypeCollisionError as v, documentModelSubgraphTypes as w, buildSubgraphSchemaModule as x, assembleSubgraphTypeDefs as y };
|
|
1241
1413
|
|
|
1242
|
-
//# sourceMappingURL=base-document-models-
|
|
1243
|
-
//# debugId=
|
|
1414
|
+
//# sourceMappingURL=base-document-models-uUQKgXcf.mjs.map
|
|
1415
|
+
//# debugId=0edd0828-ed3d-530e-80b6-70d8678af1f3
|