How to use the @graphql-codegen/visitor-plugin-common.indentMultiline function in @graphql-codegen/visitor-plugin-common

To help you get started, we’ve selected a few @graphql-codegen/visitor-plugin-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 / amplify-codegen-appsync-model-plugin / src / visitors / appsync-java-visitor.ts View on Github external
.withName('Builder')
      .implements([...stepInterfaces, this.getStepInterfaceName('Build')]);

    // Add private instance fields
    [...nonNullableFields, ...nullableFields].forEach((field: CodeGenField) => {
      const fieldName = this.getFieldName(field);
      builderClassDeclaration.addClassMember(fieldName, this.getNativeType(field), '', undefined, 'private');
    });

    // methods
    // build();
    const buildImplementation = [`String id = this.id != null ? this.id : UUID.randomUUID().toString();`, ''];
    const buildParams = this.getNonConnectedField(model)
      .map(field => this.getFieldName(field))
      .join(',\n');
    buildImplementation.push(`return new ${this.getModelName(model)}(\n${indentMultiline(buildParams)});`);
    builderClassDeclaration.addClassMethod(
      'build',
      this.getModelName(model),
      indentMultiline(buildImplementation.join('\n')),
      undefined,
      [],
      'public',
      {},
      ['Override']
    );

    // non-nullable fields
    stepFields.forEach((field: CodeGenField, idx: number, fields) => {
      const isLastStep = idx === fields.length - 1;
      const fieldName = this.getFieldName(field);
      const methodName = this.getStepFunctionName(field);
github aws-amplify / amplify-cli / packages / amplify-codegen-appsync-model-plugin / src / languages / java-declaration-block.ts View on Github external
method.flags.final ? 'final' : null,
      method.flags.transient ? 'transient' : null,
      method.flags.volatile ? 'volatile' : null,
      ...(method.returnTypeAnnotations || []).map(annotation => `@${annotation}`),
      method.returnType,
      method.name,
    ].filter(f => f);

    const args = method.args.map(arg => this.printMember(arg)).join(', ');
    const comment = method.comment ? transformComment(method.comment) : '';
    const possibleException = method.exception && method.exception.length ? ` throws ${method.exception.join(', ')}` : '';
    return [
      comment,
      [pieces.join(' '), '(', args, ')', possibleException, ' ', '{'].filter(p => p).join(''),
      '\n',
      indentMultiline(method.implementation),
      '\n',
      '}',
    ]
      .filter(p => p)
      .join('');
  }
github aws-amplify / amplify-cli / packages / amplify-codegen-appsync-model-plugin / src / visitors / appsync-java-visitor.ts View on Github external
Object.entries(this.getSelectedEnums()).forEach(([name, enumValue]) => {
      const enumDeclaration = new JavaDeclarationBlock()
        .asKind('enum')
        .access('public')
        .withName(this.getEnumName(enumValue))
        .annotate(['SuppressWarnings("all")'])
        .withComment('Auto generated enum from GraphQL schema.');
      const body = Object.values(enumValue.values);
      enumDeclaration.withBlock(indentMultiline(body.join(',\n')));
      result.push(enumDeclaration.string);
    });
    return result.join('\n');
github aws-amplify / amplify-cli / packages / amplify-codegen-model-plugin / src / languages / typescript-declaration-block.ts View on Github external
}
      methodAccessAndName.push(method.name);

      const args = method.args
        .map(arg => {
          return `${arg.name}${arg.type ? `: ${arg.type}` : ''}`;
        })
        .join(', ');

      const returnType = method.returnType ? `: ${method.returnType}` : '';
      const methodHeaderStr = `${methodAccessAndName.join(' ')}(${args})${returnType}`;

      if (this._flags.isDeclaration) {
        return `${methodHeaderStr};`;
      }
      return [`${methodHeaderStr}`, '{', method.implmentation ? indentMultiline(method.implmentation) : '', '}'].join('\n');
    });
    return methods.join('\n');
