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 {
3
3
ConstDirectiveNode ,
4
4
ConstValueNode ,
5
5
Kind ,
6
- NameNode ,
7
6
valueFromASTUntyped ,
8
7
} from "graphql" ;
9
8
import { DirectiveConfig , DirectiveObjectArguments } from "./config" ;
9
+ import { isConvertableRegexp } from "./regexp" ;
10
10
11
11
export interface FormattedDirectiveConfig {
12
12
[ directive : string ] : FormattedDirectiveArguments ;
@@ -22,7 +22,8 @@ export interface FormattedDirectiveObjectArguments {
22
22
23
23
const isFormattedDirectiveObjectArguments = (
24
24
arg : FormattedDirectiveArguments [ keyof FormattedDirectiveArguments ]
25
- ) : arg is FormattedDirectiveObjectArguments => arg !== undefined && ! Array . isArray ( arg ) ;
25
+ ) : arg is FormattedDirectiveObjectArguments =>
26
+ arg !== undefined && ! Array . isArray ( arg ) ;
26
27
27
28
// ```yml
28
29
// directives:
@@ -205,8 +206,13 @@ const stringify = (arg: any, quoteString?: boolean): string => {
205
206
if ( Array . isArray ( arg ) ) {
206
207
return arg . map ( ( v ) => stringify ( v , true ) ) . join ( "," ) ;
207
208
}
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
+ }
210
216
}
211
217
if (
212
218
typeof arg === "boolean" ||
Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ import {
13
13
indent ,
14
14
} from "@graphql-codegen/visitor-plugin-common" ;
15
15
import { TsVisitor } from "@graphql-codegen/typescript" ;
16
+ import { buildApi , formatDirectiveConfig } from "../directive" ;
16
17
17
18
const importYup = `import * as yup from 'yup'` ;
18
19
@@ -112,13 +113,16 @@ const generateInputObjectFieldYupSchema = (
112
113
field : InputValueDefinitionNode ,
113
114
indentCount : number
114
115
) : string => {
115
- // TOOD(codehex): handle directive
116
- const gen = generateInputObjectFieldTypeYupSchema (
116
+ let gen = generateInputObjectFieldTypeYupSchema (
117
117
config ,
118
118
tsVisitor ,
119
119
schema ,
120
120
field . type
121
121
) ;
122
+ if ( config . directives && field . directives ) {
123
+ const formatted = formatDirectiveConfig ( config . directives ) ;
124
+ gen += buildApi ( formatted , field . directives ) ;
125
+ }
122
126
return indent (
123
127
`${ field . name . value } : ${ maybeLazy ( field . type , gen ) } ` ,
124
128
indentCount
You can’t perform that action at this time.
0 commit comments