How to use the graphql-mapping-template.and 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-auth-transformer / src / resources.ts View on Github external
])
        ),
        // If a single owner check for at least one.
        iff(
          raw(`$util.isString($${allowedOwnersVariable})`),
          iff(raw(`$${allowedOwnersVariable} == $identityValue`), set(ref(variableToSet), raw('true')))
        )
      );
      // If the owner field is not a list and the user does not
      // provide a value for the owner, set the owner automatically.
      if (!ownerFieldIsList) {
        ownershipAuthorizationExpressions.push(
          // If the owner is not provided set it automatically.
          // If the user explicitly provides null this will be false and we leave it null.
          iff(
            and([raw(`$util.isNull($${allowedOwnersVariable})`), parens(raw(`! $${variableToCheck}.containsKey("${ownerAttribute}")`))]),
            compoundExpression([qref(`$${variableToCheck}.put("${ownerAttribute}", $identityValue)`), set(ref(variableToSet), raw('true'))])
          )
        );
      } else {
        // If the owner field is a list and the user does not
        // provide a list of values for the owner, set the list with
        // the owner as the sole member.
        ownershipAuthorizationExpressions.push(
          // If the owner is not provided set it automatically.
          // If the user explicitly provides null this will be false and we leave it null.
          iff(
            and([raw(`$util.isNull($${allowedOwnersVariable})`), parens(raw(`! $${variableToCheck}.containsKey("${ownerAttribute}")`))]),
            compoundExpression([
              qref(`$${variableToCheck}.put("${ownerAttribute}", ["$identityValue"])`),
              set(ref(variableToSet), raw('true')),
            ])
github aws-amplify / amplify-cli / packages / graphql-auth-transformer / src / resources.ts View on Github external
// If the owner is not provided set it automatically.
          // If the user explicitly provides null this will be false and we leave it null.
          iff(
            and([raw(`$util.isNull($${allowedOwnersVariable})`), parens(raw(`! $${variableToCheck}.containsKey("${ownerAttribute}")`))]),
            compoundExpression([qref(`$${variableToCheck}.put("${ownerAttribute}", $identityValue)`), set(ref(variableToSet), raw('true'))])
          )
        );
      } else {
        // If the owner field is a list and the user does not
        // provide a list of values for the owner, set the list with
        // the owner as the sole member.
        ownershipAuthorizationExpressions.push(
          // If the owner is not provided set it automatically.
          // If the user explicitly provides null this will be false and we leave it null.
          iff(
            and([raw(`$util.isNull($${allowedOwnersVariable})`), parens(raw(`! $${variableToCheck}.containsKey("${ownerAttribute}")`))]),
            compoundExpression([
              qref(`$${variableToCheck}.put("${ownerAttribute}", ["$identityValue"])`),
              set(ref(variableToSet), raw('true')),
            ])
          )
        );
      }
      ruleNumber++;
    }
    return compoundExpression([set(ref(variableToSet), raw(`false`)), ...ownershipAuthorizationExpressions]);
  }
github aws-amplify / amplify-cli / packages / graphql-auth-transformer / src / resources.ts View on Github external
]),
                        compoundExpression([
                            qref(`$${variableToCheck}.put("${ownerAttribute}", $identityValue)`),
                            set(ref(variableToSet), raw('true'))
                        ])
                    )
                )
            } else {
                // If the owner field is a list and the user does not
                // provide a list of values for the owner, set the list with
                // the owner as the sole member.
                ownershipAuthorizationExpressions.push(
                    // If the owner is not provided set it automatically.
                    // If the user explicitly provides null this will be false and we leave it null.
                    iff(
                        and([
                            raw(`$util.isNull($${allowedOwnersVariable})`),
                            parens(raw(`! $${variableToCheck}.containsKey("${ownerAttribute}")`)),
                        ]),
                        compoundExpression([
                            qref(`$${variableToCheck}.put("${ownerAttribute}", ["$identityValue"])`),
                            set(ref(variableToSet), raw('true'))
                        ])
                    )
                )
            }
            ruleNumber++
        }
        return compoundExpression([
            set(ref(variableToSet), raw(`false`)),
            ...ownershipAuthorizationExpressions,
        ]);
