How to use the apollo-codegen-core/lib/utilities/CodeGenerator 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-typescript-legacy / src / codeGeneration.ts View on Github external
export function generateSource(context: LegacyCompilerContext) {
  const generator = new CodeGenerator(context);

  generator.printOnNewline("/* tslint:disable */");
  generator.printOnNewline(
    "//  This file was automatically generated and should not be edited."
  );

  context.typesUsed.forEach(type =>
    typeDeclarationForGraphQLType(generator, type)
  );
  Object.values(context.operations).forEach(operation => {
    interfaceVariablesDeclarationForOperation(generator, operation);
    interfaceDeclarationForOperation(generator, operation);
  });
  Object.values(context.fragments).forEach(operation =>
    interfaceDeclarationForFragment(generator, operation)
  );
github apollographql / apollo-tooling / packages / apollo-codegen-flow-legacy / src / codeGeneration.ts View on Github external
export function generateSource(context: LegacyCompilerContext) {
  const generator = new CodeGenerator(context);

  generator.printOnNewline("/* @flow */");
  generator.printOnNewline("/* eslint-disable */");
  generator.printOnNewline(
    "//  This file was automatically generated and should not be edited."
  );
  context.typesUsed.forEach(type =>
    typeDeclarationForGraphQLType(generator, type)
  );
  Object.values(context.operations).forEach(operation => {
    interfaceVariablesDeclarationForOperation(generator, operation);
    typeDeclarationForOperation(generator, operation);
  });
  Object.values(context.fragments).forEach(fragment => {
    typeDeclarationForFragment(generator, fragment);
  });
github apollographql / apollo-tooling / packages / apollo-codegen-scala / src / codeGeneration.ts View on Github external
export function generateSource(context: LegacyCompilerContext) {
  const generator = new CodeGenerator(context);

  generator.printOnNewline(
    "//  This file was automatically generated and should not be edited."
  );
  generator.printNewline();

  if (context.options.namespace) {
    packageDeclaration(generator, context.options.namespace);
  }

  context.typesUsed.forEach(type => {
    typeDeclarationForGraphQLType(generator, type);
  });

  Object.values(context.operations).forEach(operation => {
    classDeclarationForOperation(generator, operation);
github apollographql / apollo-tooling / packages / apollo-codegen-scala / src / __tests__ / codeGeneration.ts View on Github external
test("should generate a trait declaration for a GraphQLInputObjectType", function() {
      const generator = new CodeGenerator({
        options: {},
        schema: undefined,
        operations: undefined,
        fragments: undefined,
        typesUsed: undefined
      });

      typeDeclarationForGraphQLType(generator, schema.getType("ReviewInput"));

      expect(generator.output).toMatchSnapshot();
    });
  });
github apollographql / apollo-tooling / packages / apollo-codegen-flow-legacy / src / __tests__ / codeGeneration.js View on Github external
function setup(schema) {
  const context = {
    schema: schema,
    operations: {},
    fragments: {},
    typesUsed: {}
  };

  const generator = new CodeGenerator(context);

  const compileFromSource = source => {
    const document = parse(source);
    const context = compileToLegacyIR(schema, document, {
      mergeInFieldsFromFragmentSpreads: true,
      addTypename: true
    });
    generator.context = context;
    return context;
  };

  const addFragment = fragment => {
    generator.context.fragments[fragment.fragmentName] = fragment;
  };

  return { generator, compileFromSource, addFragment };
github apollographql / apollo-tooling / packages / apollo-codegen-typescript-legacy / src / __tests__ / codeGeneration.js View on Github external
function setup(schema) {
    const context = {
      schema: schema,
      operations: {},
      fragments: {},
      typesUsed: {}
    };

    generator = new CodeGenerator(context);

    compileFromSource = source => {
      const document = parse(source);
      const context = compileToLegacyIR(schema, document, {
        mergeInFieldsFromFragmentSpreads: true,
        addTypename: true
      });
      generator.context = context;
      return context;
    };

    addFragment = fragment => {
      generator.context.fragments[fragment.fragmentName] = fragment;
    };

    return { generator, compileFromSource, addFragment };
github apollographql / apollo-tooling / packages / apollo-codegen-scala / src / __tests__ / codeGeneration.ts View on Github external
resetGenerator = () => {
      const context = {
        schema: schema,
        operations: {},
        fragments: {},
        typesUsed: {}
      };
      generator = new CodeGenerator(context);
    };