How to use the graphql-mapping-template.bool function in graphql-mapping-template

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

github aws-amplify / amplify-cli / packages / graphql-dynamodb-transformer / src / resources.ts View on Github external
set(ref('limit'), ref(`util.defaultIfNull($context.args.limit, ${defaultPageLimit})`)),
          DynamoDBMappingTemplate.query({
            query: obj({
              expression: str('#typename = :typename'),
              expressionNames: obj({
                '#typename': str('__typename'),
              }),
              expressionValues: obj({
                ':typename': obj({
                  S: str(type),
                }),
              }),
            }),
            scanIndexForward: ifElse(
              ref('context.args.sortDirection'),
              ifElse(equals(ref('context.args.sortDirection'), str('ASC')), bool(true), bool(false)),
              bool(true)
            ),
            filter: ifElse(ref('context.args.filter'), ref('util.transform.toDynamoDBFilterExpression($ctx.args.filter)'), nul()),
            limit: ref('limit'),
            nextToken: ifElse(ref('context.args.nextToken'), str('$context.args.nextToken'), nul()),
            isSyncEnabled,
          }),
        ])
      ),
      ResponseMappingTemplate: isSyncEnabled
        ? print(
            DynamoDBMappingTemplate.dynamoDBResponse(
              compoundExpression([iff(raw('!$result'), set(ref('result'), ref('ctx.result'))), raw('$util.toJson($result)')])
            )
          )
        : print(ref('util.toJson($ctx.result)')),
github aws-amplify / amplify-cli / packages / graphql-relation-transformer / src / ModelRelationTransformer.ts View on Github external
set(ref('query'), makeExpression(keySchema, connectionAttributes))
    ];
    if (keySchema[1] && !connectionAttributes[1]) {
        let sortKeyType = relatedType.fields.find(f => f.name.value === keySchema[1].AttributeName).type;
        let sortKeyAttType = attributeTypeFromScalar(sortKeyType);
        setup.push(applyKeyConditionExpression(keySchema[1].AttributeName, sortKeyAttType, 'query'));
    }

    var queryArguments : { query, filter, scanIndexForward, limit, nextToken, index? } = {
        query: raw('$util.toJson($query)'),
        scanIndexForward: ifElse(
            ref('context.args.sortDirection'),
            ifElse(
                equals(ref('context.args.sortDirection'), str('ASC')),
                bool(true),
                bool(false)
            ),
            bool(true)
        ),
        filter: ifElse(
            ref('context.args.filter'),
            ref('util.transform.toDynamoDBFilterExpression($ctx.args.filter)'),
            nul()
        ),
        limit: ref('limit'),
        nextToken: ifElse(
            ref('context.args.nextToken'),
            str('$context.args.nextToken'),
            nul()
        )
    }
    if (indexName) {
github aws-amplify / amplify-cli / packages / graphql-relation-transformer / src / ModelRelationTransformer.ts View on Github external
if (keySchema[1] && !connectionAttributes[1]) {
        let sortKeyType = relatedType.fields.find(f => f.name.value === keySchema[1].AttributeName).type;
        let sortKeyAttType = attributeTypeFromScalar(sortKeyType);
        setup.push(applyKeyConditionExpression(keySchema[1].AttributeName, sortKeyAttType, 'query'));
    }

    var queryArguments : { query, filter, scanIndexForward, limit, nextToken, index? } = {
        query: raw('$util.toJson($query)'),
        scanIndexForward: ifElse(
            ref('context.args.sortDirection'),
            ifElse(
                equals(ref('context.args.sortDirection'), str('ASC')),
                bool(true),
                bool(false)
            ),
            bool(true)
        ),
        filter: ifElse(
            ref('context.args.filter'),
            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);
github aws-amplify / amplify-cli / packages / graphql-connection-transformer / src / resources.ts View on Github external
'query',
                                                                this.makeCompositeSortKeyName(String(keySchema[1].AttributeName)),
                                                                String(keySchema[1].AttributeName)));
            }
        }

        let queryArguments = {
            query: raw('$util.toJson($query)'),
            scanIndexForward: ifElse(
                ref('context.args.sortDirection'),
                ifElse(
                    equals(ref('context.args.sortDirection'), str('ASC')),
                    bool(true),
                    bool(false)
                ),
                bool(true)
            ),
            filter: ifElse(
                ref('context.args.filter'),
                ref('util.transform.toDynamoDBFilterExpression($ctx.args.filter)'),
                nul()
            ),
            limit: ref('limit'),
            nextToken: ifElse(
                ref('context.args.nextToken'),
                str('$context.args.nextToken'),
                nul()
            ),
            index: indexName ? str(indexName) : undefined
        }

        if (!indexName) {
github aws-amplify / amplify-cli / packages / graphql-connection-transformer / src / resources.ts View on Github external
}
        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)
                            ),
                            bool(true)
                        ),
                        filter: ifElse(
                            ref('context.args.filter'),
                            ref('util.transform.toDynamoDBFilterExpression($ctx.args.filter)'),
                            nul()
                        ),
                        limit: ref('limit'),
                        nextToken: ifElse(
                            ref('context.args.nextToken'),
                            str('$context.args.nextToken'),
                            nul()
                        ),
                        index: str(`gsi-${connectionName}`)
