Skip to content

Commit

Permalink
fix(appsync): revert to allow resolver creation from data source (#12973
Browse files Browse the repository at this point in the history
)

* Revert to old behavior of allowing a data source to create a resolver as UNIT resolvers stem from data sources.
* Maintaining new behavior of having `GraphqlApi` create resolvers as PIPELINE resolvers stem from the `GraphqlApi` itself

Fixes #12635
Fixes #11522

----

*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 Feb 22, 2021
1 parent 6aac3b6 commit d35f032
Show file tree
Hide file tree
Showing 6 changed files with 240 additions and 237 deletions.
6 changes: 5 additions & 1 deletion packages/@aws-cdk/aws-appsync/lib/data-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,11 @@ export abstract class BaseDataSource extends CoreConstruct {
* creates a new resolver for this datasource and API using the given properties
*/
public createResolver(props: BaseResolverProps): Resolver {
return this.api.createResolver({ dataSource: this, ...props });
return new Resolver(this, `${props.typeName}${props.fieldName}Resolver`, {
api: this.api,
dataSource: this,
...props,
});
}

/**
Expand Down
3 changes: 1 addition & 2 deletions packages/@aws-cdk/aws-appsync/test/appsync.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ test('appsync should error when creating pipeline resolver with data source', ()

// THEN
expect(() => {
api.createResolver({
dataSource: ds,
ds.createResolver({
typeName: 'test',
fieldName: 'test2',
pipelineConfig: [test1, test2],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@
}
}
},
"ApiQuerygetTestsResolver025B8E0A": {
"ApidsQuerygetTestsResolver952F49EE": {
"Type": "AWS::AppSync::Resolver",
"Properties": {
"ApiId": {
Expand All @@ -152,7 +152,7 @@
"Apids0DB53FEA"
]
},
"ApiMutationaddTestResolver7A08AE91": {
"ApidsMutationaddTestResolverBCF0400B": {
"Type": "AWS::AppSync::Resolver",
"Properties": {
"ApiId": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@
}
}
},
"ApiQuerygetTestsResolver025B8E0A": {
"ApitestDataSourceQuerygetTestsResolverA3BBB672": {
"Type": "AWS::AppSync::Resolver",
"Properties": {
"ApiId": {
Expand All @@ -142,7 +142,7 @@
"ApitestDataSource96AE54D5"
]
},
"ApiMutationaddTestResolver7A08AE91": {
"ApitestDataSourceMutationaddTestResolver36203D6B": {
"Type": "AWS::AppSync::Resolver",
"Properties": {
"ApiId": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@
}
}
},
"ApiQuerygetTestResolver4C1F8B0C": {
"ApidsQuerygetTestResolverCCED7EC2": {
"Type": "AWS::AppSync::Resolver",
"Properties": {
"ApiId": {
Expand All @@ -171,7 +171,7 @@
"ApiSchema510EECD7"
]
},
"ApiQuerygetTestsResolver025B8E0A": {
"ApidsQuerygetTestsResolver952F49EE": {
"Type": "AWS::AppSync::Resolver",
"Properties": {
"ApiId": {
Expand All @@ -192,7 +192,7 @@
"ApiSchema510EECD7"
]
},
"ApiMutationaddTestResolver7A08AE91": {
"ApidsMutationaddTestResolverBCF0400B": {
"Type": "AWS::AppSync::Resolver",
"Properties": {
"ApiId": {
Expand Down Expand Up @@ -400,14 +400,12 @@
]
}
},
"Handler": "iam-query.handler",
"Role": {
"Fn::GetAtt": [
"LambdaIAM687B49AF",
"Arn"
]
},
"Runtime": "nodejs12.x",
"Environment": {
"Variables": {
"APPSYNC_ENDPOINT": {
Expand All @@ -417,7 +415,9 @@
]
}
}
}
},
"Handler": "iam-query.handler",
"Runtime": "nodejs12.x"
},
"DependsOn": [
"LambdaIAMDefaultPolicy96DEA124",
Expand Down Expand Up @@ -496,14 +496,12 @@
]
}
},
"Handler": "iam-query.handler",
"Role": {
"Fn::GetAtt": [
"testFailServiceRole9FF22F85",
"Arn"
]
},
"Runtime": "nodejs12.x",
"Environment": {
"Variables": {
"APPSYNC_ENDPOINT": {
Expand All @@ -513,7 +511,9 @@
]
}
}
}
},
"Handler": "iam-query.handler",
"Runtime": "nodejs12.x"
},
"DependsOn": [
"testFailServiceRole9FF22F85"
Expand Down
Loading

0 comments on commit d35f032

Please sign in to comment.