Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function makeSearchableXSortInputObject(obj: ObjectTypeDefinitionNode): InputObjectTypeDefinitionNode {
const name = graphqlName(`Searchable${obj.name.value}SortInput`);
return {
kind: Kind.INPUT_OBJECT_TYPE_DEFINITION,
// TODO: Service does not support new style descriptions so wait.
// description: {
// kind: 'StringValue',
// value: `Input type for ${obj.name.value} delete mutations`
// },
name: {
kind: 'Name',
value: name,
},
fields: [
{
kind: Kind.INPUT_VALUE_DEFINITION,
name: { kind: 'Name', value: 'field' },
type: makeNamedType(`Searchable${obj.name.value}SortableFields`),
private protectOnDeleteSubscription(ctx: TransformerContext, rules: AuthRule[],
parent: ObjectTypeDefinitionNode, level: string, onDelete?: string[]) {
if (onDelete) {
onDelete.forEach( (name) => {
this.addSubscriptionResolvers(ctx, rules, parent, level, name)
})
} else {
this.addSubscriptionResolvers(ctx, rules, parent,
level, graphqlName(ON_DELETE_FIELD + toUpper(parent.name.value)))
}
}
private makeListRelationalResolver(type: string, queryTypeName: string = 'Query') {
const fieldName = graphqlName('list' + plurality(toUpper(type)));
const sql = `SELECT * FROM ${type}`;
const reqFileName = `${queryTypeName}.${fieldName}.req.vtl`;
const resFileName = `${queryTypeName}.${fieldName}.res.vtl`;
const reqTemplate = print(
RelationalDBMappingTemplate.rdsQuery({
statements: list([str(sql)]),
})
);
const resTemplate = print(ref('utils.toJson($utils.rds.toJsonObject($ctx.result)[0])'));
fs.writeFileSync(`${this.resolverFilePath}/${reqFileName}`, reqTemplate, 'utf8');
fs.writeFileSync(`${this.resolverFilePath}/${resFileName}`, resTemplate, 'utf8');
let resolver = new AppSync.Resolver({
ApiId: Fn.Ref(ResourceConstants.PARAMETERS.AppSyncApiId),
DataSourceName: Fn.GetAtt(ResourceConstants.RESOURCES.RelationalDatabaseDataSource, 'Name'),
ResourceFactory.prototype.makeListResolver = function (type, nameOverride) {
var fieldName = nameOverride ? nameOverride : graphql_transformer_common_1.graphqlName('list' + graphql_transformer_common_1.toUpper(type));
var defaultPageLimit = 10;
return new appSync_1.default.Resolver({
ApiId: cloudform_1.Fn.GetAtt(graphql_transformer_common_1.ResourceConstants.RESOURCES.GraphQLAPILogicalID, 'ApiId'),
DataSourceName: cloudform_1.Fn.GetAtt(graphql_transformer_common_1.ModelResourceIDs.ModelTableDataSourceID(type), 'Name'),
FieldName: fieldName,
TypeName: 'Query',
RequestMappingTemplate: graphql_mapping_template_1.print(graphql_mapping_template_1.compoundExpression([
graphql_mapping_template_1.set(graphql_mapping_template_1.ref('limit'), graphql_mapping_template_1.ref("util.defaultIfNull($context.args.limit, " + defaultPageLimit + ")")),
graphql_mapping_template_1.DynamoDBMappingTemplate.listItem({
filter: graphql_mapping_template_1.ifElse(graphql_mapping_template_1.ref('context.args.filter'), graphql_mapping_template_1.ref('util.transform.toDynamoDBFilterExpression($ctx.args.filter)'), graphql_mapping_template_1.nul()),
limit: graphql_mapping_template_1.ref('limit'),
nextToken: graphql_mapping_template_1.ifElse(graphql_mapping_template_1.ref('context.args.nextToken'), graphql_mapping_template_1.str('$context.args.nextToken'), graphql_mapping_template_1.nul())
})
])),
ResponseMappingTemplate: graphql_mapping_template_1.print(graphql_mapping_template_1.raw('$util.toJson($ctx.result)'))
}).dependsOn(graphql_transformer_common_1.ResourceConstants.RESOURCES.GraphQLSchemaLogicalID);
public makeUpdateResolver({ type, nameOverride, syncConfig, mutationTypeName = 'Mutation' }: MutationResolverInput) {
const fieldName = nameOverride ? nameOverride : graphqlName(`update` + toUpper(type));
const isSyncEnabled = syncConfig ? true : false;
return new AppSync.Resolver({
ApiId: Fn.GetAtt(ResourceConstants.RESOURCES.GraphQLAPILogicalID, 'ApiId'),
DataSourceName: Fn.GetAtt(ModelResourceIDs.ModelTableDataSourceID(type), 'Name'),
FieldName: fieldName,
TypeName: mutationTypeName,
RequestMappingTemplate: print(
compoundExpression([
ifElse(
raw(`$${ResourceConstants.SNIPPETS.AuthCondition} && $${ResourceConstants.SNIPPETS.AuthCondition}.expression != ""`),
compoundExpression([
set(ref('condition'), ref(ResourceConstants.SNIPPETS.AuthCondition)),
ifElse(
ref(ResourceConstants.SNIPPETS.ModelObjectKey),
forEach(ref('entry'), ref(`${ResourceConstants.SNIPPETS.ModelObjectKey}.entrySet()`), [
qref('$condition.put("expression", "$condition.expression AND attribute_exists(#keyCondition$velocityCount)")'),
private makeDeleteRelationalResolver(type: string, mutationTypeName: string = 'Mutation') {
const fieldName = graphqlName('delete' + toUpper(type));
let selectSql;
if (this.typePrimaryKeyTypeMap.get(type).includes('String')) {
selectSql = `SELECT * FROM ${type} WHERE ${this.typePrimaryKeyMap.get(type)}=\'$ctx.args.${this.typePrimaryKeyMap.get(type)}\'`;
} else {
selectSql = `SELECT * FROM ${type} WHERE ${this.typePrimaryKeyMap.get(type)}=$ctx.args.${this.typePrimaryKeyMap.get(type)}`;
}
const deleteSql = `DELETE FROM ${type} WHERE ${this.typePrimaryKeyMap.get(type)}=$ctx.args.${this.typePrimaryKeyMap.get(type)}`;
const reqFileName = `${mutationTypeName}.${fieldName}.req.vtl`;
const resFileName = `${mutationTypeName}.${fieldName}.res.vtl`;
const reqTemplate = print(
compoundExpression([
RelationalDBMappingTemplate.rdsQuery({
statements: list([str(selectSql), str(deleteSql)]),
}),
])
);
public makeGetResolver(type: string, nameOverride?: string, isSyncEnabled: boolean = false, queryTypeName: string = 'Query') {
const fieldName = nameOverride ? nameOverride : graphqlName('get' + toUpper(type));
return new AppSync.Resolver({
ApiId: Fn.GetAtt(ResourceConstants.RESOURCES.GraphQLAPILogicalID, 'ApiId'),
DataSourceName: Fn.GetAtt(ModelResourceIDs.ModelTableDataSourceID(type), 'Name'),
FieldName: fieldName,
TypeName: queryTypeName,
RequestMappingTemplate: print(
DynamoDBMappingTemplate.getItem({
key: ifElse(
ref(ResourceConstants.SNIPPETS.ModelObjectKey),
raw(`$util.toJson(\$${ResourceConstants.SNIPPETS.ModelObjectKey})`),
obj({
id: ref('util.dynamodb.toDynamoDBJson($ctx.args.id)'),
}),
true
),
isSyncEnabled,
const dynamoDBFriendlySortKeyName = toCamelCase(rangeKeyFields.map(f => graphqlName(f)));
const condensedSortKeyValue = condenseRangeKey(
private protectOnCreateSubscription(ctx: TransformerContext, rules: AuthRule[],
parent: ObjectTypeDefinitionNode, level: string, onCreate?: string[]) {
if (onCreate) {
onCreate.forEach( (name) => {
this.addSubscriptionResolvers(ctx, rules, parent, level, name)
})
} else {
this.addSubscriptionResolvers(ctx, rules, parent,
level, graphqlName(ON_CREATE_FIELD + toUpper(parent.name.value)))
}
}
private makeGetRelationalResolver(type: string, queryTypeName: string = 'Query') {
const fieldName = graphqlName('get' + toUpper(type));
let sql;
if (this.typePrimaryKeyTypeMap.get(type).includes('String')) {
sql = `SELECT * FROM ${type} WHERE ${this.typePrimaryKeyMap.get(type)}=\'$ctx.args.${this.typePrimaryKeyMap.get(type)}\'`;
} else {
sql = `SELECT * FROM ${type} WHERE ${this.typePrimaryKeyMap.get(type)}=$ctx.args.${this.typePrimaryKeyMap.get(type)}`;
}
const reqFileName = `${queryTypeName}.${fieldName}.req.vtl`;
const resFileName = `${queryTypeName}.${fieldName}.res.vtl`;
const reqTemplate = print(
compoundExpression([
RelationalDBMappingTemplate.rdsQuery({
statements: list([str(sql)]),
}),
])
);