Skip to content

Commit

Permalink
fix(appsync): resolver unable to set pipelineConfig (#9093)
Browse files Browse the repository at this point in the history
**[ISSUE]**
`pipelineConfig` was be labeled as `undefined` while using the `Resolver` class instead of `createResolver`. Also, no way to set `kind` parameter for resolvers, so implemented that as well.

**[APPROACH]**
Created a property that takes `pipelineConfig` for `AppSync` functions. 

**[NOTE]**
`pipelineConfig` takes a string array for the name of `AppSync Functions` not `Lambda Functions`

Fixes #6923  

BREAKING CHANGE: `pipelineConfig` is now an array of `string` instead of `CfnResolver.PipelineConfigProperty` for usability.
- **appsync**: `pipelineConfig` parameter takes in `string []`

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
BryanPan342 authored Jul 24, 2020
1 parent d3e5533 commit dac9bb3
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 7 deletions.
13 changes: 9 additions & 4 deletions packages/@aws-cdk/aws-appsync/lib/resolver.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { Construct, IResolvable } from '@aws-cdk/core';
import { Construct } from '@aws-cdk/core';
import { CfnResolver } from './appsync.generated';
import { BaseDataSource } from './data-source';
import { GraphQLApi } from './graphqlapi';
import { MappingTemplate } from './mapping-template';

/**
* Basic properties for an AppSync resolver
*/
Expand All @@ -18,9 +19,10 @@ export interface BaseResolverProps {
/**
* configuration of the pipeline resolver
*
* @default - create a UNIT resolver
* @default - no pipeline resolver configuration
* An empty array | undefined sets resolver to be of kind, unit
*/
readonly pipelineConfig?: CfnResolver.PipelineConfigProperty | IResolvable;
readonly pipelineConfig?: string[];
/**
* The request mapping template for this resolver
*
Expand Down Expand Up @@ -65,12 +67,15 @@ export class Resolver extends Construct {
constructor(scope: Construct, id: string, props: ResolverProps) {
super(scope, id);

const pipelineConfig = props.pipelineConfig && props.pipelineConfig.length ? { functions: props.pipelineConfig } : undefined;

this.resolver = new CfnResolver(this, 'Resource', {
apiId: props.api.apiId,
typeName: props.typeName,
fieldName: props.fieldName,
dataSourceName: props.dataSource ? props.dataSource.name : undefined,
kind: props.pipelineConfig ? 'PIPELINE' : 'UNIT',
kind: pipelineConfig ? 'PIPELINE' : 'UNIT',
pipelineConfig: pipelineConfig,
requestMappingTemplate: props.requestMappingTemplate ? props.requestMappingTemplate.renderTemplate() : undefined,
responseMappingTemplate: props.responseMappingTemplate ? props.responseMappingTemplate.renderTemplate() : undefined,
});
Expand Down
78 changes: 75 additions & 3 deletions packages/@aws-cdk/aws-appsync/test/appsync.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import * as cdk from '@aws-cdk/core';
import * as appsync from '../lib';

test('should not throw an Error', () => {
// Given
// GIVEN
const stack = new cdk.Stack();

// When
// WHEN
const when = () => {
new appsync.GraphQLApi(stack, 'api', {
authorizationConfig: {},
Expand All @@ -16,6 +16,78 @@ test('should not throw an Error', () => {
});
};

// Then
// THEN
expect(when).not.toThrow();
});

test('appsync should configure pipeline when pipelineConfig has contents', () => {
// GIVEN
const stack = new cdk.Stack();

// WHEN
const api = new appsync.GraphQLApi(stack, 'api', {
authorizationConfig: {},
name: 'api',
schemaDefinitionFile: path.join(__dirname, 'appsync.test.graphql'),
});

new appsync.Resolver(stack, 'resolver', {
api: api,
typeName: 'test',
fieldName: 'test2',
pipelineConfig: ['test', 'test'],
});

// THEN
expect(stack).toHaveResourceLike('AWS::AppSync::Resolver', {
Kind: 'PIPELINE',
PipelineConfig: { Functions: [ 'test', 'test' ] },
});
});

test('appsync should configure resolver as unit when pipelineConfig is empty', () => {
// GIVEN
const stack = new cdk.Stack();

// WHEN
const api = new appsync.GraphQLApi(stack, 'api', {
authorizationConfig: {},
name: 'api',
schemaDefinitionFile: path.join(__dirname, 'appsync.test.graphql'),
});

new appsync.Resolver(stack, 'resolver', {
api: api,
typeName: 'test',
fieldName: 'test2',
});

// THEN
expect(stack).toHaveResourceLike('AWS::AppSync::Resolver', {
Kind: 'UNIT',
});
});

test('appsync should configure resolver as unit when pipelineConfig is empty array', () => {
// GIVEN
const stack = new cdk.Stack();

// WHEN
const api = new appsync.GraphQLApi(stack, 'api', {
authorizationConfig: {},
name: 'api',
schemaDefinitionFile: path.join(__dirname, 'appsync.test.graphql'),
});

new appsync.Resolver(stack, 'resolver', {
api: api,
typeName: 'test',
fieldName: 'test2',
pipelineConfig: [],
});

// THEN
expect(stack).toHaveResourceLike('AWS::AppSync::Resolver', {
Kind: 'UNIT',
});
});

0 comments on commit dac9bb3

Please sign in to comment.