Skip to content

Commit

Permalink
Merge pull request #169 from ZY-Ang/master
Browse files Browse the repository at this point in the history
Update multiple APIs support
  • Loading branch information
sid88in committed Nov 12, 2018
2 parents 2824aa2 + 42a7869 commit a3adc76
Show file tree
Hide file tree
Showing 6 changed files with 170 additions and 69 deletions.
31 changes: 31 additions & 0 deletions README.md
Expand Up @@ -151,6 +151,37 @@ custom:

> Be sure to replace all variables that have been commented out, or have an empty value.
#### Multiple APIs

If you have multiple APIs and do not want to split this up into another CloudFormation stack, simply change the `appSync` configuration property from an object into an array of objects:

```yaml
custom:
appSync:
- name: private-appsync-endpoint
schema: AppSync/schema.graphql # or something like AppSync/private/schema.graphql
authenticationType: OPENID_CONNECT
openIdConnectConfig:
...
serviceRole: AuthenticatedAppSyncServiceRole
dataSources:
...
mappingTemplatesLocation: ...
mappingTemplates:
...
- name: public-appsync-endpoint
schema: AppSync/schema.graphql # or something like AppSync/public/schema.graphql
authenticationType: NONE # or API_KEY, you get the idea
serviceRole: PublicAppSyncServiceRole
dataSources:
...
mappingTemplatesLocation: ...
mappingTemplates:
...
```

> Note: CloudFormation stack outputs and logical IDs will be changed from the defaults to api name prefixed. This allows you to differentiate the APIs on your stack if you want to work with multiple APIs.
## ▶️ Usage

### `serverless deploy`
Expand Down
1 change: 1 addition & 0 deletions __snapshots__/get-config.test.js.snap
Expand Up @@ -19,6 +19,7 @@ Object {
"type": "AMAZON_DYNAMODB",
},
],
"isSingleConfig": true,
"logConfig": undefined,
"mappingTemplates": Array [],
"mappingTemplatesLocation": "mapping-templates",
Expand Down
14 changes: 13 additions & 1 deletion get-config.js
Expand Up @@ -9,7 +9,7 @@ const objectToArrayWithNameProp = pipe(
values,
);

module.exports = (config, provider, servicePath) => {
const getConfig = (config, provider, servicePath) => {
if (
!(
config.authenticationType === 'API_KEY' ||
Expand Down Expand Up @@ -65,3 +65,15 @@ module.exports = (config, provider, servicePath) => {
substitutions: config.substitutions || {},
};
};

module.exports = (config, provider, servicePath) => {
if (!config) {
return [];
} else if (config.constructor === Array) {
return config.map(apiConfig => getConfig(apiConfig, provider, servicePath));
} else {
const singleConfig = getConfig(config, provider, servicePath);
singleConfig.isSingleConfig = true;
return [singleConfig];
}
};
2 changes: 1 addition & 1 deletion get-config.test.js
Expand Up @@ -34,5 +34,5 @@ test('returns valid config', () => {
},
{ region: 'us-east-1' },
servicePath,
)).toMatchSnapshot();
)[0]).toMatchSnapshot();
});

0 comments on commit a3adc76

Please sign in to comment.