github aws-amplify / amplify-cli / packages / graphql-dynamodb-transformer / src / resources.ts View on Github external
),
          iff(ref('context.args.nextToken'), set(ref(`${requestVariable}.nextToken`), str('$context.args.nextToken'))),
          iff(
            ref('context.args.filter'),
            set(ref(`${requestVariable}.filter`), ref('util.parseJson("$util.transform.toDynamoDBFilterExpression($ctx.args.filter)")'))
          ),
          ifElse(
            raw(`!$util.isNull($${ResourceConstants.SNIPPETS.ModelQueryExpression})
                        && !$util.isNullOrEmpty($${ResourceConstants.SNIPPETS.ModelQueryExpression}.expression)`),
            compoundExpression([
              qref(`$${requestVariable}.put("operation", "Query")`),
              qref(`$${requestVariable}.put("query", $${ResourceConstants.SNIPPETS.ModelQueryExpression})`),
              ifElse(
                raw(`!$util.isNull($ctx.args.sortDirection) && $ctx.args.sortDirection == "DESC"`),
                set(ref(`${requestVariable}.scanIndexForward`), bool(false)),
                set(ref(`${requestVariable}.scanIndexForward`), bool(true))
              ),
            ]),
            qref(`$${requestVariable}.put("operation", "Scan")`)
          ),
          raw(`$util.toJson($${requestVariable})`),
        ])
      ),
      ResponseMappingTemplate: isSyncEnabled ? print(DynamoDBMappingTemplate.dynamoDBResponse()) : print(ref('util.toJson($ctx.result)')),
    });
  }
github aws-amplify / amplify-cli / packages / graphql-connection-transformer / src / resources.ts View on Github external
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)
                            ),
                            bool(true)
                        ),
                        filter: ifElse(
                            ref('context.args.filter'),
                            ref('util.transform.toDynamoDBFilterExpression($ctx.args.filter)'),
                            nul()
                        ),
                        limit: ref('limit'),
                        nextToken: ifElse(
                            ref('context.args.nextToken'),
                            str('$context.args.nextToken'),
                            nul()
                        ),
                        index: str(`gsi-${connectionName}`)
                    })
                ])
            ),
github aws-amplify / amplify-cli / packages / graphql-connection-transformer / src / resources.ts View on Github external
} else {
                setup.push(applyCompositeKeyConditionExpression(this.getSortKeyNames(String(keySchema[1].AttributeName)),
                                                                'query',
                                                                this.makeCompositeSortKeyName(String(keySchema[1].AttributeName)),
                                                                String(keySchema[1].AttributeName)));
            }
        }

        let queryArguments = {
            query: raw('$util.toJson($query)'),
            scanIndexForward: ifElse(
                ref('context.args.sortDirection'),
                ifElse(
                    equals(ref('context.args.sortDirection'), str('ASC')),
                    bool(true),
                    bool(false)
                ),
                bool(true)
            ),
            filter: ifElse(
                ref('context.args.filter'),
                ref('util.transform.toDynamoDBFilterExpression($ctx.args.filter)'),
                nul()
            ),
            limit: ref('limit'),
            nextToken: ifElse(
                ref('context.args.nextToken'),
                str('$context.args.nextToken'),
                nul()
            ),
            index: indexName ? str(indexName) : undefined
        }
github aws-amplify / amplify-cli / packages / graphql-dynamodb-transformer / lib / resources.js View on Github external
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.query({
                    query: graphql_mapping_template_1.obj({
                        'expression': graphql_mapping_template_1.str('#typename = :typename'),
                        'expressionNames': graphql_mapping_template_1.obj({
                            '#typename': graphql_mapping_template_1.str('__typename')
                        }),
                        'expressionValues': graphql_mapping_template_1.obj({
                            ':typename': graphql_mapping_template_1.obj({
                                'S': graphql_mapping_template_1.str(type)
                            })
                        })
                    }),
                    scanIndexForward: graphql_mapping_template_1.ifElse(graphql_mapping_template_1.ref('context.args.sortDirection'), graphql_mapping_template_1.ifElse(graphql_mapping_template_1.equals(graphql_mapping_template_1.ref('context.args.sortDirection'), graphql_mapping_template_1.str('ASC')), graphql_mapping_template_1.bool(true), graphql_mapping_template_1.bool(false)), graphql_mapping_template_1.bool(true)),
                    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.compoundExpression([
                graphql_mapping_template_1.iff(graphql_mapping_template_1.raw('!$result'), graphql_mapping_template_1.set(graphql_mapping_template_1.ref('result'), graphql_mapping_template_1.ref('ctx.result'))),
                graphql_mapping_template_1.raw('$util.toJson($result)')
            ]))
        }).dependsOn(graphql_transformer_common_1.ResourceConstants.RESOURCES.GraphQLSchemaLogicalID);
    };
    /**