Skip to content

Commit

Permalink
feat: capability injection for the vNext GraphQL Transformer (#7735)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcvberg committed Jul 27, 2021
1 parent 14d4a36 commit f3eae13
Show file tree
Hide file tree
Showing 13 changed files with 420 additions and 343 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export class FunctionTransformer extends TransformerPluginBase {
const dataSourceId = FunctionResourceIDs.FunctionDataSourceID(config.name, config.region);

if (!createdResources.has(dataSourceId)) {
const dataSource = context.api.addLambdaDataSource(
const dataSource = context.api.host.addLambdaDataSource(
dataSourceId,
lambda.Function.fromFunctionAttributes(stack, `${dataSourceId}Function`, {
functionArn: lambdaArnResource(env, config.name, config.region),
Expand All @@ -84,7 +84,7 @@ export class FunctionTransformer extends TransformerPluginBase {
let func = createdResources.get(functionId);

if (func === undefined) {
func = context.api.addAppSyncFunction(
func = context.api.host.addAppSyncFunction(
functionId,
MappingTemplate.s3MappingTemplateFromString(
printBlock(`Invoke AWS Lambda data source: ${dataSourceId}`)(
Expand Down Expand Up @@ -125,7 +125,7 @@ export class FunctionTransformer extends TransformerPluginBase {
let resolver = createdResources.get(resolverId);

if (resolver === undefined) {
resolver = context.api.addResolver(
resolver = context.api.host.addResolver(
config.resolverTypeName,
config.resolverFieldName,
MappingTemplate.s3MappingTemplateFromString(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,8 @@ export class HttpTransformer extends TransformerPluginBase {
// Create a new data source if necessary.
const dataSourceId = HttpResourceIDs.HttpDataSourceID(directive.origin);

if (context.api.getDataSource(dataSourceId) === undefined) {
context.api.addHttpDataSource(dataSourceId, replaceEnvAndRegion(env, region, directive.origin), {}, stack);
if (context.api.host.getDataSource(dataSourceId) === undefined) {
context.api.host.addHttpDataSource(dataSourceId, replaceEnvAndRegion(env, region, directive.origin), {}, stack);
}

// Create the GraphQL resolver.
Expand Down Expand Up @@ -272,7 +272,7 @@ function createResolver(stack: cdk.Stack, dataSourceId: string, context: Transfo
? MappingTemplate.inlineTemplateFromString(requestTemplateString)
: MappingTemplate.s3MappingTemplateFromString(requestTemplateString, `${config.resolverTypeName}.${config.resolverFieldName}.req.vtl`);

return context.api.addResolver(
return context.api.host.addResolver(
config.resolverTypeName,
config.resolverFieldName,
requestMappingTemplate,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ export class ModelTransformer extends TransformerModelBase implements Transforme
removalPolicy: RemovalPolicy.DESTROY,
});
// Expose a better API to select what stack this belongs to
const dataSource = context.api.addDynamoDbDataSource(
const dataSource = context.api.host.addDynamoDbDataSource(
`${def!.name.value}DS`,
table,
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ export class PredictionsTransformer extends TransformerPluginBase {
const datasourceName = actionToDataSourceMap.get(action) as string;
const functionName = PredictionsResourceIDs.getPredictionFunctionName(action);
const roleAction = actionToRoleAction.get(action);
let datasource = context.api.getDataSource(datasourceName);
let datasource = context.api.host.getDataSource(datasourceName);

if (roleAction && !seenActions.has(action)) {
role.attachInlinePolicy(
Expand Down Expand Up @@ -263,7 +263,7 @@ function createPredictionsDataSource(
case identifyEntities:
case identifyText:
case identifyLabels:
datasource = context.api.addHttpDataSource(
datasource = context.api.host.addHttpDataSource(
'RekognitionDataSource',
cdk.Fn.sub('https://rekognition.${AWS::Region}.amazonaws.com'),
{
Expand All @@ -276,7 +276,7 @@ function createPredictionsDataSource(
);
break;
case translateText:
datasource = context.api.addHttpDataSource(
datasource = context.api.host.addHttpDataSource(
'TranslateDataSource',
cdk.Fn.sub('https://translate.${AWS::Region}.amazonaws.com'),
{
Expand All @@ -290,7 +290,7 @@ function createPredictionsDataSource(
break;
case convertTextToSpeech:
default:
datasource = context.api.addLambdaDataSource(
datasource = context.api.host.addLambdaDataSource(
'LambdaDataSource',
lambda.Function.fromFunctionAttributes(stack, 'LambdaDataSourceFunction', {
functionArn: (lambdaFn as lambda.IFunction)?.functionArn,
Expand Down Expand Up @@ -321,7 +321,7 @@ function createResolver(
substitutions.env = (env as unknown) as string;
}

return context.api.addResolver(
return context.api.host.addResolver(
config.resolverTypeName,
config.resolverFieldName,
MappingTemplate.inlineTemplateFromString(
Expand Down Expand Up @@ -374,7 +374,7 @@ function createPredictionsLambda(context: TransformerContextProvider, stack: cdk

// Update the runtime to Node 14 once the following issue is resolved:
// https://github.com/aws-cloudformation/cloudformation-coverage-roadmap/issues/80#issuecomment-831796699
return context.api.addLambdaFunction(
return context.api.host.addLambdaFunction(
PredictionsResourceIDs.lambdaHandlerName,
`functions/${functionId}.zip`,
PredictionsResourceIDs.lambdaHandlerName,
Expand Down Expand Up @@ -669,7 +669,7 @@ function createActionFunction(context: TransformerContextProvider, stack: cdk.St
break;
}

return context.api.addAppSyncFunction(
return context.api.host.addAppSyncFunction(
`${action}Function`,
MappingTemplate.inlineTemplateFromString(print(actionFunctionResolver.request)),
MappingTemplate.inlineTemplateFromString(print(actionFunctionResolver.response)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const createEsDataSource = (
const { ElasticsearchDataSourceLogicalID } = ResourceConstants.RESOURCES;
assert(region);
const dsEndpoint = 'https://' + domainEndpoint;
return graphqlApiProvider.addElasticSearchDataSource(
return graphqlApiProvider.host.addElasticSearchDataSource(
ElasticsearchDataSourceLogicalID,
region,
dsEndpoint,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const createLambda = (
ES_USE_EXTERNAL_VERSIONING: isProjectUsingDataStore.toString(),
};

return apiGraphql.addLambdaFunction(
return apiGraphql.host.addLambdaFunction(
ElasticsearchStreamingLambdaFunctionLogicalID,
'functions/' + ElasticsearchStreamingLambdaFunctionLogicalID + '.zip',
parameterMap.get(ElasticsearchStreamingLambdaHandlerName)!.valueAsString,
Expand Down

0 comments on commit f3eae13

Please sign in to comment.