Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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)
);
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);
});
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);
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();
});
});
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 };
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 };
resetGenerator = () => {
const context = {
schema: schema,
operations: {},
fragments: {},
typesUsed: {}
};
generator = new CodeGenerator(context);
};
beforeEach(function() {
generator = new CodeGenerator();
});