How to use the graphql-transformer-common.ResourceConstants.CONDITIONS function in graphql-transformer-common

To help you get started, we’ve selected a few graphql-transformer-common 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-connection-transformer / src / resources.ts View on Github external
// If the GSI does not exist yet then add it.
        const existingGSI = gsis.find(gsi => gsi.IndexName === connectionGSIName)
        if (!existingGSI) {
            const keySchema = [new KeySchema({ AttributeName: connectionAttributeName, KeyType: 'HASH' })]
            if (sortField) {
                keySchema.push(new KeySchema({ AttributeName: sortField.name, KeyType: 'RANGE' }))
            }
            gsis.push(new GlobalSecondaryIndex({
                IndexName: connectionGSIName,
                KeySchema: keySchema,
                Projection: new Projection({
                    ProjectionType: 'ALL'
                }),
                ProvisionedThroughput: Fn.If(
                    ResourceConstants.CONDITIONS.ShouldUsePayPerRequestBilling,
                    Refs.NoValue,
                    {
                        ReadCapacityUnits: Fn.Ref(ResourceConstants.PARAMETERS.DynamoDBModelTableReadIOPS),
                        WriteCapacityUnits: Fn.Ref(ResourceConstants.PARAMETERS.DynamoDBModelTableWriteIOPS)
                    }
                ) as any,
            }))
        }

        // If the attribute definition does not exist yet, add it.
        const attributeDefinitions = table.Properties.AttributeDefinitions as AttributeDefinition[]
        const existingAttribute = attributeDefinitions.find(attr => attr.AttributeName === connectionAttributeName)
        if (!existingAttribute) {
            attributeDefinitions.push(new AttributeDefinition({
                AttributeName: connectionAttributeName,
                AttributeType: 'S'
github aws-amplify / amplify-cli / packages / graphql-function-transformer / src / FunctionTransformer.ts View on Github external
role = (name: string, region: string): any => {
    return new IAM.Role({
      RoleName: Fn.If(
        ResourceConstants.CONDITIONS.HasEnvironmentParameter,
        Fn.Join('-', [
          FunctionResourceIDs.FunctionIAMRoleName(name, true), // max of 64. 64-10-26-28 = 0
          Fn.GetAtt(ResourceConstants.RESOURCES.GraphQLAPILogicalID, 'ApiId'), // 26
          Fn.Ref(ResourceConstants.PARAMETERS.Env), // 10
        ]),
        Fn.Join('-', [
          FunctionResourceIDs.FunctionIAMRoleName(name, false), // max of 64. 64-26-38 = 0
          Fn.GetAtt(ResourceConstants.RESOURCES.GraphQLAPILogicalID, 'ApiId'), // 26
        ])
      ),
      AssumeRolePolicyDocument: {
        Version: '2012-10-17',
        Statement: [
          {
            Effect: 'Allow',
            Principal: {
github aws-amplify / amplify-cli / packages / graphql-key-transformer / src / KeyTransformer.ts View on Github external
if (primaryPartitionKeyName === ks[0].AttributeName) {
                // This is an LSI.
                // Add the new secondary index and update the table's attribute definitions.
                tableResource.Properties.LocalSecondaryIndexes = append(
                    tableResource.Properties.LocalSecondaryIndexes,
                    new LocalSecondaryIndex(baseIndexProperties)
                )
            } else {
                // This is a GSI.
                // Add the new secondary index and update the table's attribute definitions.
                tableResource.Properties.GlobalSecondaryIndexes = append(
                    tableResource.Properties.GlobalSecondaryIndexes,
                    new GlobalSecondaryIndex({
                        ...baseIndexProperties,
                        ProvisionedThroughput: Fn.If(
                            ResourceConstants.CONDITIONS.ShouldUsePayPerRequestBilling,
                            Refs.NoValue,
                            {
                                ReadCapacityUnits: Fn.Ref(ResourceConstants.PARAMETERS.DynamoDBModelTableReadIOPS),
                                WriteCapacityUnits: Fn.Ref(ResourceConstants.PARAMETERS.DynamoDBModelTableWriteIOPS)
                            }
                        ) as any,
                    })
                )
            }
            const existingAttrDefSet = new Set(tableResource.Properties.AttributeDefinitions.map(ad => ad.AttributeName));
            for (const attr of attrDefs) {
                if (!existingAttrDefSet.has(attr.AttributeName)) {
                    tableResource.Properties.AttributeDefinitions.push(attr);
                }
            }
        }
github aws-amplify / amplify-cli / packages / graphql-auth-transformer / src / resources.ts View on Github external
public makeAppSyncApiKey(apiKeyConfig: Transformer.ApiKeyConfig) {
    let expirationDays = 7;
    if (apiKeyConfig && apiKeyConfig.apiKeyExpirationDays) {
      expirationDays = apiKeyConfig.apiKeyExpirationDays;
    }
    const expirationDateInSeconds = 60 /* s */ * 60 /* m */ * 24 /* h */ * expirationDays; /* d */
    const nowEpochTime = Math.floor(Date.now() / 1000);
    return new AppSync.ApiKey({
      ApiId: Fn.GetAtt(ResourceConstants.RESOURCES.GraphQLAPILogicalID, 'ApiId'),
      Description: apiKeyConfig && apiKeyConfig.description ? apiKeyConfig.description : undefined,
      Expires: Fn.If(
        ResourceConstants.CONDITIONS.APIKeyExpirationEpochIsPositive,
        Fn.Ref(ResourceConstants.PARAMETERS.APIKeyExpirationEpoch),
        nowEpochTime + expirationDateInSeconds
      ),
    }).condition(ResourceConstants.CONDITIONS.ShouldCreateAPIKey);
  }
github aws-amplify / amplify-cli / packages / graphql-auth-transformer / src / resources.ts View on Github external
public makeAppSyncApiKey(apiKeyConfig: Transformer.ApiKeyConfig) {
    let expirationDays = 7;
    if (apiKeyConfig && apiKeyConfig.apiKeyExpirationDays) {
      expirationDays = apiKeyConfig.apiKeyExpirationDays;
    }
    const expirationDateInSeconds = 60 /* s */ * 60 /* m */ * 24 /* h */ * expirationDays; /* d */
    const nowEpochTime = Math.floor(Date.now() / 1000);
    return new AppSync.ApiKey({
      ApiId: Fn.GetAtt(ResourceConstants.RESOURCES.GraphQLAPILogicalID, 'ApiId'),
      Description: apiKeyConfig && apiKeyConfig.description ? apiKeyConfig.description : undefined,
      Expires: Fn.If(
        ResourceConstants.CONDITIONS.APIKeyExpirationEpochIsPositive,
        Fn.Ref(ResourceConstants.PARAMETERS.APIKeyExpirationEpoch),
        nowEpochTime + expirationDateInSeconds
      ),
    }).condition(ResourceConstants.CONDITIONS.ShouldCreateAPIKey);
  }
github aws-amplify / amplify-cli / packages / graphql-elasticsearch-transformer / src / resources.ts View on Github external
private joinWithEnv(separator: string, listToJoin: any[]) {
        return Fn.If(
            ResourceConstants.CONDITIONS.HasEnvironmentParameter,
            Fn.Join(
                separator,
                [
                    ...listToJoin,
                    Fn.Ref(ResourceConstants.PARAMETERS.Env)
                ]
            ),
            Fn.Join(
                separator,
                listToJoin
            )
        )
    }
github aws-amplify / amplify-cli / packages / graphql-transformer-core / src / util / syncUtils.ts View on Github external
function joinWithEnv(separator: string, listToJoin: any[]) {
    return Fn.If(
      ResourceConstants.CONDITIONS.HasEnvironmentParameter,
      Fn.Join(separator, [...listToJoin, Fn.Ref(ResourceConstants.PARAMETERS.Env)]),
      Fn.Join(separator, listToJoin)
    );
  }
  export function syncLambdaIAMRole({ name, region }: { name: string; region?: string }) {
github aws-amplify / amplify-cli / packages / graphql-dynamodb-transformer / src / resources.ts View on Github external
public makeAppSyncAPI() {
    return new AppSync.GraphQLApi({
      Name: Fn.If(
        ResourceConstants.CONDITIONS.HasEnvironmentParameter,
        Fn.Join('-', [Fn.Ref(ResourceConstants.PARAMETERS.AppSyncApiName), Fn.Ref(ResourceConstants.PARAMETERS.Env)]),
        Fn.Ref(ResourceConstants.PARAMETERS.AppSyncApiName)
      ),
      AuthenticationType: 'API_KEY',
    });
  }
github aws-amplify / amplify-cli / packages / graphql-transformer-core / src / util / syncUtils.ts View on Github external
export function syncLambdaArnResource({ name, region }: { name: string; region?: string }) {
    const env = 'env;';
    const substitutions = {};
    if (referencesEnv(name)) {
      substitutions[env] = Fn.Ref(ResourceConstants.PARAMETERS.Env);
    }
    return Fn.If(
      ResourceConstants.CONDITIONS.HasEnvironmentParameter,
      Fn.Sub(lambdaArnKey(name, region), substitutions),
      Fn.Sub(lambdaArnKey(removeEnvReference(name), region), {})
    );
  }
  export function lambdaArnKey(name: string, region?: string) {
github aws-amplify / amplify-cli / packages / graphql-appsync-transformer / src / resources.ts View on Github external
public makeEnvironmentConditions() {
        return {
            [ResourceConstants.CONDITIONS.HasEnvironmentParameter]:
                Fn.Not(Fn.Equals(Fn.Ref(ResourceConstants.PARAMETERS.Env), ResourceConstants.NONE))
        }
    }