Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const allResourceIds = Object.keys(rootStack.Resources).filter((k: string) => {
const resource = rootStack.Resources[k];
return resourceTypesToDependOn[resource.Type];
});
// Looping through the parameters defined by the transform (aka. rootStack)
const parametersKeys = Object.keys(rootStack.Parameters);
const customStackParams = parametersKeys.reduce(
(acc: any, k: string) => ({
...acc,
[k]: Fn.Ref(k),
}),
{}
);
// customStackParams is a map that will be passed as the "parameters" value
// to any nested stacks.
customStackParams[ResourceConstants.PARAMETERS.AppSyncApiId] = Fn.GetAtt(ResourceConstants.RESOURCES.GraphQLAPILogicalID, 'ApiId');
// Load the root stack's parameters as we will update them with the Child Stack's parameters
// if they are not already present in the root stack.
let updatedParameters = rootStack.Parameters;
for (const userStack of Object.keys(userStacks)) {
if (transformOutput.stacks[userStack]) {
throw new Error(`You cannot provide a stack named ${userStack} as it \
will be overwritten by a stack generated by the GraphQL Transform.`);
}
const userDefinedStack = userConfig.stacks[userStack];
/**
* First loop through the parameters in the user defined stack and see
* if there are any Parameters that are present in the child but not the
* root stack - if so, add it to the root stack.
export function syncLambdaIAMRole({ name, region }: { name: string; region?: string }) {
return new IAM.Role({
RoleName: Fn.If(
ResourceConstants.CONDITIONS.HasEnvironmentParameter,
Fn.Join('-', [
name.slice(0, 26), // max of 64. 64-10-26-28 = 0
Fn.GetAtt(ResourceConstants.RESOURCES.GraphQLAPILogicalID, 'ApiId'), // 26
Fn.Ref(ResourceConstants.PARAMETERS.Env), // 10
]),
Fn.Join('-', [
// tslint:disable-next-line: no-magic-numbers
name.slice(0, 37), // max of 64. 64-26-38 = 0
Fn.GetAtt(ResourceConstants.RESOURCES.GraphQLAPILogicalID, 'ApiId'), // 26
])
),
AssumeRolePolicyDocument: {
Version: '2012-10-17',
Statement: [
{
Effect: 'Allow',
Principal: {
Service: 'appsync.amazonaws.com',
},
Action: 'sts:AssumeRole',
},
],
},
Policies: [
{
role = (name: string, region: string): any => {
return new IAM.Role({
RoleName: Fn.If(
ResourceConstants.CONDITIONS.HasEnvironmentParameter,
Fn.Join('-', [
FunctionResourceIDs.FunctionIAMRoleName(name, true), // max of 64. 64-10-26-28 = 0
Fn.GetAtt(ResourceConstants.RESOURCES.GraphQLAPILogicalID, 'ApiId'), // 26
Fn.Ref(ResourceConstants.PARAMETERS.Env), // 10
]),
Fn.Join('-', [
FunctionResourceIDs.FunctionIAMRoleName(name, false), // max of 64. 64-26-38 = 0
Fn.GetAtt(ResourceConstants.RESOURCES.GraphQLAPILogicalID, 'ApiId'), // 26
])
),
AssumeRolePolicyDocument: {
Version: '2012-10-17',
Statement: [
{
Effect: 'Allow',
Principal: {
Service: 'appsync.amazonaws.com',
},
Action: 'sts:AssumeRole',
public makeHttpDataSource(baseURL: string) {
return new AppSync.DataSource({
ApiId: Fn.GetAtt(ResourceConstants.RESOURCES.GraphQLAPILogicalID, 'ApiId'),
Name: HttpResourceIDs.HttpDataSourceID(baseURL),
Type: 'HTTP',
HttpConfig: {
Endpoint: this.replaceEnv(baseURL),
},
});
}
DataSourceName: Fn.GetAtt(ModelResourceIDs.ModelTableDataSourceID(relatedType.name.value), 'Name'),
FieldName: field,
TypeName: type,
RequestMappingTemplate: print(
compoundExpression([
...setup,
queryObj
])
),
ResponseMappingTemplate: print(
compoundExpression([
iff(raw('!$result'), set(ref('result'), ref('ctx.result'))),
raw('$util.toJson($result)')
])
)
}).dependsOn(ResourceConstants.RESOURCES.GraphQLSchemaLogicalID)
}
private domainArn() {
return Fn.GetAtt(
ResourceConstants.RESOURCES.ElasticsearchDomainLogicalID,
"DomainArn"
)
}
public makeApiKeyOutput(): any {
return {
Description: "Your GraphQL API key. Provide via 'x-api-key' header.",
Value: Fn.GetAtt(ResourceConstants.RESOURCES.APIKeyLogicalID, 'ApiKey'),
Export: {
Name: Fn.Join(':', [Refs.StackName, "GraphQLApiKey"])
},
Condition: ResourceConstants.CONDITIONS.ShouldCreateAPIKey
};
}
SyncResourceIDs.syncTableName,
Fn.GetAtt(ResourceConstants.RESOURCES.GraphQLAPILogicalID, 'ApiId'),
])
),
}),
Fn.Sub('arn:aws:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${tablename}/*', {
tablename: Fn.If(
ResourceConstants.CONDITIONS.HasEnvironmentParameter,
Fn.Join('-', [
SyncResourceIDs.syncTableName,
Fn.GetAtt(ResourceConstants.RESOURCES.GraphQLAPILogicalID, 'ApiId'),
Fn.Ref(ResourceConstants.PARAMETERS.Env),
]),
Fn.Join('-', [
SyncResourceIDs.syncTableName,
Fn.GetAtt(ResourceConstants.RESOURCES.GraphQLAPILogicalID, 'ApiId'),
])
),
}),
]
: []),
],
},
],
},
}),
...(syncConfig && SyncUtils.isLambdaSyncConfig(syncConfig)
? [SyncUtils.createSyncLambdaIAMPolicy(syncConfig.LambdaConflictHandler)]
: []),
],
});
}
public makeApiKeyOutput(): any {
return {
Description: "Your GraphQL API key. Provide via 'x-api-key' header.",
Value: Fn.GetAtt(ResourceConstants.RESOURCES.APIKeyLogicalID, 'ApiKey'),
Export: {
Name: Fn.Join(':', [Refs.StackName, 'GraphQLApiKey']),
},
Condition: ResourceConstants.CONDITIONS.ShouldCreateAPIKey,
};
}
private buildAndSetSchema(ctx: TransformerContext): string {
const SDL = this.buildSchema(ctx);
const schemaResource = this.schemaResourceUtil.makeAppSyncSchema();
ctx.setResource(ResourceConstants.RESOURCES.GraphQLSchemaLogicalID, schemaResource);
return SDL;
}