1 | "use strict";
|
2 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
3 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
4 | };
|
5 | Object.defineProperty(exports, "__esModule", { value: true });
|
6 | exports.determineApolloConfig = void 0;
|
7 | const createSHA_1 = __importDefault(require("./utils/createSHA"));
|
8 | function determineApolloConfig(input) {
|
9 | var _a, _b;
|
10 | const apolloConfig = {};
|
11 | const { APOLLO_KEY, APOLLO_GRAPH_REF, APOLLO_GRAPH_ID, APOLLO_GRAPH_VARIANT, } = process.env;
|
12 | if (input === null || input === void 0 ? void 0 : input.key) {
|
13 | apolloConfig.key = input.key;
|
14 | }
|
15 | else if (APOLLO_KEY) {
|
16 | apolloConfig.key = APOLLO_KEY;
|
17 | }
|
18 | if (apolloConfig.key) {
|
19 | apolloConfig.keyHash = createSHA_1.default('sha512')
|
20 | .update(apolloConfig.key)
|
21 | .digest('hex');
|
22 | }
|
23 | if (input === null || input === void 0 ? void 0 : input.graphRef) {
|
24 | apolloConfig.graphRef = input.graphRef;
|
25 | }
|
26 | else if (APOLLO_GRAPH_REF) {
|
27 | apolloConfig.graphRef = APOLLO_GRAPH_REF;
|
28 | }
|
29 | const graphId = (_a = input === null || input === void 0 ? void 0 : input.graphId) !== null && _a !== void 0 ? _a : APOLLO_GRAPH_ID;
|
30 | const graphVariant = (_b = input === null || input === void 0 ? void 0 : input.graphVariant) !== null && _b !== void 0 ? _b : APOLLO_GRAPH_VARIANT;
|
31 | if (apolloConfig.graphRef) {
|
32 | if (graphId) {
|
33 | throw new Error('Cannot specify both graph ref and graph ID. Please use ' +
|
34 | '`apollo.graphRef` or `APOLLO_GRAPH_REF` without also setting the graph ID.');
|
35 | }
|
36 | if (graphVariant) {
|
37 | throw new Error('Cannot specify both graph ref and graph variant. Please use ' +
|
38 | '`apollo.graphRef` or `APOLLO_GRAPH_REF` without also setting the graph ID.');
|
39 | }
|
40 | }
|
41 | else if (graphId) {
|
42 | apolloConfig.graphRef = graphVariant
|
43 | ? `${graphId}@${graphVariant}`
|
44 | : graphId;
|
45 | }
|
46 | return apolloConfig;
|
47 | }
|
48 | exports.determineApolloConfig = determineApolloConfig;
|
49 |
|
\ | No newline at end of file |