github aws-amplify / amplify-cli / packages / graphql-dynamodb-transformer / src / resources.ts View on Github external
iff(
            ref('context.args.condition'),
            compoundExpression([
              set(ref('condition.expressionValues'), obj({})),
              set(
                ref('conditionFilterExpressions'),
                raw('$util.parseJson($util.transform.toDynamoDBConditionExpression($context.args.condition))')
              ),
              // tslint:disable-next-line
              qref(`$condition.put("expression", "($condition.expression) AND $conditionFilterExpressions.expression")`),
              qref(`$condition.expressionNames.putAll($conditionFilterExpressions.expressionNames)`),
              qref(`$condition.expressionValues.putAll($conditionFilterExpressions.expressionValues)`),
            ])
          ),
          iff(
            and([ref('condition.expressionValues'), raw('$condition.expressionValues.size() == 0')]),
            set(
              ref('condition'),
              obj({
                expression: ref('condition.expression'),
                expressionNames: ref('condition.expressionNames'),
              })
            )
          ),
          DynamoDBMappingTemplate.putItem(
            {
              key: ifElse(
                ref(ResourceConstants.SNIPPETS.ModelObjectKey),
                raw(`$util.toJson(\$${ResourceConstants.SNIPPETS.ModelObjectKey})`),
                obj({
                  id: raw(`$util.dynamodb.toDynamoDBJson($util.defaultIfNullOrBlank($ctx.args.input.id, $util.autoId()))`),
                }),
github aws-amplify / amplify-cli / packages / graphql-dynamodb-transformer / src / resources.ts View on Github external
compoundExpression([
              set(
                ref('conditionFilterExpressions'),
                raw('$util.parseJson($util.transform.toDynamoDBConditionExpression($context.args.condition))')
              ),
              // tslint:disable-next-line
              qref(`$condition.put("expression", "($condition.expression) AND $conditionFilterExpressions.expression")`),
              qref(`$condition.expressionNames.putAll($conditionFilterExpressions.expressionNames)`),
              set(ref('conditionExpressionValues'), raw('$util.defaultIfNull($condition.expressionValues, {})')),
              qref(`$conditionExpressionValues.putAll($conditionFilterExpressions.expressionValues)`),
              set(ref('condition.expressionValues'), ref('conditionExpressionValues')),
              qref(`$condition.expressionValues.putAll($conditionFilterExpressions.expressionValues)`),
            ])
          ),
          iff(
            and([ref('condition.expressionValues'), raw('$condition.expressionValues.size() == 0')]),
            set(
              ref('condition'),
              obj({
                expression: ref('condition.expression'),
                expressionNames: ref('condition.expressionNames'),
              })
            )
          ),
          DynamoDBMappingTemplate.deleteItem({
            key: ifElse(
              ref(ResourceConstants.SNIPPETS.ModelObjectKey),
              raw(`$util.toJson(\$${ResourceConstants.SNIPPETS.ModelObjectKey})`),
              obj({
                id: ref('util.dynamodb.toDynamoDBJson($ctx.args.input.id)'),
              }),
              true
github aws-amplify / amplify-cli / packages / graphql-auth-transformer / src / resources.ts View on Github external
if (authProvider === 'userPools') {
        const statements = [
          raw(`$util.isNullOrEmpty($${ResourceConstants.SNIPPETS.AuthMode})`),
          not(raw(`$util.isNull($ctx.identity)`)),
          not(raw(`$util.isNull($ctx.identity.sub)`)),
          not(raw(`$util.isNull($ctx.identity.issuer)`)),
          not(raw(`$util.isNull($ctx.identity.username)`)),
          not(raw(`$util.isNull($ctx.identity.claims)`)),
          not(raw(`$util.isNull($ctx.identity.sourceIp)`)),
        ];

        if (isUserPoolTheDefault === true) {
          statements.push(not(raw(`$util.isNull($ctx.identity.defaultAuthStrategy)`)));
        }

        const userPoolsExpression = iff(and(statements), set(ref(ResourceConstants.SNIPPETS.AuthMode), str(`userPools`)));

        expressions.push(userPoolsExpression);
      } else if (authProvider === 'oidc') {
        const oidcExpression = iff(
          and([
            raw(`$util.isNullOrEmpty($${ResourceConstants.SNIPPETS.AuthMode})`),
            not(raw(`$util.isNull($ctx.identity)`)),
            not(raw(`$util.isNull($ctx.identity.sub)`)),
            not(raw(`$util.isNull($ctx.identity.issuer)`)),
            not(raw(`$util.isNull($ctx.identity.claims)`)),
            raw(`$util.isNull($ctx.identity.username)`),
            raw(`$util.isNull($ctx.identity.sourceIp)`),
          ]),
          set(ref(ResourceConstants.SNIPPETS.AuthMode), str(`oidc`))
        );
github aws-amplify / amplify-cli / packages / graphql-auth-transformer / src / resources.ts View on Github external
not(raw(`$util.isNull($ctx.identity.issuer)`)),
          not(raw(`$util.isNull($ctx.identity.username)`)),
          not(raw(`$util.isNull($ctx.identity.claims)`)),
          not(raw(`$util.isNull($ctx.identity.sourceIp)`)),
        ];

        if (isUserPoolTheDefault === true) {
          statements.push(not(raw(`$util.isNull($ctx.identity.defaultAuthStrategy)`)));
        }

        const userPoolsExpression = iff(and(statements), set(ref(ResourceConstants.SNIPPETS.AuthMode), str(`userPools`)));

        expressions.push(userPoolsExpression);
      } else if (authProvider === 'oidc') {
        const oidcExpression = iff(
          and([
            raw(`$util.isNullOrEmpty($${ResourceConstants.SNIPPETS.AuthMode})`),
            not(raw(`$util.isNull($ctx.identity)`)),
            not(raw(`$util.isNull($ctx.identity.sub)`)),
            not(raw(`$util.isNull($ctx.identity.issuer)`)),
            not(raw(`$util.isNull($ctx.identity.claims)`)),
            raw(`$util.isNull($ctx.identity.username)`),
            raw(`$util.isNull($ctx.identity.sourceIp)`),
          ]),
          set(ref(ResourceConstants.SNIPPETS.AuthMode), str(`oidc`))
        );

        if (expressions.length > 0) {
          expressions.push(newline());
        }

        expressions.push(oidcExpression);