Skip to content

Commit 30bec29

Browse files
authored
Added support for multiple graphql schemas. (#34)
* Added support for multiple graphql schemas. * Code style fixes.
1 parent 20bcf95 commit 30bec29

File tree

3 files changed

+321
-9
lines changed

3 files changed

+321
-9
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
"cfn-resolver-lib": "^1.1.6",
2727
"dataloader": "^2.0.0",
2828
"extend": "^3.0.2",
29-
"lodash": "^4.17.15"
29+
"lodash": "^4.17.15",
30+
"merge-graphql-schemas": "^1.5.8"
3031
},
3132
"devDependencies": {
3233
"@babel/cli": "^7.8.4",

src/getAppSyncConfig.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { invoke } from 'amplify-nodejs-function-runtime-provider/lib/utils/invok
55
import fs from 'fs';
66
import { forEach } from 'lodash';
77
import path from 'path';
8+
import { mergeTypes } from 'merge-graphql-schemas';
89

910
export default function getAppSyncConfig(context, appSyncConfig) {
1011
// Flattening params
@@ -186,9 +187,19 @@ export default function getAppSyncConfig(context, appSyncConfig) {
186187
}, []);
187188
};
188189

190+
// Load the schema. If multiple provided, merge them
191+
const schemaPaths = Array.isArray(cfg.schema) ? cfg.schema : [cfg.schema || 'schema.graphql'];
192+
const schemas = schemaPaths.map(
193+
(schemaPath) => getFileMap(context.serverless.config.servicePath, schemaPath),
194+
);
195+
const schema = {
196+
path: schemas.find((s) => s.path),
197+
content: mergeTypes(schemas.map((s) => s.content)),
198+
};
199+
189200
return {
190201
appSync: makeAppSync(cfg),
191-
schema: getFileMap(context.serverless.config.servicePath, cfg.schema || 'schema.graphql'),
202+
schema,
192203
resolvers: cfg.mappingTemplates.map(makeResolver),
193204
dataSources: cfg.dataSources.map(makeDataSource).filter((v) => v !== null),
194205
functions: cfg.functionConfigurations.map(makeFunctionConfiguration),

0 commit comments

Comments
 (0)