File tree Expand file tree Collapse file tree 2 files changed +16
-6
lines changed Expand file tree Collapse file tree 2 files changed +16
-6
lines changed Original file line number Diff line number Diff line change @@ -3,10 +3,10 @@ import {
33 ConstDirectiveNode ,
44 ConstValueNode ,
55 Kind ,
6- NameNode ,
76 valueFromASTUntyped ,
87} from "graphql" ;
98import { DirectiveConfig , DirectiveObjectArguments } from "./config" ;
9+ import { isConvertableRegexp } from "./regexp" ;
1010
1111export interface FormattedDirectiveConfig {
1212 [ directive : string ] : FormattedDirectiveArguments ;
@@ -22,7 +22,8 @@ export interface FormattedDirectiveObjectArguments {
2222
2323const isFormattedDirectiveObjectArguments = (
2424 arg : FormattedDirectiveArguments [ keyof FormattedDirectiveArguments ]
25- ) : arg is FormattedDirectiveObjectArguments => arg !== undefined && ! Array . isArray ( arg ) ;
25+ ) : arg is FormattedDirectiveObjectArguments =>
26+ arg !== undefined && ! Array . isArray ( arg ) ;
2627
2728// ```yml
2829// directives:
@@ -205,8 +206,13 @@ const stringify = (arg: any, quoteString?: boolean): string => {
205206 if ( Array . isArray ( arg ) ) {
206207 return arg . map ( ( v ) => stringify ( v , true ) ) . join ( "," ) ;
207208 }
208- if ( quoteString && typeof arg === "string" ) {
209- return JSON . stringify ( arg ) ;
209+ if ( typeof arg === "string" ) {
210+ if ( isConvertableRegexp ( arg ) ) {
211+ return arg ;
212+ }
213+ if ( quoteString ) {
214+ return JSON . stringify ( arg ) ;
215+ }
210216 }
211217 if (
212218 typeof arg === "boolean" ||
Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ import {
1313 indent ,
1414} from "@graphql-codegen/visitor-plugin-common" ;
1515import { TsVisitor } from "@graphql-codegen/typescript" ;
16+ import { buildApi , formatDirectiveConfig } from "../directive" ;
1617
1718const importYup = `import * as yup from 'yup'` ;
1819
@@ -112,13 +113,16 @@ const generateInputObjectFieldYupSchema = (
112113 field : InputValueDefinitionNode ,
113114 indentCount : number
114115) : string => {
115- // TOOD(codehex): handle directive
116- const gen = generateInputObjectFieldTypeYupSchema (
116+ let gen = generateInputObjectFieldTypeYupSchema (
117117 config ,
118118 tsVisitor ,
119119 schema ,
120120 field . type
121121 ) ;
122+ if ( config . directives && field . directives ) {
123+ const formatted = formatDirectiveConfig ( config . directives ) ;
124+ gen += buildApi ( formatted , field . directives ) ;
125+ }
122126 return indent (
123127 `${ field . name . value } : ${ maybeLazy ( field . type , gen ) } ` ,
124128 indentCount
You can’t perform that action at this time.
0 commit comments