1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const config_1 = require("./config");
|
4 | function loadConfigStep(flags, defaultEndpoint) {
|
5 | const header = Array.isArray(flags.header)
|
6 | ? flags.header
|
7 | : [flags.header];
|
8 | const task = {
|
9 | title: "Loading Apollo config",
|
10 | task: async (ctx) => {
|
11 | if (flags.config) {
|
12 | ctx.config = config_1.loadConfigFromFile(flags.config, defaultEndpoint, !flags.clientSchema);
|
13 | }
|
14 | else {
|
15 | ctx.config = config_1.findAndLoadConfig(process.cwd(), defaultEndpoint, !flags.clientSchema);
|
16 | }
|
17 | if (flags.schema || flags.endpoint) {
|
18 | ctx.config.schemas = {
|
19 | default: {
|
20 | schema: flags.schema,
|
21 | endpoint: flags.endpoint && Object.assign({ url: flags.endpoint }, (header.length > 0 && {
|
22 | headers: header
|
23 | .filter(x => !!x)
|
24 | .map(x => JSON.parse(x))
|
25 | .reduce((a, b) => Object.assign(a, b), {})
|
26 | }))
|
27 | }
|
28 | };
|
29 | }
|
30 | if (flags.clientSchema) {
|
31 | const extendsName = ctx.config.schemas.default
|
32 | ? "serverSchema"
|
33 | : undefined;
|
34 | ctx.config.schemas.serverSchema = ctx.config.schemas.default;
|
35 | ctx.config.schemas.default = {
|
36 | extends: extendsName,
|
37 | schema: flags.clientSchema,
|
38 | clientSide: true
|
39 | };
|
40 | }
|
41 | if (!ctx.config.queries ||
|
42 | (ctx.config.queries.length == 0 && flags.queries)) {
|
43 | ctx.config.queries = [
|
44 | {
|
45 | schema: "default",
|
46 | includes: flags.queries.split("\n"),
|
47 | excludes: []
|
48 | }
|
49 | ];
|
50 | }
|
51 | else if (flags.queries && flags.queries != "**/*.graphql") {
|
52 | ctx.config.queries = ctx.config.queries.map((query) => {
|
53 | return Object.assign({}, query, {
|
54 | includes: flags.queries.split("\n")
|
55 | });
|
56 | });
|
57 | }
|
58 | if (flags.key) {
|
59 | if (Object.keys(ctx.config.schemas).length == 1) {
|
60 | Object.values(ctx.config.schemas)[0].engineKey =
|
61 | flags.key;
|
62 | }
|
63 | }
|
64 | if (flags.engine) {
|
65 | ctx.config.engineEndpoint = flags.engine;
|
66 | }
|
67 | if (flags.skipSSLValidation) {
|
68 | if (Object.keys(ctx.config.schemas).length == 1) {
|
69 | const endpointConfiguration = Object.values(ctx.config.schemas)[0].endpoint;
|
70 | if (endpointConfiguration) {
|
71 | endpointConfiguration.skipSSLValidation = flags.skipSSLValidation;
|
72 | }
|
73 | }
|
74 | }
|
75 | if (ctx.config.queries.length == 0 && ctx.config.schemas.default) {
|
76 | ctx.config.queries.push({
|
77 | schema: "default",
|
78 | includes: ["**/*.graphql"],
|
79 | excludes: []
|
80 | });
|
81 | }
|
82 | }
|
83 | };
|
84 | return task;
|
85 | }
|
86 | exports.loadConfigStep = loadConfigStep;
|
87 |
|
\ | No newline at end of file |