Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"cfn-resolver-lib": "^1.1.7",
"dataloader": "^2.0.0",
"fb-watchman": "^2.0.1",
"globby": "^11.0.3",
"jest": "^26.6.3",
"lodash": "^4.17.20",
"merge-graphql-schemas": "^1.5.8"
Expand Down
1 change: 1 addition & 0 deletions src/__tests__/getAppSyncConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ describe('getAppSyncConfig', () => {
const config = {
name: 'myAPI',
authenticationType: 'API_KEY',
schema: '*.graphql',
defaultMappingTemplates: {
request: 'default.request.vtl',
response: 'default.response.vtl',
Expand Down
25 changes: 22 additions & 3 deletions src/getAppSyncConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import fs from 'fs';
import { forEach, isNil, first } from 'lodash';
import path from 'path';
import { mergeTypes } from 'merge-graphql-schemas';
import * as globby from 'globby';
import directLambdaRequest from './templates/direct-lambda.request.vtl';
import directLambdaResponse from './templates/direct-lambda.response.vtl';

Expand Down Expand Up @@ -35,9 +36,26 @@ export default function getAppSyncConfig(context, appSyncConfig) {
});
};

const toAbsolutePath = (basePath, filePath) =>
path.isAbsolute(filePath) ? filePath : path.join(basePath, filePath);

const globFilePaths = (basePath, filePaths) => {
return filePaths
.map((filePath) => {
const paths = globby.sync(toAbsolutePath(basePath, filePath));
if (path.isAbsolute(filePath)) {
return paths;
} else {
// For backward compatibility with FileMap, revert to relative path
return paths.map((p) => path.relative(basePath, p));
}
})
.flat();
};

const getFileMap = (basePath, filePath) => ({
path: filePath,
content: fs.readFileSync(path.join(basePath, filePath), {
content: fs.readFileSync(toAbsolutePath(basePath, filePath), {
encoding: 'utf8',
}),
});
Expand Down Expand Up @@ -208,8 +226,9 @@ export default function getAppSyncConfig(context, appSyncConfig) {
const schemaPaths = Array.isArray(cfg.schema)
? cfg.schema
: [cfg.schema || 'schema.graphql'];
const schemas = schemaPaths.map((schemaPath) =>
getFileMap(context.serverless.config.servicePath, schemaPath),
const basePath = context.serverless.config.servicePath;
const schemas = globFilePaths(basePath, schemaPaths).map((schemaPath) =>
getFileMap(basePath, schemaPath),
);
const schema = {
path: first(schemas).path,
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4030,7 +4030,7 @@ globby@11.0.0:
merge2 "^1.3.0"
slash "^3.0.0"

globby@^11.0.0, globby@^11.0.1:
globby@^11.0.0, globby@^11.0.1, globby@^11.0.3:
version "11.0.3"
resolved "https://registry.yarnpkg.com/globby/-/globby-11.0.3.tgz#9b1f0cb523e171dd1ad8c7b2a9fb4b644b9593cb"
integrity sha512-ffdmosjA807y7+lA1NM0jELARVmYul/715xiILEjo3hBLPTcirgQNnXECn5g3mtR8TOLCVbkfua1Hpen25/Xcg==
Expand Down