Skip to content
This repository was archived by the owner on Mar 24, 2020. It is now read-only.
Open
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
10 changes: 9 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,15 @@ class ServerlessAmplifyPlugin {
const resource = resources.find(r => r.ResourceType === 'AWS::AppSync::GraphQLApi');
if (resource) {
const schemaFile = this.getTemporarySchemaFile(resource);
graphqlGenerator(schemaFile, fileDetails.filename, { language: 'graphql' });
const fileType = path.extname(fileDetails.filename).substr(1);
const language = {
ts: 'typescript',
js: 'javascript',
swift: 'swift',
scala: 'scala',
graphql: 'graphql',
}[fileType];
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
}[fileType];
}[fileType];
if(language == null) {
throw new Error(`File type '${fileType}' not supported for GraphQL operations`);
}

graphqlGenerator(schemaFile, fileDetails.filename, { language });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not provide any error handling when the language is not one of those listed. In that case, language will be explicitly undefined and that will cause horrible errors. Please add error handling appropriate to the situation.

} else {
throw new Error(`No GraphQL API found - cannot write ${fileDetails.filename} file`);
}
Expand Down