github aws-amplify / amplify-cli / packages / amplify-codegen-model-plugin / src / languages / swift-declaration-block.ts View on Github external
private generatePropertiesStr(prop: StructProperty): string {
    const propertyTypeName = prop.flags.isList ? `[${prop.type}]` : prop.type;
    const propertyType = propertyTypeName ? `:${propertyTypeName}${prop.flags.optional && !prop.flags.isList ? '?' : ''}` : '';
    let resultArr: string[] = [
      prop.access,
      prop.flags.static ? 'static' : '',
      prop.flags.variable ? 'var' : 'let',
      `${prop.name}`,
      propertyType,
    ];

    const getterStr = prop.getter ? `{\n${indentMultiline(prop.getter)} \n}` : null;
    const setterStr = prop.setter ? `{\n${indentMultiline(prop.setter)} \n}` : null;
    let getterSetterStr = '';
    if (setterStr) {
      getterSetterStr = this.mergeSections(
        ['{', indentMultiline(`set: ${setterStr}`), getterStr ? indentMultiline(`get: ${getterStr}`) : '', '}'],
        false
      );
    } else if (getterStr) {
      getterSetterStr = indentMultiline(getterStr);
    }
    resultArr.push(getterSetterStr);
    if (prop.value) {
      resultArr.push('=');
      resultArr.push(prop.value);
    }
    const propDeclaration = resultArr.filter(r => !!r).join(' ');
github aws-amplify / amplify-cli / packages / amplify-codegen-appsync-model-plugin / src / languages / swift-declaration-block.ts View on Github external
private generatePropertiesStr(prop: StructProperty): string {
    const propertyTypeName = prop.flags.isList ? `List<${prop.type}>` : prop.type;
    const propertyType = propertyTypeName ? `: ${propertyTypeName}${prop.flags.optional ? '?' : ''}` : '';
    let resultArr: string[] = [
      prop.access,
      prop.flags.static ? 'static' : '',
      prop.flags.variable ? 'var' : 'let',
      `${prop.name}${propertyType}`,
    ];

    const getterStr = prop.getter ? `{\n${indentMultiline(prop.getter)} \n}` : null;
    const setterStr = prop.setter ? `{\n${indentMultiline(prop.setter)} \n}` : null;
    let getterSetterStr = '';
    if (setterStr) {
      getterSetterStr = this.mergeSections(
        ['{', indentMultiline(`set: ${setterStr}`), getterStr ? indentMultiline(`get: ${getterStr}`) : '', '}'],
        false
      );
    } else if (getterStr) {
      getterSetterStr = indentMultiline(getterStr);
    }
    resultArr.push(getterSetterStr);
    if (prop.value) {
      resultArr.push('=');
      resultArr.push(prop.value);
    }
    const propDeclaration = resultArr.filter(r => !!r).join(' ');
    return this.mergeSections([prop.comment ? `${transformComment(prop.comment)}` : '', propDeclaration], false);
  }
github aws-amplify / amplify-cli / packages / amplify-codegen-appsync-model-plugin / src / languages / swift-declaration-block.ts View on Github external
this._methods.map(method => {
        const argsStr = this.generateArgsStr(method.args);
        const argWithParenthesis = argsStr.length ? ['(', indentMultiline(argsStr).trim(), ')'].join('') : '()';
        const methodHeader = this.mergeSections(
          [
            method.access === 'DEFAULT' ? '' : method.access,
            method.flags.static ? 'static' : '',
            ['init', 'deinit'].includes(method.name) ? '' : 'func',
            `${method.name}${argWithParenthesis}`,
            method.returnType ? `-> ${method.returnType}` : '',
            '{',
          ],
          false,
          ' '
        );
        const methodFooter = '}';
        return this.mergeSections([method.comment, methodHeader, indentMultiline(method.implementation), methodFooter], false);
      }),
      false
github aws-amplify / amplify-cli / packages / amplify-codegen-model-plugin / src / languages / swift-declaration-block.ts View on Github external
private generatePropertiesStr(prop: StructProperty): string {
    const propertyTypeName = prop.flags.isList ? `[${prop.type}]` : prop.type;
    const propertyType = propertyTypeName ? `:${propertyTypeName}${prop.flags.optional && !prop.flags.isList ? '?' : ''}` : '';
    let resultArr: string[] = [
      prop.access,
      prop.flags.static ? 'static' : '',
      prop.flags.variable ? 'var' : 'let',
      `${prop.name}`,
      propertyType,
    ];

    const getterStr = prop.getter ? `{\n${indentMultiline(prop.getter)} \n}` : null;
    const setterStr = prop.setter ? `{\n${indentMultiline(prop.setter)} \n}` : null;
    let getterSetterStr = '';
    if (setterStr) {
      getterSetterStr = this.mergeSections(
        ['{', indentMultiline(`set: ${setterStr}`), getterStr ? indentMultiline(`get: ${getterStr}`) : '', '}'],
        false
      );
    } else if (getterStr) {
      getterSetterStr = indentMultiline(getterStr);
    }
    resultArr.push(getterSetterStr);
    if (prop.value) {
      resultArr.push('=');
      resultArr.push(prop.value);
    }
    const propDeclaration = resultArr.filter(r => !!r).join(' ');
    return this.mergeSections([prop.comment ? `${transformComment(prop.comment)}` : '', propDeclaration], false);
github aws-amplify / amplify-cli / packages / amplify-codegen-appsync-model-plugin / src / visitors / appsync-swift-visitor.ts View on Github external
generateModelSchema(name: string, model: CodeGenModel, extensionDeclaration: SwiftDeclarationBlock): void {
    const keysName = lowerCaseFirst(model.name);
    const fields = model.fields.map(field => {
      return this.generateFieldSchema(field, keysName);
    });

    const closure = [
      '{ model in',
      `let ${keysName} = ${this.getModelName(model)}.keys`,
      '',
      `model.pluralName = "${this.pluralizeModelName(model)}"`,
      '',
      'model.fields(',
      indentMultiline(fields.join(',\n')),
      ')',
      '}',
    ].join('\n');
    extensionDeclaration.addProperty(
      'schema',
      '',
      `defineSchema ${indentMultiline(closure).trim()}`,
      'public',
      { static: true, variable: false },
      ' MARK: - ModelSchema'
    );
  }
github aws-amplify / amplify-cli / packages / amplify-codegen-appsync-model-plugin / src / languages / swift-declaration-block.ts View on Github external
private generateArgsStr(args: MethodArgument[]): string {
    const res: string[] = args.reduce((acc: string[], arg) => {
      const val: string | null = arg.value ? arg.value : arg.flags.isList ? '[]' : arg.flags.optional ? 'nil' : null;
      const type = arg.flags.isList ? `List<${arg.type}>` : arg.type;
      acc.push([arg.name, ': ', type, arg.flags.optional ? '?' : '', val ? ` = ${val}` : ''].join(''));
      return acc;
    }, []);

    return res.length > 1 ? indentMultiline(res.join(',\n')) : res.join(',');
  }