diff --git a/src/cli/generate.ts b/src/cli/generate.ts index 7f62797ba..fd4099728 100755 --- a/src/cli/generate.ts +++ b/src/cli/generate.ts @@ -12,6 +12,22 @@ const args = Command.create().description(`Generate a type safe GraphQL client.` `Directory path for where to output the generated TypeScript files.`, ), ) + .parametersExclusive( + `schemaErrorType`, + $ => + $.parameter( + `schemaErrorTypes`, + z.boolean().describe( + `Use the schema error types pattern. All object types whose name starts with "Error" will be considered to be error types. If you want to specify a custom name pattern then use the other parameter "schemaErrorTypePattern".`, + ), + ) + .parameter( + `schemaErrorTypePattern`, + z.string().min(1).describe( + `Designate objects whose name matches this JS regular expression as being error types in your schema.`, + ), + ).default(`schemaErrorTypes`, true), + ) .parameter(`format`, z.boolean().describe(`Format the generated files using dprint.`).default(true)) .settings({ parameters: { @@ -24,4 +40,9 @@ await generateFiles({ outputDirPath: args.output, schemaPath: args.schema, format: args.format, + errorTypeNamePattern: args.schemaErrorType._tag === `schemaErrorTypePattern` + ? new RegExp(args.schemaErrorType.value) + : args.schemaErrorType.value + ? /^Error.+/ + : undefined, })