wgc
Version:
The official CLI tool to manage the GraphQL Federation Platform Cosmo
62 lines • 3.28 kB
JavaScript
import { readFile } from 'node:fs/promises';
import { existsSync } from 'node:fs';
import { EnumStatusCode } from '@wundergraph/cosmo-connect/dist/common/common_pb';
import { join, resolve } from 'pathe';
export const FIXTURES_DIR_PATH = resolve('./test/fixtures');
export const ROUTER_SDL = 'type Query {\n users: [User]!\n}\n\ntype User {\n id: String @authenticated\n}';
export const CLIENT_SDL = 'type Query {\n users: [User]!\n}\n\ntype User {\n id: String\n}';
export function mockGenerateRouterToken(splitConfigsEnabled, _) {
return {
response: {
code: EnumStatusCode.OK,
},
/**
* This token was generated by jwt.io with the following claims:
* iss: 019e668c-b0f1-745c-82ac-d9ff15ab4c48
* organization_id: 019e668d-680c-755a-9e36-e3d498480718
* federated_graph_id: 019e668c-ef82-70be-a867-2af36b362b7d
*
* if `splitConfigsEnabled` is `true`, then the claim `features` is populated with `split-config-loading`;
* otherwise, the claim is not present in the token
*/
token: splitConfigsEnabled
? 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzM4NCJ9.eyJpc3MiOiIwMTllNjY4Yy1iMGYxLTc0NWMtODJhYy1kOWZmMTVhYjRjNDgiLCJhdWQiOiJjb3NtbzpncmFwaC1rZXkiLCJmZWRlcmF0ZWRfZ3JhcGhfaWQiOiIwMTllNjY4Yy1lZjgyLTcwYmUtYTg2Ny0yYWYzNmIzNjJiN2QiLCJvcmdhbml6YXRpb25faWQiOiIwMTllNjY4ZC02ODBjLTc1NWEtOWUzNi1lM2Q0OTg0ODA3MTgiLCJmZWF0dXJlcyI6WyJzcGxpdC1jb25maWctbG9hZGluZyJdfQ.7GvXTrnK2H9jiKOTR2FMadQpIoRKF713IxSztgFCDntCqnzN-1_20jmqnk_wxK0Q'
: 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzM4NCJ9.eyJpc3MiOiIwMTllNjY4Yy1iMGYxLTc0NWMtODJhYy1kOWZmMTVhYjRjNDgiLCJhdWQiOiJjb3NtbzpncmFwaC1rZXkiLCJmZWRlcmF0ZWRfZ3JhcGhfaWQiOiIwMTllNjY4Yy1lZjgyLTcwYmUtYTg2Ny0yYWYzNmIzNjJiN2QiLCJvcmdhbml6YXRpb25faWQiOiIwMTllNjY4ZC02ODBjLTc1NWEtOWUzNi1lM2Q0OTg0ODA3MTgifQ.PPMNqh7EfTiTiLD9AydAf7CSg_LRXTkdAOy1SNMlLc0Pe58e4tNDPuDx3iWbdJ3m',
};
}
export const mockFetchRouterConfig = async (info) => {
let url;
if (info instanceof URL) {
url = info;
}
else if (typeof info === 'string') {
url = new URL(info);
}
else if (info instanceof Request) {
url = new URL(info.url);
}
let filePath;
if (url) {
if (url.pathname.endsWith('routerconfigs/latest.json')) {
filePath = join(FIXTURES_DIR_PATH, 'router-compose', 'router-config.json.snap');
}
else if (url.pathname.endsWith('manifest/latest.json')) {
filePath = join(FIXTURES_DIR_PATH, 'router-compose', 'split-config', 'router-config.json.snap');
}
else if (url.pathname.endsWith('manifest/mapper.json')) {
filePath = join(FIXTURES_DIR_PATH, 'router-compose', 'split-config', 'mapper.json.snap');
}
else if (url.pathname.endsWith('manifest/feature-flags/my-feature-flag.json')) {
filePath = join(FIXTURES_DIR_PATH, 'router-compose', 'split-config', 'feature-flags', 'my-feature-flag.json.snap');
}
}
let body;
if (filePath && existsSync(filePath)) {
body = new Blob([await readFile(filePath)]).stream();
}
return new Response(body, {
status: body ? 200 : 404,
statusText: body ? 'OK' : 'Not Found',
});
};
//# sourceMappingURL=utils.js.map