UNPKG

wgc

Version:

The official CLI tool to manage the GraphQL Federation Platform Cosmo

60 lines 2.47 kB
import { EnumStatusCode } from '@wundergraph/cosmo-connect/dist/common/common_pb'; import pc from 'picocolors'; import { getBaseHeaders } from '../../../core/config.js'; export const getSubgraphsOfFedGraph = async ({ client, name, namespace, }) => { var _a, _b; const resp = await client.platform.getFederatedGraphByName({ name, namespace, includeMetrics: false, }, { headers: getBaseHeaders(), }); if (((_a = resp.response) === null || _a === void 0 ? void 0 : _a.code) !== EnumStatusCode.OK) { throw new Error(`${pc.red(`Could not fetch the federated graph ${pc.bold(name)}`)} \n${pc.red(pc.bold(((_b = resp.response) === null || _b === void 0 ? void 0 : _b.details) || ''))}`); } const subgraphs = await resp.subgraphs; return subgraphs.map((s) => { return { name: s.name, routingURL: s.routingURL, subscriptionURL: s.subscriptionUrl, subscriptionProtocol: s.subscriptionProtocol, isEventDrivenGraph: s.isEventDrivenGraph, isV2Graph: s.isV2Graph, }; }); }; export const getFederatedGraphSchemas = async ({ client, name, namespace, }) => { var _a, _b; const resp = await client.platform.getFederatedGraphSDLByName({ name, namespace, }, { headers: getBaseHeaders(), }); if (((_a = resp.response) === null || _a === void 0 ? void 0 : _a.code) !== EnumStatusCode.OK || !(resp === null || resp === void 0 ? void 0 : resp.sdl)) { throw new Error(`${pc.red(`Could not fetch the SDL of the federated graph ${pc.bold(name)}`)} \n${pc.red(pc.bold(((_b = resp.response) === null || _b === void 0 ? void 0 : _b.details) || ''))}`); } return { sdl: resp.sdl, clientSchema: resp.clientSchema, }; }; // Returns the latest valid schema version of a subgraph that was composed to form the provided federated graph. export const getSubgraphSDL = async ({ client, fedGraphName, subgraphName, namespace, }) => { var _a; const resp = await client.platform.getSubgraphSDLFromLatestComposition({ name: subgraphName, namespace, fedGraphName, }, { headers: getBaseHeaders(), }); if (((_a = resp.response) === null || _a === void 0 ? void 0 : _a.code) !== EnumStatusCode.OK) { return undefined; } const sdl = await resp.sdl; return sdl; }; //# sourceMappingURL=utils.js.map