forked from sid88in/serverless-appsync-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget-config.js
54 lines (48 loc) · 1.54 KB
/
get-config.js
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
const fs = require('fs');
const path = require('path');
const {
mapObjIndexed,
pipe,
values,
merge,
} = require('ramda');
const objectToArrayWithNameProp = pipe(
mapObjIndexed((item, key) => merge({ name: key }, item)),
values,
);
module.exports = (config, provider, servicePath) => {
// TODO verify authenticationType
if (!config.authenticationType) {
throw new Error('appSync property `authenticationType` is required.');
}
if (!config.serviceRole) {
throw new Error('appSync property `serviceRole` is required.');
}
if (
config.authenticationType === 'AMAZON_COGNITO_USER_POOLS' &&
!config.userPoolConfig
) {
throw new Error('appSync property `userPoolConfig` is required when authenticationType `AMAZON_COGNITO_USER_POOLS` is chosen.');
}
const mappingTemplatesLocation = config.mappingTemplatesLocation || 'mapping-templates';
const mappingTemplates = config.mappingTemplates || [];
const schemaPath = path.join(servicePath, config.schema || 'schema.graphql');
const schemaContent = fs.readFileSync(schemaPath, {
encoding: 'utf8',
});
const dataSources = objectToArrayWithNameProp(config.dataSources);
return {
name: config.name || 'api',
apiId: config.apiId,
apiKey: config.apiKey,
region: provider.region,
authenticationType: config.authenticationType,
schema: schemaContent,
userPoolConfig: config.userPoolConfig,
serviceRoleArn: config.serviceRole,
// TODO verify dataSources structure
dataSources,
mappingTemplatesLocation,
mappingTemplates,
};
};