How to use the graphql-mapping-template.equals 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.

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-auth-transformer / src / resources.ts View on Github external
public appendItemIfLocallyAuthorized(): Expression {
    return iff(
      parens(
        or([
          equals(ref(ResourceConstants.SNIPPETS.IsLocalDynamicGroupAuthorizedVariable), raw('true')),
          equals(ref(ResourceConstants.SNIPPETS.IsLocalOwnerAuthorizedVariable), raw('true')),
        ])
      ),
      qref('$items.add($item)')
    );
  }
github aws-amplify / amplify-cli / packages / graphql-relation-transformer / src / ModelRelationTransformer.ts View on Github external
const setup: Expression[] = [
        set(ref('limit'), ref(`util.defaultIfNull($context.args.limit, ${defaultPageLimit})`)),
        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()
        )
github aws-amplify / amplify-cli / packages / graphql-auth-transformer / src / resources.ts View on Github external
public appendItemIfLocallyAuthorized(): Expression {
        return iff(
            parens(
                or([
                    equals(ref(ResourceConstants.SNIPPETS.IsLocalDynamicGroupAuthorizedVariable), raw('true')),
                    equals(ref(ResourceConstants.SNIPPETS.IsLocalOwnerAuthorizedVariable), raw('true'))
                ])
            ), qref('$items.add($item)')
        )
    }
github aws-amplify / amplify-cli / packages / graphql-connection-transformer / src / resources.ts View on Github external
setup.push(applyKeyConditionExpression(String(keySchema[1].AttributeName),
                                                       attributeTypeFromScalar(sortKeyField.type), 'query'));
            } 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()
            ),
github aws-amplify / amplify-cli / packages / graphql-connection-transformer / src / resources.ts View on Github external
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)
                            ),
                            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()
                        ),
github aws-amplify / amplify-cli / packages / graphql-auth-transformer / src / resources.ts View on Github external
public throwIfSubscriptionUnauthorized(): Expression {
    const ifUnauthThrow = iff(
      not(
        parens(
          or([
            equals(ref(ResourceConstants.SNIPPETS.IsStaticGroupAuthorizedVariable), raw('true')),
            equals(ref(ResourceConstants.SNIPPETS.IsOwnerAuthorizedVariable), raw('true')),
          ])
        )
      ),
      raw('$util.unauthorized()')
    );
    return block('Throw if unauthorized', [ifUnauthThrow]);
  }
github aws-amplify / amplify-cli / packages / graphql-auth-transformer / src / resources.ts View on Github external
public throwIfNotStaticGroupAuthorizedOrAuthConditionIsEmpty(): Expression {
        const ifUnauthThrow = iff(
            not(parens(
                or([
                    equals(ref(ResourceConstants.SNIPPETS.IsStaticGroupAuthorizedVariable), raw('true')),
                    parens(raw('$authCondition && $authCondition.expression != ""'))
                ])
            )), raw('$util.unauthorized()')
        )
        return block('Throw if unauthorized', [
            ifUnauthThrow,
        ])
    }
github aws-amplify / amplify-cli / packages / graphql-auth-transformer / src / resources.ts View on Github external
public throwIfUnauthorized(): Expression {
        const ifUnauthThrow = iff(
            not(parens(
                or([
                    equals(ref(ResourceConstants.SNIPPETS.IsStaticGroupAuthorizedVariable), raw('true')),
                    equals(ref(ResourceConstants.SNIPPETS.IsDynamicGroupAuthorizedVariable), raw('true')),
                    equals(ref(ResourceConstants.SNIPPETS.IsOwnerAuthorizedVariable), raw('true'))
                ])
            )), raw('$util.unauthorized()')
        )
        return block('Throw if unauthorized', [
            ifUnauthThrow,
        ])
    }