How to use the graphql-mapping-template.newline 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 / ModelAuthTransformer.ts View on Github external
objectPath
        )
        const ownerAuthorizationExpression = this.resources.ownerAuthorizationExpressionForReadOperations(
            ownerAuthorizationRules,
            objectPath
        )
        const throwIfUnauthorizedExpression = this.resources.throwIfUnauthorized()

        // Update the existing resolver with the authorization checks.
        return compoundExpression([
            staticGroupAuthorizationExpression,
            newline(),
            dynamicGroupAuthorizationExpression,
            newline(),
            ownerAuthorizationExpression,
            newline(),
            throwIfUnauthorizedExpression
        ]);
    }
github aws-amplify / amplify-cli / packages / graphql-auth-transformer / src / ModelAuthTransformer.ts View on Github external
}
                return false;
            };
            const ownerAuthorizationExpression = this.resources.ownerAuthorizationExpressionForSubscriptions(
                ownerAuthorizationRules,
                fieldIsList
            );

            const throwIfUnauthorizedExpression = this.resources.throwIfSubscriptionUnauthorized();
            const templateParts = [
                print(
                    compoundExpression([
                        staticGroupAuthorizationExpression,
                        newline(),
                        ownerAuthorizationExpression,
                        newline(),
                        throwIfUnauthorizedExpression
                    ])
                ),
                resolver.Properties.ResponseMappingTemplate
            ];
            resolver.Properties.ResponseMappingTemplate = templateParts.join('\n\n');
            ctx.setResource(resolverResourceId, resolver);

                // check if owner is enabled in auth
            const hasOwner = rules.find( rule => rule.allow === OWNER_AUTH_STRATEGY && !rule.ownerField);
            const hasStaticGroupAuth = rules.find( rule => rule.allow === GROUPS_AUTH_STRATEGY && !rule.groupsField);
            if (hasOwner) {
                this.addOwner(ctx, parent.name.value);
                // If static group is specified in any of the rules then it would specify the owner arg as optional
                if (hasStaticGroupAuth) {
                    this.addSubscriptionOwnerArgument(ctx, resolver, false)
github aws-amplify / amplify-cli / packages / graphql-transformer-common / src / dynamodbUtils.ts View on Github external
...keyNames.map((keyName, idx) =>
          iff(
            raw(`!$util.isNull($ctx.args.${sortKeyArgumentName}.ge.${keyName})`),
            idx === 0
              ? set(ref(accumulatorVar1), str(`$ctx.args.${sortKeyArgumentName}.ge.${keyName}`))
              : set(ref(accumulatorVar1), str(`$${accumulatorVar1}${sep}$ctx.args.${sortKeyArgumentName}.ge.${keyName}`)),
            true
          )
        ),
        set(ref(`${queryExprReference}.expression`), raw(`"$${queryExprReference}.expression AND #sortKey >= :sortKey"`)),
        qref(`$${queryExprReference}.expressionNames.put("#sortKey", "${sortKeyAttributeName}")`),
        // TODO: Handle N & B.
        qref(`$${queryExprReference}.expressionValues.put(":sortKey", { "S": "$${accumulatorVar1}" })`),
      ])
    ),
    newline(),
  ]);
}
github aws-amplify / amplify-cli / packages / graphql-transformer-common / src / dynamodbUtils.ts View on Github external
function applyCompositeSortKey(sortKeys: string[], sortKeyTypes: ('S' | 'N' | 'B')[], queryExprReference: string) {
  if (sortKeys.length === 0) {
    return newline();
  }
  // E.g. status#date
  const sortKeyAttributeName = ModelResourceIDs.ModelCompositeAttributeName(sortKeys);
  const sortKeyArgumentName = ModelResourceIDs.ModelCompositeKeyArgumentName(sortKeys);
  return compoundExpression([
    applyCompositeKeyConditionExpression(sortKeys, queryExprReference, sortKeyArgumentName, sortKeyAttributeName),
  ]);
}
github aws-amplify / amplify-cli / packages / graphql-auth-transformer / src / ModelAuthTransformer.ts View on Github external
compoundExpression([
                    dynamicGroupAuthorizationExpression,
                    newline(),
                    ownerAuthorizationExpression,
                    newline(),
                    collectAuthCondition
                ])
            )

            const throwIfNotStaticGroupAuthorizedOrAuthConditionIsEmpty = this.resources.throwIfNotStaticGroupAuthorizedOrAuthConditionIsEmpty()

            const authorizationLogic = compoundExpression([
                staticGroupAuthorizationExpression,
                newline(),
                ifNotStaticallyAuthedCreateAuthCondition,
                newline(),
                throwIfNotStaticGroupAuthorizedOrAuthConditionIsEmpty
            ]);

            const templateParts = [
                print(
                    field && ifCondition ?
                        iff(ifCondition, authorizationLogic) :
                        authorizationLogic
                ),
                resolver.Properties.RequestMappingTemplate
            ]
            resolver.Properties.RequestMappingTemplate = templateParts.join('\n\n')
            ctx.setResource(resolverResourceId, resolver)
        }
    }
