How to use the graphql-transformer-common.toUpper 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-relational-schema-transformer / src / AuroraServerlessMySQLDatabaseReader.ts View on Github external
// Fields in the general type (e.g. Post). Both the identifying field and any others the db dictates will be required.
    const fields = new Array();
    // Fields in the update input type (e.g. UpdatePostInput). Only the identifying field will be required, any others will be optional.
    const updateFields = new Array();
    // Field in the create input type (e.g. CreatePostInput).
    const createFields = new Array();

    // The primary key, used to help generate queries and mutations
    let primaryKey = '';
    let primaryKeyType = '';

    // Field Lists needed as context for auto-generating the Query Resolvers
    const intFieldList = new Array();
    const stringFieldList = new Array();

    const formattedTableName = toUpper(tableName);

    for (const columnDescription of columnDescriptions) {
      // If a field is the primary key, save it.
      if (columnDescription.Key == 'PRI') {
        primaryKey = columnDescription.Field;
        primaryKeyType = getGraphQLTypeFromMySQLType(columnDescription.Type);
      } else {
        /**
         * If the field is not a key, then store it in the fields list.
         * As we need this information later to generate query resolvers
         *
         * Currently we will only auto-gen query resolvers for the Int and String scalars
         */
        const type = getGraphQLTypeFromMySQLType(columnDescription.Type);
        if (type === 'Int') {
          intFieldList.push(columnDescription.Field);
github aws-amplify / amplify-cli / packages / graphql-dynamodb-transformer / lib / resources.js View on Github external
ResourceFactory.prototype.makeUpdateResolver = function (type, nameOverride) {
        var fieldName = nameOverride ? nameOverride : graphql_transformer_common_1.graphqlName("update" + graphql_transformer_common_1.toUpper(type));
        return new appSync_1.default.Resolver({
            ApiId: cloudform_1.Fn.GetAtt(graphql_transformer_common_1.ResourceConstants.RESOURCES.GraphQLAPILogicalID, 'ApiId'),
            DataSourceName: cloudform_1.Fn.GetAtt(graphql_transformer_common_1.ModelResourceIDs.ModelTableDataSourceID(type), 'Name'),
            FieldName: fieldName,
            TypeName: 'Mutation',
            RequestMappingTemplate: graphql_mapping_template_1.print(graphql_mapping_template_1.compoundExpression([
                graphql_mapping_template_1.ifElse(graphql_mapping_template_1.ref(graphql_transformer_common_1.ResourceConstants.SNIPPETS.AuthCondition), graphql_mapping_template_1.compoundExpression([
                    graphql_mapping_template_1.set(graphql_mapping_template_1.ref('condition'), graphql_mapping_template_1.ref(graphql_transformer_common_1.ResourceConstants.SNIPPETS.AuthCondition)),
                    graphql_mapping_template_1.qref('$condition.put("expression", "$condition.expression AND attribute_exists(#id)")'),
                    graphql_mapping_template_1.qref('$condition.expressionNames.put("#id", "id")')
                ]), graphql_mapping_template_1.set(graphql_mapping_template_1.ref('condition'), graphql_mapping_template_1.obj({
                    expression: graphql_mapping_template_1.str("attribute_exists(#id)"),
                    expressionNames: graphql_mapping_template_1.obj({
                        "#id": graphql_mapping_template_1.str("id")
                    })
                }))),
github aws-amplify / amplify-cli / packages / graphql-relational-schema-transformer / src / RelationalDBSchemaTransformer.ts View on Github external
private getSubscriptions(types: TableContext[]): ObjectTypeDefinitionNode {
    const fields = [];
    for (const typeContext of types) {
      const type = typeContext.tableTypeDefinition;
      const formattedTypeValue = toUpper(type.name.value);
      fields.push(
        getOperationFieldDefinition(`onCreate${formattedTypeValue}`, [], getNamedType(`${type.name.value}`), [
          getDirectiveNode(`create${formattedTypeValue}`),
        ])
      );
    }
    return getTypeDefinition(fields, 'Subscription');
  }
github aws-amplify / amplify-cli / packages / graphql-relational-schema-transformer / src / RelationalDBResolverGenerator.ts View on Github external
private makeUpdateRelationalResolver(type: string, mutationTypeName: string = 'Mutation') {
    const fieldName = graphqlName('update' + toUpper(type));
    const updateSql = `UPDATE ${type} SET $update WHERE ${this.typePrimaryKeyMap.get(type)}=$ctx.args.update${toUpper(
      type
    )}Input.${this.typePrimaryKeyMap.get(type)}`;
    let selectSql;
    if (this.typePrimaryKeyTypeMap.get(type).includes('String')) {
      selectSql = `SELECT * FROM ${type} WHERE ${this.typePrimaryKeyMap.get(type)}=\'$ctx.args.update${toUpper(
        type
      )}Input.${this.typePrimaryKeyMap.get(type)}\'`;
    } else {
      selectSql = `SELECT * FROM ${type} WHERE ${this.typePrimaryKeyMap.get(type)}=$ctx.args.update${toUpper(
        type
      )}Input.${this.typePrimaryKeyMap.get(type)}`;
    }
    const reqFileName = `${mutationTypeName}.${fieldName}.req.vtl`;
    const resFileName = `${mutationTypeName}.${fieldName}.res.vtl`;
github aws-amplify / amplify-cli / packages / graphql-relational-schema-transformer / src / RelationalDBResolverGenerator.ts View on Github external
private makeCreateRelationalResolver(type: string, mutationTypeName: string = 'Mutation') {
    const fieldName = graphqlName('create' + toUpper(type));
    let createSql = `INSERT INTO ${type} $colStr VALUES $valStr`;
    let selectSql;
    if (this.typePrimaryKeyTypeMap.get(type).includes('String')) {
      selectSql = `SELECT * FROM ${type} WHERE ${this.typePrimaryKeyMap.get(type)}=\'$ctx.args.create${toUpper(
        type
      )}Input.${this.typePrimaryKeyMap.get(type)}\'`;
    } else {
      selectSql = `SELECT * FROM ${type} WHERE ${this.typePrimaryKeyMap.get(type)}=$ctx.args.create${toUpper(
        type
      )}Input.${this.typePrimaryKeyMap.get(type)}`;
    }

    const reqFileName = `${mutationTypeName}.${fieldName}.req.vtl`;
    const resFileName = `${mutationTypeName}.${fieldName}.res.vtl`;

    const reqTemplate = print(
github aws-amplify / amplify-cli / packages / graphql-relational-schema-transformer / src / RelationalDBResolverGenerator.ts View on Github external
private makeCreateRelationalResolver(type: string, mutationTypeName: string = 'Mutation') {
    const fieldName = graphqlName('create' + toUpper(type));
    let createSql = `INSERT INTO ${type} $colStr VALUES $valStr`;
    let selectSql;
    if (this.typePrimaryKeyTypeMap.get(type).includes('String')) {
      selectSql = `SELECT * FROM ${type} WHERE ${this.typePrimaryKeyMap.get(type)}=\'$ctx.args.create${toUpper(
        type
      )}Input.${this.typePrimaryKeyMap.get(type)}\'`;
    } else {
      selectSql = `SELECT * FROM ${type} WHERE ${this.typePrimaryKeyMap.get(type)}=$ctx.args.create${toUpper(
        type
      )}Input.${this.typePrimaryKeyMap.get(type)}`;
    }

    const reqFileName = `${mutationTypeName}.${fieldName}.req.vtl`;
    const resFileName = `${mutationTypeName}.${fieldName}.res.vtl`;

    const reqTemplate = print(
      compoundExpression([
        set(ref('cols'), list([])),
        set(ref('vals'), list([])),
        forEach(ref('entry'), ref(`ctx.args.create${toUpper(type)}Input.keySet()`), [
          set(ref('discard'), ref(`cols.add($entry)`)),
          set(ref('discard'), ref(`vals.add("'$ctx.args.create${toUpper(type)}Input[$entry]'")`)),
        ]),
        set(ref('valStr'), ref('vals.toString().replace("[","(").replace("]",")")')),
github aws-amplify / amplify-cli / packages / graphql-auth-transformer / src / ModelAuthTransformer.ts View on Github external
private protectOnUpdateSubscription(ctx: TransformerContext, rules: AuthRule[],
        parent: ObjectTypeDefinitionNode, level: string, onUpdate?: string[]) {
        if (onUpdate) {
            onUpdate.forEach( (name) => {
                this.addSubscriptionResolvers(ctx, rules, parent, level, name)
            })
        } else {
            this.addSubscriptionResolvers(ctx, rules, parent,
                level, graphqlName(ON_UPDATE_FIELD + toUpper(parent.name.value)))
        }
    }