Open
Description
I have a use case where I would like to be able to pass more than just a string as a directive argument. For example, if I have a directive designed to enforce uniqueness on arrays (in Zod), I would want to use the refine()
method like so:
z.array(z.string()).refine(items => new Set(items).size === items.length);
Translating this to typescript-validation-schema:
directive @array(
unique: Boolean = false
) on INPUT_FIELD_DEFINITION | FIELD_DEFINITION | ARGUMENT_DEFINITION
input TestInput {
userIds: [Int] @array(unique: true)
}
With my CodegenConfig
defined in a TypeScript file: (https://the-guild.dev/graphql/codegen/docs/config-reference/codegen-config)
import type { CodegenConfig } from '@graphql-codegen/cli';
const config: CodegenConfig = {
overwrite: true,
watch: false,
// ... other config ...
generates: {
'graphql/typings.ts': {
plugins: [
'typescript',
'typescript-validation-schema',
],
config: {
strictScalars: true,
schema: 'zod',
directives: {
array: {
unique: ['refine', (items) => new Set(items).size === items.length], // function passed as argument
},
},
},
},
},
};
export default config;
However, that directive configuration yields the following error:
My request is that the typescript-validation-schema package can support receiving functions as arguments for custom directive definitions.
Metadata
Metadata
Assignees
Labels
No labels