How to use the @graphql-codegen/visitor-plugin-common.indent 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 / languages / swift-declaration-block.ts View on Github external
.map((line, index) => {
      const isLast = lines.length === index + 1;
      const isFirst = index === 0;

      if (isFirst && isLast) {
        return indent(`// ${comment} \n`, indentLevel);
      }
      line = line.split('*/').join('*\\/');
      return indent(`${isFirst ? '/*' : ''} * ${line}${isLast ? '\n */\n' : ''}`, indentLevel);
    })
    .join('\n');
github aws-amplify / amplify-cli / packages / amplify-codegen-model-plugin / src / languages / typescript-declaration-block.ts View on Github external
.map((line, index) => {
      const isLast = lines.length === index + 1;
      const isFirst = index === 0;

      if (isFirst && isLast) {
        return indent(`// ${comment} */\n`, indentLevel);
      }

      return indent(`${isFirst ? '/*' : ''} * ${line}${isLast ? '\n */\n' : ''}`, indentLevel);
    })
    .join('\n');
github dotansimha / graphql-code-generator / packages / plugins / java / java / src / visitor.ts View on Github external
.map(arg => {
        const typeToUse = this.resolveInputFieldType(arg.type);

        if (typeToUse.isArray && !typeToUse.isScalar) {
          this._addListImport = true;
          return indent(`this._${arg.name.value} = ((List>) args.get("${arg.name.value}")).stream().map(${typeToUse.baseType}::new).collect(Collectors.toList());`, 3);
        } else if (typeToUse.isScalar) {
          return indent(`this._${arg.name.value} = (${typeToUse.typeName}) args.get("${arg.name.value}");`, 3);
        } else {
          return indent(`this._${arg.name.value} = new ${typeToUse.typeName}((Map) args.get("${arg.name.value}"));`, 3);
        }
      })
      .join('\n');
github aws-amplify / amplify-cli / packages / amplify-codegen-model-plugin / src / visitors / appsync-java-visitor.ts View on Github external
const interfaces = nonIdFields.map((field, idx) => {
      const fieldName = this.getFieldName(field);
      const isLastField = nonIdFields.length - 1 === idx ? true : false;
      const returnType = isLastField ? 'Build' : nonIdFields[idx + 1].name;
      const interfaceName = this.getStepInterfaceName(field.name);
      const interfaceDeclaration = new JavaDeclarationBlock()
        .asKind('interface')
        .withName(interfaceName)
        .access('public');
      interfaceDeclaration.withBlock(
        indent(`${this.getStepInterfaceName(returnType)} ${fieldName}(${this.getNativeType(field)} ${fieldName});`)
      );
      return interfaceDeclaration;
    });
github dotansimha / graphql-code-generator / packages / plugins / java / apollo-android / src / operation-visitor.ts View on Github external
@Override
  public void write(Object value, ResponseWriter.ListItemWriter listItemWriter) {
    listItemWriter.${writerMethod.name}(((${f.className}) value)${writerMethod.useMarshaller ? '.marshaller()' : ''});
  }
});`,
        2
      );
    }

    let fValue = `${f.fieldName}${writerMethod.useMarshaller ? '.marshaller()' : ''}`;

    if (writerMethod.checkNull || !f.isNonNull) {
      fValue = `${f.fieldName} != null ? ${fValue} : null`;
    }

    return indent(`writer.${writerMethod.name}(${writerMethod.castTo ? `(${writerMethod.castTo}) ` : ''}$responseFields[${index}], ${fValue});`, 2);
  })
  .join('\n')}
github dotansimha / graphql-code-generator / packages / plugins / typescript / mongodb / src / fields-tree.ts View on Github external
const fields = Object.keys(root).map(fieldName => {
      const fieldValue = root[fieldName];

      return indent(`${fieldName}: ${this._getInnerField(fieldValue, level + 1)},`, level);
    });
github dotansimha / graphql-code-generator / packages / plugins / typescript / typescript / src / visitor.ts View on Github external
FieldDefinition(node: FieldDefinitionNode, key?: number | string, parent?: any): string {
    const typeString = (node.type as any) as string;
    const originalFieldNode = parent[key] as FieldDefinitionNode;
    const addOptionalSign = !this.config.avoidOptionals.object && originalFieldNode.type.kind !== Kind.NON_NULL_TYPE;
    const comment = transformComment((node.description as any) as string, 1);

    return comment + indent(`${this.config.immutableTypes ? 'readonly ' : ''}${node.name}${addOptionalSign ? '?' : ''}: ${typeString},`);
  }
github aws-amplify / amplify-cli / packages / amplify-codegen-model-plugin / src / visitors / appsync-java-visitor.ts View on Github external
model.fields.forEach((field: CodeGenField) => {
      const fieldName = this.getFieldName(field);
      const returnType = this.getNativeType(field);
      const methodName = `get${pascalCase(field.name)}`;
      const body = indent(`return ${fieldName};`);
      declarationsBlock.addClassMethod(methodName, returnType, body, undefined, undefined, 'public');
    });
  }
github aws-amplify / amplify-cli / packages / amplify-codegen-appsync-model-plugin / src / visitors / appsync-java-visitor.ts View on Github external
const interfaces = requiredInterfaces.map((field, idx) => {
      const isLastField = requiredInterfaces.length - 1 === idx ? true : false;
      const returnType = isLastField ? 'Build' : requiredInterfaces[idx + 1].name;
      const interfaceName = this.getStepInterfaceName(field.name);
      const methodName = this.getStepFunctionName(field);
      const argumentType = this.getNativeType(field);
      const argumentName = this.getStepFunctionArgumentName(field);
      const interfaceDeclaration = new JavaDeclarationBlock()
        .asKind('interface')
        .withName(interfaceName)
        .access('public');
      interfaceDeclaration.withBlock(indent(`${this.getStepInterfaceName(returnType)} ${methodName}(${argumentType} ${argumentName});`));
      return interfaceDeclaration;
    });