forked from apollographql/apollo-tooling
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathload-config.ts
More file actions
107 lines (97 loc) · 2.76 KB
/
load-config.ts
File metadata and controls
107 lines (97 loc) · 2.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import {
loadConfigFromFile,
findAndLoadConfig,
SchemaDependency
} from "./config";
import { ListrTask } from "listr";
export function loadConfigStep(
flags: any,
defaultEndpoint: boolean
): ListrTask {
const header: any[] = Array.isArray(flags.header)
? flags.header
: [flags.header];
const task = {
title: "Loading Apollo config",
task: async (ctx: any) => {
if (flags.config) {
ctx.config = loadConfigFromFile(
flags.config,
defaultEndpoint,
!flags.clientSchema
);
} else {
ctx.config = findAndLoadConfig(
process.cwd(),
defaultEndpoint,
!flags.clientSchema
);
}
if (flags.schema || flags.endpoint) {
ctx.config.schemas = {
default: {
schema: flags.schema,
endpoint: flags.endpoint && {
url: flags.endpoint,
...(header.length > 0 && {
headers: header
.filter(x => !!x)
.map(x => JSON.parse(x))
.reduce((a, b) => Object.assign(a, b), {})
})
}
}
};
}
if (flags.clientSchema) {
const extendsName = ctx.config.schemas.default
? "serverSchema"
: undefined;
ctx.config.schemas.serverSchema = ctx.config.schemas.default;
ctx.config.schemas.default = {
extends: extendsName,
schema: flags.clientSchema,
clientSide: true
};
}
if (!ctx.config.queries || ctx.config.queries.length == 0 && flags.queries) {
ctx.config.queries = [
{
schema: "default",
includes: flags.queries.split("\n"),
excludes: []
}
];
}
else if (flags.queries && flags.queries != '**/*.graphql') {
ctx.config.queries = ctx.config.queries.map((query: any) => {
return Object.assign({}, query, {
includes: flags.queries.split("\n")
})
})
}
if (flags.key) {
if (Object.keys(ctx.config.schemas).length == 1) {
(Object.values(ctx.config.schemas)[0] as SchemaDependency).engineKey =
flags.key;
}
}
if (flags.engine) {
ctx.config.engineEndpoint = flags.engine;
}
if (flags.insecure) {
if (Object.keys(ctx.config.schemas).length == 1) {
(Object.values(ctx.config.schemas)[0] as SchemaDependency).skipsSSLValidation = flags.insecure;
}
}
if (ctx.config.queries.length == 0 && ctx.config.schemas.default) {
ctx.config.queries.push({
schema: "default",
includes: ["**/*.graphql"],
excludes: []
});
}
}
};
return task;
}