Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add assumeValidSDL config option #3014

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/getting-started/codegen-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ Here are the supported options that you can define in the config file (see [sour

- **`pluckConfig.globalIdentifier`** - Overrides the name of the default GraphQL name identifier.

- **`assumeValidSDL`** - A flag to assume the SDL is valid

## Environment Variables

You can use environment variables in your `codegen.yml` file::
Expand Down Expand Up @@ -101,6 +103,8 @@ The Codegen also supports several CLI flags that allow you to override the defau

- **`--overwrite` (`-o`)** - Overrides the `overwrite` config to true.

- **`--assumeValidSDL` (`-v`)** - Overrides the `assumeValidSDL` config to true.

## Debug Mode

You can set the `DEBUG` environment variable to `1` in order to tell the codegen to print debug information.
Expand Down
6 changes: 6 additions & 0 deletions packages/graphql-codegen-cli/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export type YamlCliFlags = {
require: string[];
overwrite: boolean;
project: string;
assumeValidSDL?: boolean;
};

function generateSearchPlaces(moduleName: string) {
Expand Down Expand Up @@ -140,6 +141,7 @@ export function parseArgv(argv = process.argv): Command & YamlCliFlags {
.option('-r, --require [value]', 'Loads specific require.extensions before running the codegen and reading the configuration', collect, [])
.option('-o, --overwrite', 'Overwrites existing files')
.option('-p, --project <name>', 'Name of a project in GraphQL Config')
.option('-v, --assumeValidSDL', 'Assumes valid GraphQL SDL.')
.parse(argv) as any) as Command & YamlCliFlags;
}

Expand Down Expand Up @@ -172,6 +174,10 @@ export async function createContext(cliFlags: Command & YamlCliFlags = parseArgv
context.useProject(cliFlags.project);
}

if (cliFlags.assumeValidSDL === true) {
config.assumeValidSDL = cliFlags.assumeValidSDL;
}

context.updateConfig(config);

return context;
Expand Down
3 changes: 2 additions & 1 deletion packages/graphql-codegen-core/src/execute-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export interface ExecutePluginOptions {
outputFilename: string;
allPlugins: Types.ConfiguredPlugin[];
skipDocumentsValidation?: boolean;
assumeValidSDL?: true;
}

export async function executePlugin(options: ExecutePluginOptions, plugin: CodegenPlugin): Promise<Types.PluginOutput> {
Expand All @@ -34,7 +35,7 @@ export async function executePlugin(options: ExecutePluginOptions, plugin: Codeg

const schema = options.schemaAst;

const outputSchema: GraphQLSchema = schema || buildASTSchema(options.schema);
const outputSchema: GraphQLSchema = schema || buildASTSchema(options.schema, { assumeValidSDL: options.assumeValidSDL || false });
const documents = options.documents || [];

if (plugin.validate && typeof plugin.validate === 'function') {
Expand Down
2 changes: 2 additions & 0 deletions packages/utils/plugins-helpers/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export namespace Types {
schema?: InstanceOrArray<Schema>;
config?: PluginConfig;
hooks?: LifecycleHooksDefinition<string | string[]>;
assumeValidSDL?: boolean;
};

/* Output Builder Preset */
Expand Down Expand Up @@ -110,6 +111,7 @@ export namespace Types {
globalIdentifier?: string;
};
hooks?: LifecycleHooksDefinition<string | string[]>;
assumeValidSDL?: boolean;
}

export type ComplexPluginOutput = { content: string; prepend?: string[]; append?: string[] };
Expand Down