How to use the apollo-codegen-core/lib/utilities/graphql.sortEnumValues 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-flow-legacy / src / codeGeneration.ts View on Github external
function enumerationDeclaration(
  generator: CodeGenerator,
  type: GraphQLEnumType
) {
  const { name, description } = type;
  const values = type.getValues();

  generator.printNewlineIfNeeded();
  if (description) {
    description.split("\n").forEach(line => {
      generator.printOnNewline(`// ${line.trim()}`);
    });
  }
  generator.printOnNewline(`export type ${name} =`);
  const nValues = values.length;
  sortEnumValues(values).forEach((value, i) => {
    if (!value.description || value.description.indexOf("\n") === -1) {
      generator.printOnNewline(
        `  "${value.value}"${i === nValues - 1 ? ";" : " |"}${wrap(
          " // ",
          value.description || undefined
        )}`
      );
    } else {
      if (value.description) {
        value.description.split("\n").forEach(line => {
          generator.printOnNewline(`  // ${line.trim()}`);
        });
      }
      generator.printOnNewline(
        `  "${value.value}"${i === nValues - 1 ? ";" : " |"}`
      );
github apollographql / apollo-tooling / packages / apollo-codegen-typescript / src / language.ts View on Github external
public enumerationDeclaration(type: GraphQLEnumType) {
    const { name, description } = type;
    const enumMembers = sortEnumValues(type.getValues()).map(({ value }) => {
      return t.TSEnumMember(t.identifier(value), t.stringLiteral(value));
    });

    const typeAlias = t.exportNamedDeclaration(
      t.TSEnumDeclaration(t.identifier(name), enumMembers),
      []
    );

    if (description) {
      typeAlias.leadingComments = [
        {
          type: "CommentBlock",
          value: commentBlockContent(description)
        } as t.CommentBlock
      ];
    }
github apollographql / apollo-tooling / packages / apollo-codegen-typescript-legacy / src / codeGeneration.ts View on Github external
function enumerationDeclaration(
  generator: CodeGenerator,
  type: GraphQLEnumType
) {
  const { name, description } = type;
  const values = type.getValues();

  generator.printNewlineIfNeeded();
  printDocComment(generator, description || undefined);
  generator.printOnNewline(`export enum ${name} {`);
  sortEnumValues(values).forEach(value => {
    printDocComment(generator, value.description || undefined, 1);
    generator.printOnNewline(`  ${value.value} = "${value.value}",`);
  });
  generator.printOnNewline(`}`);
  generator.printNewline();
}
github apollographql / apollo-tooling / packages / apollo-codegen-flow / src / language.ts View on Github external
public enumerationDeclaration(type: GraphQLEnumType) {
    const { name, description } = type;
    const unionValues = sortEnumValues(type.getValues()).map(({ value }) => {
      const type = t.stringLiteralTypeAnnotation(value);

      return type;
    });

    const typeAlias = t.exportNamedDeclaration(
      t.typeAlias(
        t.identifier(name),
        undefined,
        t.unionTypeAnnotation(unionValues)
      ),
      []
    );

    typeAlias.leadingComments = [
      {