Skip to content

Commit dac9bb3

Browse files
authored
fix(appsync): resolver unable to set pipelineConfig (#9093)
**[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*
1 parent d3e5533 commit dac9bb3

File tree

2 files changed

+84
-7
lines changed

2 files changed

+84
-7
lines changed

packages/@aws-cdk/aws-appsync/lib/resolver.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import { Construct, IResolvable } from '@aws-cdk/core';
1+
import { Construct } from '@aws-cdk/core';
22
import { CfnResolver } from './appsync.generated';
33
import { BaseDataSource } from './data-source';
44
import { GraphQLApi } from './graphqlapi';
55
import { MappingTemplate } from './mapping-template';
6+
67
/**
78
* Basic properties for an AppSync resolver
89
*/
@@ -18,9 +19,10 @@ export interface BaseResolverProps {
1819
/**
1920
* configuration of the pipeline resolver
2021
*
21-
* @default - create a UNIT resolver
22+
* @default - no pipeline resolver configuration
23+
* An empty array | undefined sets resolver to be of kind, unit
2224
*/
23-
readonly pipelineConfig?: CfnResolver.PipelineConfigProperty | IResolvable;
25+
readonly pipelineConfig?: string[];
2426
/**
2527
* The request mapping template for this resolver
2628
*
@@ -65,12 +67,15 @@ export class Resolver extends Construct {
6567
constructor(scope: Construct, id: string, props: ResolverProps) {
6668
super(scope, id);
6769

70+
const pipelineConfig = props.pipelineConfig && props.pipelineConfig.length ? { functions: props.pipelineConfig } : undefined;
71+
6872
this.resolver = new CfnResolver(this, 'Resource', {
6973
apiId: props.api.apiId,
7074
typeName: props.typeName,
7175
fieldName: props.fieldName,
7276
dataSourceName: props.dataSource ? props.dataSource.name : undefined,
73-
kind: props.pipelineConfig ? 'PIPELINE' : 'UNIT',
77+
kind: pipelineConfig ? 'PIPELINE' : 'UNIT',
78+
pipelineConfig: pipelineConfig,
7479
requestMappingTemplate: props.requestMappingTemplate ? props.requestMappingTemplate.renderTemplate() : undefined,
7580
responseMappingTemplate: props.responseMappingTemplate ? props.responseMappingTemplate.renderTemplate() : undefined,
7681
});

packages/@aws-cdk/aws-appsync/test/appsync.test.ts

Lines changed: 75 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import * as cdk from '@aws-cdk/core';
44
import * as appsync from '../lib';
55

66
test('should not throw an Error', () => {
7-
// Given
7+
// GIVEN
88
const stack = new cdk.Stack();
99

10-
// When
10+
// WHEN
1111
const when = () => {
1212
new appsync.GraphQLApi(stack, 'api', {
1313
authorizationConfig: {},
@@ -16,6 +16,78 @@ test('should not throw an Error', () => {
1616
});
1717
};
1818

19-
// Then
19+
// THEN
2020
expect(when).not.toThrow();
2121
});
22+
23+
test('appsync should configure pipeline when pipelineConfig has contents', () => {
24+
// GIVEN
25+
const stack = new cdk.Stack();
26+
27+
// WHEN
28+
const api = new appsync.GraphQLApi(stack, 'api', {
29+
authorizationConfig: {},
30+
name: 'api',
31+
schemaDefinitionFile: path.join(__dirname, 'appsync.test.graphql'),
32+
});
33+
34+
new appsync.Resolver(stack, 'resolver', {
35+
api: api,
36+
typeName: 'test',
37+
fieldName: 'test2',
38+
pipelineConfig: ['test', 'test'],
39+
});
40+
41+
// THEN
42+
expect(stack).toHaveResourceLike('AWS::AppSync::Resolver', {
43+
Kind: 'PIPELINE',
44+
PipelineConfig: { Functions: [ 'test', 'test' ] },
45+
});
46+
});
47+
48+
test('appsync should configure resolver as unit when pipelineConfig is empty', () => {
49+
// GIVEN
50+
const stack = new cdk.Stack();
51+
52+
// WHEN
53+
const api = new appsync.GraphQLApi(stack, 'api', {
54+
authorizationConfig: {},
55+
name: 'api',
56+
schemaDefinitionFile: path.join(__dirname, 'appsync.test.graphql'),
57+
});
58+
59+
new appsync.Resolver(stack, 'resolver', {
60+
api: api,
61+
typeName: 'test',
62+
fieldName: 'test2',
63+
});
64+
65+
// THEN
66+
expect(stack).toHaveResourceLike('AWS::AppSync::Resolver', {
67+
Kind: 'UNIT',
68+
});
69+
});
70+
71+
test('appsync should configure resolver as unit when pipelineConfig is empty array', () => {
72+
// GIVEN
73+
const stack = new cdk.Stack();
74+
75+
// WHEN
76+
const api = new appsync.GraphQLApi(stack, 'api', {
77+
authorizationConfig: {},
78+
name: 'api',
79+
schemaDefinitionFile: path.join(__dirname, 'appsync.test.graphql'),
80+
});
81+
82+
new appsync.Resolver(stack, 'resolver', {
83+
api: api,
84+
typeName: 'test',
85+
fieldName: 'test2',
86+
pipelineConfig: [],
87+
});
88+
89+
// THEN
90+
expect(stack).toHaveResourceLike('AWS::AppSync::Resolver', {
91+
Kind: 'UNIT',
92+
});
93+
});

0 commit comments

Comments
 (0)