How to use the apollo-codegen-core/lib/utilities/printing.join function in apollo-codegen-core

To help you get started, we’ve selected a few apollo-codegen-core 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 apollographql / apollo-tooling / packages / apollo-codegen-scala / src / naming.ts View on Github external
context: LegacyCompilerContext,
  field: GraphQLInputField,
  namespace?: string,
  parentTraitName?: string
): GraphQLInputField & Property {
  const name = field.name;
  const unescapedPropertyName = isMetaFieldName(name) ? name : camelCase(name);
  const propertyName = escapeIdentifierIfNeeded(unescapedPropertyName);

  const type = field.type;
  const isList = isListType(type);
  const isOptional = !isNonNullType(type);
  const bareType = getNamedType(type);

  const bareTypeName = isCompositeType(bareType)
    ? join(
        [
          namespace,
          parentTraitName,
          escapeIdentifierIfNeeded(pascalCase(Inflector.singularize(name)))
        ],
        "."
      )
    : undefined;
  const typeName = typeNameFromGraphQLType(
    context,
    type,
    bareTypeName,
    isOptional,
    true
  );
  return {
github apollographql / apollo-tooling / packages / apollo-codegen-swift / src / language.ts View on Github external
classDeclaration(
    { className, modifiers, superClass, adoptedProtocols = [] }: Class,
    closure: Function
  ) {
    this.printNewlineIfNeeded();
    this.printOnNewline(
      (
        wrap(swift``, new SwiftSource(_join(modifiers, " ")), swift` `) ||
        swift``
      ).concat(swift`class ${className}`)
    );
    this.print(
      wrap(
        swift`: `,
        join(
          [
            superClass !== undefined
              ? SwiftSource.identifier(superClass)
              : undefined,
            ...adoptedProtocols.map(SwiftSource.identifier)
          ],
          ", "
        )
      )
github apollographql / apollo-tooling / packages / apollo-codegen-scala / src / codeGeneration.ts View on Github external
insideCompanion: () => {
      if (possibleTypes) {
        generator.printNewlineIfNeeded();
        generator.printOnNewline("val possibleTypes = scala.collection.Set(");
        generator.print(
          join(Array.from(possibleTypes).map(type => `"${String(type)}"`), ", ")
        );
        generator.print(")");
      }

      generator.printNewlineIfNeeded();
      generator.printOnNewline(
        `implicit class ViewExtensions(private val orig: ${traitName}) extends AnyVal`
      );
      generator.withinBlock(() => {
        if (inlineFragments && inlineFragments.length > 0) {
          inlineFragments.forEach(inlineFragment => {
            const fragClass = traitNameForInlineFragment(inlineFragment);
            generator.printOnNewline(`def as${inlineFragment.typeCondition}`);
            generator.print(`: Option[${fragClass}] =`);
            generator.withinBlock(() => {
              generator.printOnNewline(
github apollographql / apollo-tooling / packages / apollo-codegen-swift / src / helpers.ts View on Github external
propertyFromField(
    field: Field,
    namespace?: string
  ): Field & Property & Struct {
    const { responseKey, isConditional } = field;

    const propertyName = isMetaFieldName(responseKey)
      ? responseKey
      : camelCase(responseKey);

    const structName = join(
      [namespace, this.structNameForPropertyName(responseKey)],
      "."
    );

    let type = field.type;

    if (isConditional && isNonNullType(type)) {
      type = type.ofType;
    }

    const isOptional = !isNonNullType(type);

    const unmodifiedType = getNamedType(field.type);

    const unmodifiedTypeName = isCompositeType(unmodifiedType)
      ? structName
github apollographql / apollo-tooling / packages / apollo-codegen-scala / src / naming.ts View on Github external
export function propertyFromLegacyField(
  context: LegacyCompilerContext,
  field: LegacyField,
  namespace?: string,
  parentTraitName?: string
): LegacyField & Property {
  const name = field.responseName;
  const propertyName = escapeIdentifierIfNeeded(name);

  const type = field.type;
  const isList = isListType(type);
  const isOptional = field.isConditional || !isNonNullType(type);
  const bareType = getNamedType(type);

  const bareTypeName = isCompositeType(bareType)
    ? join(
        [
          namespace,
          parentTraitName,
          escapeIdentifierIfNeeded(pascalCase(Inflector.singularize(name)))
        ],
        "."
      )
    : undefined;
  const typeName = typeNameFromGraphQLType(
    context,
    type,
    bareTypeName,
    isOptional
  );
  return { ...field, propertyName, typeName, isOptional, isList };
}
github apollographql / apollo-tooling / packages / apollo-codegen-swift / src / language.ts View on Github external
static join(
    maybeArray?: (SwiftSource | undefined)[],
    separator?: string
  ): SwiftSource | undefined {
    const result = _join(maybeArray, separator);
    return result ? new SwiftSource(result) : undefined;
  }
}