Skip to content

Commit

Permalink
feat(ts-client): can specify error type pattern in cli
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonkuhrt committed Apr 20, 2024
1 parent 2a77493 commit 547dfe5
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/cli/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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,
})

0 comments on commit 547dfe5

Please sign in to comment.