github aws-amplify / amplify-cli / packages / graphql-auth-transformer / src / ModelAuthTransformer.ts View on Github external
field.name.value,
                fieldIsList
            )

            const throwIfUnauthorizedExpression = this.resources.throwIfUnauthorized()
            const templateParts = [
                print(
                    iff(
                        raw(`$ctx.args.input.containsKey("${field.name.value}")`),
                        compoundExpression([
                            staticGroupAuthorizationExpression,
                            newline(),
                            dynamicGroupAuthorizationExpression,
                            newline(),
                            ownerAuthorizationExpression,
                            newline(),
                            throwIfUnauthorizedExpression
                        ])
                    )
                ),
                createResolverResource.Properties.RequestMappingTemplate
            ]
            createResolverResource.Properties.RequestMappingTemplate = templateParts.join('\n\n')
            ctx.setResource(resolverResourceId, createResolverResource)
        }
    }
github aws-amplify / amplify-cli / packages / graphql-auth-transformer / src / ModelAuthTransformer.ts View on Github external
}
            const ownerAuthorizationExpression = this.resources.ownerAuthorizationExpressionForCreateOperations(
                ownerAuthorizationRules,
                fieldIsList
            )

            const throwIfUnauthorizedExpression = this.resources.throwIfUnauthorized()
            const templateParts = [
                print(
                    compoundExpression([
                        staticGroupAuthorizationExpression,
                        newline(),
                        dynamicGroupAuthorizationExpression,
                        newline(),
                        ownerAuthorizationExpression,
                        newline(),
                        throwIfUnauthorizedExpression
                    ])
                ),
                resolver.Properties.RequestMappingTemplate
            ]
            resolver.Properties.RequestMappingTemplate = templateParts.join('\n\n')
            ctx.setResource(resolverResourceId, resolver)
        }
    }
github aws-amplify / amplify-cli / packages / graphql-transformer-common / src / dynamodbUtils.ts View on Github external
raw(`!$util.isNull($ctx.args.${sortKeyArgumentName})`),
        compoundExpression([
          set(ref('sortKeyArgumentOperations'), raw(`$ctx.args.${sortKeyArgumentName}.keySet()`)),
          iff(
            raw(`$sortKeyArgumentOperations.size() > 1`),
            invalidArgumentError(`Argument ${sortKeyArgumentName} must specify at most one key condition operation.`)
          ),
          forEach(ref('operation'), ref('sortKeyArgumentOperations'), [
            ifElse(raw(`$operation == "between"`), validateBetween(), validateOtherOperation()),
          ]),
        ])
      )
    );
    return block('Validate key arguments.', exprs);
  } else {
    return newline();
  }
}