Skip to content

Commit

Permalink
Transform stack schema graphql from validation version
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasmichaelwallace committed Jul 13, 2020
1 parent 9558394 commit b2430f7
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
23 changes: 23 additions & 0 deletions __snapshots__/index.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,29 @@ Object {
}
`;

exports[`appsync config Schema is transformed into App Sync compatible syntax 1`] = `
Object {
"GraphQlSchema": Object {
"Properties": Object {
"ApiId": Object {
"Fn::GetAtt": Array [
"GraphQlApi",
"ApiId",
],
},
"Definition": "
type Thing implements One, Another {
hello: ID!
}
enum Method {
DELETE GET }
",
},
"Type": "AWS::AppSync::GraphQLSchema",
},
}
`;

exports[`appsync config appsync cloudwatch log group is created when logs enabled 1`] = `
Object {
"Properties": Object {
Expand Down
21 changes: 21 additions & 0 deletions index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,27 @@ describe('appsync config', () => {
expect(resources.GraphQlApiLogGroup).toMatchSnapshot();
});

test('Schema is transformed into App Sync compatible syntax', () => {
Object.assign(
config,
{
schema: `
"""A valid schema"""
type Thing implements One & Another {
hello: ID!
}
"""A valid enum"""
enum Method {
DELETE # Delete something
GET # Get something
}
`,
},
);
const schema = plugin.getGraphQLSchemaResource(config);
expect(schema).toMatchSnapshot();
});

test('Datasource generates lambdaFunctionArn from functionName', () => {
Object.assign(
config,
Expand Down
6 changes: 5 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -835,11 +835,15 @@ class ServerlessAppsyncPlugin {
getGraphQLSchemaResource(config) {
const logicalIdGraphQLApi = this.getLogicalId(config, RESOURCE_API);
const logicalIdGraphQLSchema = this.getLogicalId(config, RESOURCE_SCHEMA);
const appSyncSafeSchema = config.schema
.replace(/"""[^"]*"""\n/g, '') // appsync does not support the new style descriptions
.replace(/#.*\n/g, '') // appysnc does not support old-style # comments in enums, so remove them all
.replace(/ *& */g, ', ') // appsync does not support the standard '&', but the "unofficial" ',' join for interfaces
return {
[logicalIdGraphQLSchema]: {
Type: 'AWS::AppSync::GraphQLSchema',
Properties: {
Definition: config.schema,
Definition: appSyncSafeSchema,
ApiId: { 'Fn::GetAtt': [logicalIdGraphQLApi, 'ApiId'] },
},
},
Expand Down

0 comments on commit b2430f7

Please sign in to comment.