Skip to content

Commit 547dfe5

Browse files
committed
feat(ts-client): can specify error type pattern in cli
1 parent 2a77493 commit 547dfe5

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/cli/generate.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,22 @@ const args = Command.create().description(`Generate a type safe GraphQL client.`
1212
`Directory path for where to output the generated TypeScript files.`,
1313
),
1414
)
15+
.parametersExclusive(
16+
`schemaErrorType`,
17+
$ =>
18+
$.parameter(
19+
`schemaErrorTypes`,
20+
z.boolean().describe(
21+
`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".`,
22+
),
23+
)
24+
.parameter(
25+
`schemaErrorTypePattern`,
26+
z.string().min(1).describe(
27+
`Designate objects whose name matches this JS regular expression as being error types in your schema.`,
28+
),
29+
).default(`schemaErrorTypes`, true),
30+
)
1531
.parameter(`format`, z.boolean().describe(`Format the generated files using dprint.`).default(true))
1632
.settings({
1733
parameters: {
@@ -24,4 +40,9 @@ await generateFiles({
2440
outputDirPath: args.output,
2541
schemaPath: args.schema,
2642
format: args.format,
43+
errorTypeNamePattern: args.schemaErrorType._tag === `schemaErrorTypePattern`
44+
? new RegExp(args.schemaErrorType.value)
45+
: args.schemaErrorType.value
46+
? /^Error.+/
47+
: undefined,
2748
})

0 commit comments

Comments
 (0)