@@ -5,6 +5,7 @@ import fs from 'fs';
55import { forEach , isNil , first } from 'lodash' ;
66import path from 'path' ;
77import { mergeTypes } from 'merge-graphql-schemas' ;
8+ import * as globby from 'globby' ;
89import directLambdaRequest from './templates/direct-lambda.request.vtl' ;
910import directLambdaResponse from './templates/direct-lambda.response.vtl' ;
1011
@@ -35,9 +36,26 @@ export default function getAppSyncConfig(context, appSyncConfig) {
3536 } ) ;
3637 } ;
3738
39+ const toAbsolutePath = ( basePath , filePath ) =>
40+ path . isAbsolute ( filePath ) ? filePath : path . join ( basePath , filePath ) ;
41+
42+ const globFilePaths = ( basePath , filePaths ) => {
43+ return filePaths
44+ . map ( ( filePath ) => {
45+ const paths = globby . sync ( toAbsolutePath ( basePath , filePath ) ) ;
46+ if ( path . isAbsolute ( filePath ) ) {
47+ return paths ;
48+ } else {
49+ // For backward compatibility with FileMap, revert to relative path
50+ return paths . map ( ( p ) => path . relative ( basePath , p ) ) ;
51+ }
52+ } )
53+ . flat ( ) ;
54+ } ;
55+
3856 const getFileMap = ( basePath , filePath ) => ( {
3957 path : filePath ,
40- content : fs . readFileSync ( path . join ( basePath , filePath ) , {
58+ content : fs . readFileSync ( toAbsolutePath ( basePath , filePath ) , {
4159 encoding : 'utf8' ,
4260 } ) ,
4361 } ) ;
@@ -208,8 +226,9 @@ export default function getAppSyncConfig(context, appSyncConfig) {
208226 const schemaPaths = Array . isArray ( cfg . schema )
209227 ? cfg . schema
210228 : [ cfg . schema || 'schema.graphql' ] ;
211- const schemas = schemaPaths . map ( ( schemaPath ) =>
212- getFileMap ( context . serverless . config . servicePath , schemaPath ) ,
229+ const basePath = context . serverless . config . servicePath ;
230+ const schemas = globFilePaths ( basePath , schemaPaths ) . map ( ( schemaPath ) =>
231+ getFileMap ( basePath , schemaPath ) ,
213232 ) ;
214233 const schema = {
215234 path : first ( schemas ) . path ,
0 commit comments