How to use the cloudform-types/types/appSync/resolver function in cloudform-types

To help you get started, we’ve selected a few cloudform-types examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github aws-amplify / amplify-cli / packages / graphql-relation-transformer / src / ModelRelationTransformer.ts View on Github external
let attributeName = keySchema[0].AttributeName as string

    let keyObj : ObjectNode = obj({
        [attributeName] :
            ref(`util.dynamodb.toDynamoDBJson($util.defaultIfNullOrBlank($ctx.source.${connectionAttributes[0]}, "${NONE_VALUE}"))`)
        })

    if (connectionAttributes[1]) {
        const sortKeyName = keySchema[1].AttributeName as string
        keyObj.attributes.push([
            sortKeyName,
            ref(`util.dynamodb.toDynamoDBJson($util.defaultIfNullOrBlank($ctx.source.${connectionAttributes[1]}, "${NONE_VALUE}"))`)
        ]);
    }

    return new Resolver({
        ApiId: Fn.GetAtt(ResourceConstants.RESOURCES.GraphQLAPILogicalID, 'ApiId'),
        DataSourceName: ModelResourceIDs.ModelTableResourceID(relatedType),
        FieldName: field,
        TypeName: type,
        RequestMappingTemplate: print(
            compoundExpression([
                DynamoDBMappingTemplate.getItem({
                    key: keyObj
                })
            ])
        ),
        ResponseMappingTemplate: print(
            ref('util.toJson($context.result)')
        )
    }).dependsOn([ResourceConstants.RESOURCES.GraphQLSchemaLogicalID, ModelResourceIDs.ModelTableResourceID(relatedType)])
}
github aws-amplify / amplify-cli / packages / graphql-connection-transformer / src / resources.ts View on Github external
rangeKeyFields.map(keyField => `\${ctx.source.${keyField}}`)
            )

            keyObj.attributes.push([
                sortKeyName,
                ref(`util.dynamodb.toDynamoDBJson($util.defaultIfNullOrBlank("${condensedSortKeyValue}", "${NONE_VALUE}"))`)
            ]);
        } else if (connectionAttributes[1]) {
            const sortKeyName = keySchema[1].AttributeName as string
            keyObj.attributes.push([
                sortKeyName,
                ref(`util.dynamodb.toDynamoDBJson($util.defaultIfNullOrBlank($ctx.source.${connectionAttributes[1]}, "${NONE_VALUE}"))`)
            ]);
        }

        return new Resolver({
            ApiId: Fn.GetAtt(ResourceConstants.RESOURCES.GraphQLAPILogicalID, 'ApiId'),
            DataSourceName: Fn.GetAtt(ModelResourceIDs.ModelTableDataSourceID(relatedType), 'Name'),
            FieldName: field,
            TypeName: type,
            RequestMappingTemplate: print(
                compoundExpression([
                    DynamoDBMappingTemplate.getItem({
                        key: keyObj
                    })
                ])
            ),
            ResponseMappingTemplate: print(
                ref('util.toJson($context.result)')
            )
        }).dependsOn(ResourceConstants.RESOURCES.GraphQLSchemaLogicalID)
    }
github aws-amplify / amplify-cli / packages / graphql-relation-transformer / src / ModelRelationTransformer.ts View on Github external
ref('util.transform.toDynamoDBFilterExpression($ctx.args.filter)'),
            nul()
        ),
        limit: ref('limit'),
        nextToken: ifElse(
            ref('context.args.nextToken'),
            str('$context.args.nextToken'),
            nul()
        )
    }
    if (indexName) {
        let indexArg = "index";
        queryArguments[indexArg] = str(indexName);
    }

    return new Resolver({
        ApiId: Fn.GetAtt(ResourceConstants.RESOURCES.GraphQLAPILogicalID, 'ApiId'),
        DataSourceName: ModelResourceIDs.ModelTableResourceID(relatedType.name.value),
        FieldName: field,
        TypeName: type,
        RequestMappingTemplate: print(
            compoundExpression([
                ...setup,
                DynamoDBMappingTemplate.query(queryArguments)
            ])
        ),
        ResponseMappingTemplate: print(
            compoundExpression([
                iff(raw('!$result'), set(ref('result'), ref('ctx.result'))),
                raw('$util.toJson($result)')
            ])
        )
github aws-amplify / amplify-cli / packages / graphql-connection-transformer / src / resources.ts View on Github external
nextToken: ifElse(
                ref('context.args.nextToken'),
                str('$context.args.nextToken'),
                nul()
            ),
            index: indexName ? str(indexName) : undefined
        }

        if (!indexName) {
            const indexArg = 'index'
            delete queryArguments[indexArg];
        }

        const queryObj = DynamoDBMappingTemplate.query(queryArguments);

        return new Resolver({
            ApiId: Fn.GetAtt(ResourceConstants.RESOURCES.GraphQLAPILogicalID, 'ApiId'),
            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)')
                ])
            )
github aws-amplify / amplify-cli / packages / graphql-connection-transformer / src / resources.ts View on Github external
set(ref('query'), obj({
                'expression': str('#connectionAttribute = :connectionAttribute'),
                'expressionNames': obj({
                    '#connectionAttribute': str(connectionAttribute)
                }),
                'expressionValues': obj({
                    ':connectionAttribute': obj({
                        'S': str('$context.source.id')
                    })
                })
            }))
        ];
        if (sortKeyInfo) {
            setup.push(applyKeyConditionExpression(sortKeyInfo.fieldName, sortKeyInfo.attributeType, 'query'));
        }
        return new Resolver({
            ApiId: Fn.GetAtt(ResourceConstants.RESOURCES.GraphQLAPILogicalID, 'ApiId'),
            DataSourceName: Fn.GetAtt(ModelResourceIDs.ModelTableDataSourceID(relatedType), 'Name'),
            FieldName: field,
            TypeName: type,
            RequestMappingTemplate: print(
                compoundExpression([
                    ...setup,
                    DynamoDBMappingTemplate.query({
                        query: raw('$util.toJson($query)'),
                        scanIndexForward: ifElse(
                            ref('context.args.sortDirection'),
                            ifElse(
                                equals(ref('context.args.sortDirection'), str('ASC')),
                                bool(true),
                                bool(false)
                            ),
github aws-amplify / amplify-cli / packages / graphql-connection-transformer / src / resources.ts View on Github external
public makeGetItemConnectionResolver(type: string, field: string, relatedType: string, connectionAttribute: string): Resolver {
        return new Resolver({
            ApiId: Fn.GetAtt(ResourceConstants.RESOURCES.GraphQLAPILogicalID, 'ApiId'),
            DataSourceName: Fn.GetAtt(ModelResourceIDs.ModelTableDataSourceID(relatedType), 'Name'),
            FieldName: field,
            TypeName: type,
            RequestMappingTemplate: print(
                DynamoDBMappingTemplate.getItem({
                    key: obj({
                        id: ref(`util.dynamodb.toDynamoDBJson($util.defaultIfNullOrBlank($ctx.source.${connectionAttribute}, "${NONE_VALUE}"))`)
                    })
                })
            ),
            ResponseMappingTemplate: print(
                ref('util.toJson($context.result)')
            )
        }).dependsOn(ResourceConstants.RESOURCES.GraphQLSchemaLogicalID)
    }