@powerhousedao/reactor-api 6.2.3-dev.79 → 6.2.3-dev.80
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-D-EdZ4e-.mjs +2 -2
- package/dist/adapter-gateway-apollo-D-EdZ4e-.mjs.map +1 -1
- package/dist/{base-document-models-ux7TZ9X3.mjs → base-document-models-D-cmBBYJ.mjs} +116 -27
- package/dist/base-document-models-D-cmBBYJ.mjs.map +1 -0
- package/dist/{create-schema-BUk-IQCT.d.mts → create-schema-Dio_7akA.d.mts} +22 -7
- package/dist/create-schema-Dio_7akA.d.mts.map +1 -0
- package/dist/error-info-BaEL50f5.mjs +2 -2
- package/dist/error-info-BaEL50f5.mjs.map +1 -1
- package/dist/index.d.mts +297 -7
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +607 -138
- package/dist/index.mjs.map +1 -1
- package/dist/{package-subgraph-check-BGfeyfnc.mjs → package-subgraph-check-C0PD_Tj9.mjs} +4 -4
- package/dist/{package-subgraph-check-BGfeyfnc.mjs.map → package-subgraph-check-C0PD_Tj9.mjs.map} +1 -1
- package/dist/src/graphql/subgraph-types.d.mts +1 -1
- package/dist/src/graphql/subgraph-types.mjs +1 -1
- package/dist/src/packages/vite-loader.d.mts +4 -1
- package/dist/src/packages/vite-loader.d.mts.map +1 -1
- package/dist/src/packages/vite-loader.mjs +31 -13
- package/dist/src/packages/vite-loader.mjs.map +1 -1
- package/dist/{subgraph-extraction-BYKOycxo.mjs → subgraph-extraction-BA9WKjn1.mjs} +470 -10
- package/dist/subgraph-extraction-BA9WKjn1.mjs.map +1 -0
- package/dist/{types-BEpxtyKW.d.mts → types-PXB1ctpi.d.mts} +19 -2
- package/dist/types-PXB1ctpi.d.mts.map +1 -0
- package/package.json +13 -14
- package/dist/base-document-models-ux7TZ9X3.mjs.map +0 -1
- package/dist/create-schema-BUk-IQCT.d.mts.map +0 -1
- package/dist/subgraph-extraction-BYKOycxo.mjs.map +0 -1
- package/dist/types-BEpxtyKW.d.mts.map +0 -1
|
@@ -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]="4b08cabd-f774-5807-9d1f-f0a6822a26ad")}catch(e){}}();
|
|
3
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";
|
|
@@ -158,4 +158,4 @@ function createApolloFetchHandler(server, contextFactory) {
|
|
|
158
158
|
export { createApolloFetchHandler as n, adapter_gateway_apollo_exports as t };
|
|
159
159
|
|
|
160
160
|
//# sourceMappingURL=adapter-gateway-apollo-D-EdZ4e-.mjs.map
|
|
161
|
-
//# debugId=
|
|
161
|
+
//# debugId=4b08cabd-f774-5807-9d1f-f0a6822a26ad
|
|
@@ -1 +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,SAAS,OAAO;GACd,QAAQ,MACN,uBAAuB,QAAQ,KAAK,iCAClC,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,GAEzD;GACA,OAAO;EACT;CACF,CAAC;AACH;AAGA,IAAM,0BAAN,cAAsC,wBAAwB;CAC5D,YACE,QACA;EAGA,MAAM;GACJ,SAAS;GACT,GAAG;EACL,CAAC;CACH;CAEA,gBAAgB,SAA0C;EACxD,MAAM,EAAE,kBAAkB,QAAQ,QAAQ;EAG1C,IAAI,iBAAiB,SAAS,QAAQ,MACpC,QAAQ,QAAQ,KAAK,QAAQ,IAAI,iBAAiB,aAAa;CAEnE;AACF;AAEA,IAAa,uBAAb,MAAsE;CACpE;CACA,WAA6C,CAAC;CAE9C,oBAAkD;CAClD,kBAIW;CACX,gBAAqD;CAErD,YAAY,QAAiB;EAC3B,KAAK,UAAU;CACjB;CAEA,MAAM,MAAM,aAAyC,CAGrD;CAEA,MAAM,cACJ,QACA,gBACuB;EACvB,MAAM,SAAS,IAAI,aAAsB;GACvC;GACA,QAAQ,KAAK;GACb,eAAe;GAOf,0BAA0B;GAC1B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,KAAK,CAAC,CAAC;EACpD,KAAK,SAAS,SAAS;EAEvB,IAAI,KAAK,mBAAmB;GAC1B,MAAM,KAAK,kBAAkB,KAAK;GAClC,KAAK,oBAAoB;EAC3B;EACA,KAAK,kBAAkB;EACvB,KAAK,gBAAgB;CACvB;AACF;;;;;AAMA,SAAgB,yBACd,QACA,gBACc;CACd,OAAO,OAAO,YAAwC;EACpD,MAAM,MAAM,IAAI,IAAI,QAAQ,GAAG;EAC/B,MAAM,UAAU,IAAI,UAAU;EAC9B,QAAQ,QAAQ,SAAS,OAAO,QAAQ,QAAQ,IAAI,KAAK,KAAK,CAAC;EAE/D,IAAI,OAAgB,KAAA;EACpB,IAAI,QAAQ,WAAW,SAAS,QAAQ,WAAW,QACjD,IAAI;GACF,OAAQ,MAAM,QAAQ,KAAK;EAC7B,QAAQ,CAER;EAGF,MAAM,SAAS,MAAM,OAAO,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"}
|
|
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 override 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,SAAS,OAAO;GACd,QAAQ,MACN,uBAAuB,QAAQ,KAAK,iCAClC,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,GAEzD;GACA,OAAO;EACT;CACF,CAAC;AACH;AAGA,IAAM,0BAAN,cAAsC,wBAAwB;CAC5D,YACE,QACA;EAGA,MAAM;GACJ,SAAS;GACT,GAAG;EACL,CAAC;CACH;CAEA,gBAAyB,SAA0C;EACjE,MAAM,EAAE,kBAAkB,QAAQ,QAAQ;EAG1C,IAAI,iBAAiB,SAAS,QAAQ,MACpC,QAAQ,QAAQ,KAAK,QAAQ,IAAI,iBAAiB,aAAa;CAEnE;AACF;AAEA,IAAa,uBAAb,MAAsE;CACpE;CACA,WAA6C,CAAC;CAE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SAAS,cAAc;GAChC,QAAQ,OAAO,UAAU;GACzB,SAAS;EACX,CAAC;CACH;AACF","debug_id":"4b08cabd-f774-5807-9d1f-f0a6822a26ad"}
|
|
@@ -1,19 +1,88 @@
|
|
|
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]="15ba8214-2497-5db6-b2f0-f5342ed231ba")}catch(e){}}();
|
|
3
3
|
import { childLogger, documentModelDocumentModelModule } from "document-model";
|
|
4
4
|
import { gql } from "graphql-tag";
|
|
5
|
-
import { Kind, Lexer, Source, TokenKind, isTypeDefinitionNode, isTypeExtensionNode, parse, print, visit } from "graphql";
|
|
5
|
+
import { GraphQLScalarType, Kind, Lexer, Source, TokenKind, isTypeDefinitionNode, isTypeExtensionNode, parse, print, valueFromASTUntyped, visit } from "graphql";
|
|
6
6
|
import { createHash } from "node:crypto";
|
|
7
|
+
import { scalarCatalog } from "document-model/scalars";
|
|
8
|
+
import { GraphQLJSON, GraphQLJSONObject } from "graphql-type-json";
|
|
9
|
+
import { inspect, isDeepStrictEqual } from "node:util";
|
|
10
|
+
import { z } from "zod";
|
|
7
11
|
import { buildSubgraphSchema } from "@apollo/subgraph";
|
|
8
|
-
import { typeDefs } from "@powerhousedao/document-engineering/graphql";
|
|
9
12
|
import { camelCase, kebabCase, pascalCase } from "change-case";
|
|
10
|
-
import { GraphQLJSON, GraphQLJSONObject } from "graphql-type-json";
|
|
11
13
|
import { reactorDriveDocumentModelModule } from "@powerhousedao/reactor-drive";
|
|
12
14
|
import { ReactorGroupV1 } from "@powerhousedao/reactor-group";
|
|
13
15
|
import { driveDocumentModelModule } from "@powerhousedao/shared/document-drive";
|
|
14
16
|
//#region src/graphql/auth/schema.graphql
|
|
15
17
|
var schema_default$1 = "# Auth Subgraph Schema\n# Contains all document permission and authorization related types\n\nscalar DateTime\n\n# Permission levels for documents\nenum DocumentPermissionLevel {\n # Can fetch and read the document\n READ\n # Can push updates and modify the document\n WRITE\n # Can manage document permissions and settings\n ADMIN\n}\n\n# Document permission entry\ntype DocumentPermissionEntry {\n documentId: String!\n userAddress: String!\n permission: DocumentPermissionLevel!\n grantedBy: String!\n createdAt: DateTime!\n updatedAt: DateTime!\n}\n\n# Operation user permission entry\ntype OperationUserPermission {\n documentId: String!\n operationType: String!\n userAddress: String!\n grantedBy: String!\n createdAt: DateTime!\n}\n\n# Combined document access info\ntype DocumentAccessInfo {\n documentId: String!\n permissions: [DocumentPermissionEntry!]!\n}\n\n# Operation permissions info\ntype OperationPermissionsInfo {\n documentId: String!\n operationType: String!\n userPermissions: [OperationUserPermission!]!\n}\n\n# Document protection info\ntype DocumentProtectionInfo {\n documentId: String!\n protected: Boolean!\n ownerAddress: String\n}\n\ntype Query {\n # Get permissions for a document (requires ADMIN permission or global admin)\n documentAccess(\n documentIdOrSlug: String\n documentId: String @deprecated(reason: \"Use documentIdOrSlug.\")\n ): DocumentAccessInfo!\n\n # Get protection status for a document (requires ADMIN permission or global admin)\n documentProtection(\n documentIdOrSlug: String\n documentId: String @deprecated(reason: \"Use documentIdOrSlug.\")\n ): DocumentProtectionInfo!\n\n # Get all documents the current user has explicit access to\n userDocumentPermissions: [DocumentPermissionEntry!]!\n\n # Get operation permissions for a document and operation type\n # (requires ADMIN permission or global admin)\n operationPermissions(\n documentIdOrSlug: String\n documentId: String @deprecated(reason: \"Use documentIdOrSlug.\")\n operationType: String!\n ): OperationPermissionsInfo!\n\n # Check if the current user can execute a specific operation on a document\n canExecuteOperation(\n documentIdOrSlug: String\n documentId: String @deprecated(reason: \"Use documentIdOrSlug.\")\n operationType: String!\n ): Boolean!\n}\n\ntype Mutation {\n # Set document protection status (requires ADMIN permission or global admin)\n setDocumentProtection(\n documentIdOrSlug: String\n documentId: String @deprecated(reason: \"Use documentIdOrSlug.\")\n protected: Boolean!\n ): DocumentProtectionInfo!\n\n # Transfer document ownership (requires ADMIN permission or global admin)\n transferDocumentOwnership(\n documentIdOrSlug: String\n documentId: String @deprecated(reason: \"Use documentIdOrSlug.\")\n newOwnerAddress: String!\n ): DocumentProtectionInfo!\n\n # Grant a user permission on a document (requires ADMIN permission or global admin)\n grantDocumentPermission(\n documentIdOrSlug: String\n documentId: String @deprecated(reason: \"Use documentIdOrSlug.\")\n userAddress: String!\n permission: DocumentPermissionLevel!\n ): DocumentPermissionEntry!\n\n # Revoke a user's permission on a document (requires ADMIN permission or global admin)\n revokeDocumentPermission(\n documentIdOrSlug: String\n documentId: String @deprecated(reason: \"Use documentIdOrSlug.\")\n userAddress: String!\n ): Boolean!\n\n # --- Operation Permissions ---\n\n # Grant a user permission to execute an operation on a document\n grantOperationPermission(\n documentIdOrSlug: String\n documentId: String @deprecated(reason: \"Use documentIdOrSlug.\")\n operationType: String!\n userAddress: String!\n ): OperationUserPermission!\n\n # Revoke a user's permission to execute an operation\n revokeOperationPermission(\n documentIdOrSlug: String\n documentId: String @deprecated(reason: \"Use documentIdOrSlug.\")\n operationType: String!\n userAddress: String!\n ): Boolean!\n}\n";
|
|
16
18
|
//#endregion
|
|
19
|
+
//#region src/utils/scalar-types.ts
|
|
20
|
+
const EMPTY_SCALAR_REGISTRY = /* @__PURE__ */ new Map();
|
|
21
|
+
function sameScalarRegistry(a, b) {
|
|
22
|
+
if (a.size !== b.size) return false;
|
|
23
|
+
for (const [name, scalar] of a) {
|
|
24
|
+
const other = b.get(name);
|
|
25
|
+
if (other?.definition !== scalar.definition || other.packageName !== scalar.packageName) return false;
|
|
26
|
+
}
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
const catalogScalarSdl = scalarCatalog.map(({ name }) => `scalar ${name}`).join("\n");
|
|
30
|
+
const catalogResolvers = Object.fromEntries(scalarCatalog.map(({ name }) => [name, new GraphQLScalarType({
|
|
31
|
+
serialize: (value) => value,
|
|
32
|
+
parseValue: (value) => value,
|
|
33
|
+
parseLiteral: valueFromASTUntyped,
|
|
34
|
+
...name === "JSONObject" ? GraphQLJSONObject.toConfig() : name === "Unknown" ? GraphQLJSON.toConfig() : {},
|
|
35
|
+
name
|
|
36
|
+
})]));
|
|
37
|
+
function hasVariable(ast) {
|
|
38
|
+
let found = false;
|
|
39
|
+
visit(ast, { Variable() {
|
|
40
|
+
found = true;
|
|
41
|
+
} });
|
|
42
|
+
return found;
|
|
43
|
+
}
|
|
44
|
+
function losslessJson(value) {
|
|
45
|
+
try {
|
|
46
|
+
const json = JSON.parse(JSON.stringify(value));
|
|
47
|
+
return isDeepStrictEqual(json, value) ? { json } : void 0;
|
|
48
|
+
} catch {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
function show(value) {
|
|
53
|
+
try {
|
|
54
|
+
return losslessJson(value) ? JSON.stringify(value) : inspect(value, {
|
|
55
|
+
customInspect: false,
|
|
56
|
+
breakLength: Infinity
|
|
57
|
+
});
|
|
58
|
+
} catch {
|
|
59
|
+
return "a value that cannot be printed";
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
/** Validates with the definition's schema and accepts only a canonical value. */
|
|
63
|
+
function registeredScalarType(definition) {
|
|
64
|
+
const check = (value) => {
|
|
65
|
+
const result = definition.schema.safeParse(value);
|
|
66
|
+
if (!result.success) throw new Error(`${definition.name}: ${z.prettifyError(result.error)}`);
|
|
67
|
+
const output = losslessJson(result.data);
|
|
68
|
+
if (!output) throw new Error(`${definition.name}: the schema output is not JSON: ${show(result.data)}`);
|
|
69
|
+
const reparsed = definition.schema.safeParse(output.json);
|
|
70
|
+
if (reparsed.success && isDeepStrictEqual(reparsed.data, result.data)) return result.data;
|
|
71
|
+
const outcome = reparsed.success ? `parses to ${show(reparsed.data)}.` : `fails it: ${z.prettifyError(reparsed.error)}`;
|
|
72
|
+
throw new Error(`${definition.name}: the schema must accept its own output unchanged, but ${show(result.data)} ${outcome}`);
|
|
73
|
+
};
|
|
74
|
+
return new GraphQLScalarType({
|
|
75
|
+
name: definition.name,
|
|
76
|
+
description: definition.description,
|
|
77
|
+
serialize: (value) => value,
|
|
78
|
+
parseValue: check,
|
|
79
|
+
parseLiteral: (ast, variables) => {
|
|
80
|
+
if (variables == null && hasVariable(ast)) return null;
|
|
81
|
+
return check(valueFromASTUntyped(ast, variables));
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
//#endregion
|
|
17
86
|
//#region src/utils/create-schema.ts
|
|
18
87
|
const logger = childLogger(["reactor-api", "create-schema"]);
|
|
19
88
|
/**
|
|
@@ -170,13 +239,16 @@ function buildModuleSchemas(specification, documentName, allTypeNames, hasValidS
|
|
|
170
239
|
}).filter(Boolean).join("\n") ?? "";
|
|
171
240
|
}
|
|
172
241
|
const buildSubgraphSchemaModule = (documentModels, resolvers, typeDefs, options = {}) => {
|
|
242
|
+
const generated = options.generated ?? getGeneratedDocumentModelTypes(documentModels, void 0, options.scalars);
|
|
173
243
|
const newResolvers = {
|
|
244
|
+
...catalogResolvers,
|
|
245
|
+
...Object.fromEntries(Array.from(generated.scalars, ([name, { definition }]) => [name, registeredScalarType(definition)])),
|
|
174
246
|
...resolvers,
|
|
175
|
-
JSONObject:
|
|
176
|
-
Unknown:
|
|
247
|
+
JSONObject: catalogResolvers.JSONObject,
|
|
248
|
+
Unknown: catalogResolvers.Unknown
|
|
177
249
|
};
|
|
178
250
|
return {
|
|
179
|
-
typeDefs: assembleSubgraphTypeDefs(
|
|
251
|
+
typeDefs: assembleSubgraphTypeDefs(generated, typeDefs, options.ownTypeNames),
|
|
180
252
|
resolvers: newResolvers
|
|
181
253
|
};
|
|
182
254
|
};
|
|
@@ -268,14 +340,10 @@ function reservedTypeNamesTaken(documentModel, reserved, definitions = documentM
|
|
|
268
340
|
const generated = addScalarFlags(definitions, /* @__PURE__ */ new Map());
|
|
269
341
|
return Array.from(generated).filter(([name, scalar]) => reserved.has(name) && !(scalar && reserved.get(name))).map(([name]) => name);
|
|
270
342
|
}
|
|
271
|
-
const
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
scalar Unknown
|
|
276
|
-
scalar Address
|
|
277
|
-
${typeDefs.join("\n").replaceAll(";", "")}
|
|
278
|
-
|
|
343
|
+
const CATALOG_SCALARS = gql`
|
|
344
|
+
${catalogScalarSdl}
|
|
345
|
+
`.definitions;
|
|
346
|
+
const HOST_TYPES = gql`
|
|
279
347
|
type PHOperationContext {
|
|
280
348
|
signer: Signer
|
|
281
349
|
}
|
|
@@ -320,6 +388,28 @@ const GENERATED_HEAD = gql`
|
|
|
320
388
|
stateJSON: JSONObject
|
|
321
389
|
}
|
|
322
390
|
`.definitions;
|
|
391
|
+
/**
|
|
392
|
+
* A federation gateway composes this SDL, not the schema built from it, so the
|
|
393
|
+
* description is declared here as well as on the resolver.
|
|
394
|
+
*/
|
|
395
|
+
function generatedHead(scalars) {
|
|
396
|
+
return [
|
|
397
|
+
...CATALOG_SCALARS,
|
|
398
|
+
...Array.from(scalars, ([name, { definition }]) => ({
|
|
399
|
+
kind: Kind.SCALAR_TYPE_DEFINITION,
|
|
400
|
+
name: {
|
|
401
|
+
kind: Kind.NAME,
|
|
402
|
+
value: name
|
|
403
|
+
},
|
|
404
|
+
description: definition.description === void 0 ? void 0 : {
|
|
405
|
+
kind: Kind.STRING,
|
|
406
|
+
value: definition.description,
|
|
407
|
+
block: true
|
|
408
|
+
}
|
|
409
|
+
})),
|
|
410
|
+
...HOST_TYPES
|
|
411
|
+
];
|
|
412
|
+
}
|
|
323
413
|
const GENERATED_TAIL = gql`
|
|
324
414
|
type GqlDocument implements IDocument {
|
|
325
415
|
id: String!
|
|
@@ -347,17 +437,17 @@ const GENERATED_TAIL = gql`
|
|
|
347
437
|
* The generated schema for `documentModels`. `schemas` supplies models'
|
|
348
438
|
* definitions already built; the others are built here.
|
|
349
439
|
*/
|
|
350
|
-
function getGeneratedDocumentModelTypes(documentModels, schemas) {
|
|
440
|
+
function getGeneratedDocumentModelTypes(documentModels, schemas, scalars = EMPTY_SCALAR_REGISTRY) {
|
|
351
441
|
return generatedTypesFrom(documentModels.map((model) => ({
|
|
352
442
|
global: model.documentModel.global,
|
|
353
443
|
generated: schemas?.get(model)?.generated
|
|
354
|
-
})));
|
|
444
|
+
})), scalars);
|
|
355
445
|
}
|
|
356
446
|
/** {@link getGeneratedDocumentModelTypes} from the models' global states. */
|
|
357
447
|
function generatedTypesOf(documentModels) {
|
|
358
|
-
return generatedTypesFrom(documentModels.map((global) => ({ global })));
|
|
448
|
+
return generatedTypesFrom(documentModels.map((global) => ({ global })), EMPTY_SCALAR_REGISTRY);
|
|
359
449
|
}
|
|
360
|
-
function generatedTypesFrom(documentModels) {
|
|
450
|
+
function generatedTypesFrom(documentModels, scalars) {
|
|
361
451
|
const modelDefinitions = [];
|
|
362
452
|
const addedDocumentModels = /* @__PURE__ */ new Set();
|
|
363
453
|
documentModels.forEach(({ global, generated }) => {
|
|
@@ -370,13 +460,14 @@ function generatedTypesFrom(documentModels) {
|
|
|
370
460
|
modelDefinitions.push(...generated ?? documentModelDefinitions(global));
|
|
371
461
|
});
|
|
372
462
|
const definitions = dedupeTypeDefinitions([
|
|
373
|
-
...
|
|
463
|
+
...generatedHead(scalars),
|
|
374
464
|
...modelDefinitions,
|
|
375
465
|
...GENERATED_TAIL
|
|
376
466
|
]);
|
|
377
467
|
return {
|
|
378
468
|
definitions,
|
|
379
|
-
names: new Set(definitions.map(typeDefinitionName).filter((name) => name !== void 0))
|
|
469
|
+
names: new Set(definitions.map(typeDefinitionName).filter((name) => name !== void 0)),
|
|
470
|
+
scalars
|
|
380
471
|
};
|
|
381
472
|
}
|
|
382
473
|
const hasValidSchema = (schema) => !!(schema && /\b(input|type|enum|union|interface)\s+\w+/.test(schema));
|
|
@@ -814,9 +905,7 @@ function generateNewApiSchema(documentName, specification, prefixedStateInputTyp
|
|
|
814
905
|
const operationMutations = specification?.modules.flatMap((module) => module.operations.filter((op) => op.name && hasValidSchema(op.schema)).flatMap((op) => [`${camelCase(op.name)}(documentIdOrSlug: String, docId: PHID @deprecated(reason: "Use documentIdOrSlug."), input: ${documentName}_${pascalCase(op.name)}Input!): ${documentName}MutationResult!`, `${camelCase(op.name)}Async(documentIdOrSlug: String, docId: PHID @deprecated(reason: "Use documentIdOrSlug."), input: ${documentName}_${pascalCase(op.name)}Input!): String!`])).join("\n ") ?? "";
|
|
815
906
|
const moduleSchemas = buildModuleSchemas(specification, documentName, allTypeNames, hasValidSchema);
|
|
816
907
|
return gql`
|
|
817
|
-
|
|
818
|
-
scalar JSONObject
|
|
819
|
-
scalar AttachmentRef
|
|
908
|
+
${catalogScalarSdl}
|
|
820
909
|
|
|
821
910
|
${revisionType}
|
|
822
911
|
|
|
@@ -1488,7 +1577,7 @@ const baseDocumentModels = [
|
|
|
1488
1577
|
["reactor-group", ReactorGroupV1]
|
|
1489
1578
|
];
|
|
1490
1579
|
//#endregion
|
|
1491
|
-
export { getDocumentModelSubgraphName as A, createMergedSchema as C, generateDocumentModelSchema as D, findSubgraphTypeCollisions as E, reservedTypeNamesTaken as F, typeDefinitionNames as I,
|
|
1580
|
+
export { getDocumentModelSubgraphName as A, createMergedSchema as C, generateDocumentModelSchema as D, findSubgraphTypeCollisions as E, reservedTypeNamesTaken as F, typeDefinitionNames as I, EMPTY_SCALAR_REGISTRY as L, getGeneratedDocumentModelTypes as M, hasOperationSchemas as N, generatedTypesOf as O, reservedTypeNames as P, sameScalarRegistry as R, buildSubgraphSchemaModule as S, documentModelSubgraphTypes as T, describeOwnershipConflicts as _, inspectionAdminTypeDefs as a, assembleSubgraphTypeDefs as b, HOST_ORIGIN as c, byClaimPriority as d, decideAdmission as f, collectSubgraphClaims as g, supergraphClaimLosers as h, inspectionTypeDefs as i, getDocumentModelTypeDefs as j, getDocumentModelSchemaName as k, RegistrationOrder as l, documentModelSubgraphSources as m, systemTypeDefs as n, CORE_ORIGIN as o, describeOrigin as p, schema_default as r, DOCUMENT_MODEL_ORIGIN as s, baseDocumentModels as t, admitDocumentModels as u, DocumentModelSchemaCache as v, createSchema as w, buildDocumentModelSchema as x, SubgraphTypeCollisionError as y, schema_default$1 as z };
|
|
1492
1581
|
|
|
1493
|
-
//# sourceMappingURL=base-document-models-
|
|
1494
|
-
//# debugId=
|
|
1582
|
+
//# sourceMappingURL=base-document-models-D-cmBBYJ.mjs.map
|
|
1583
|
+
//# debugId=15ba8214-2497-5db6-b2f0-f5342ed231ba
|