File tree Expand file tree Collapse file tree 2 files changed +52
-4
lines changed Expand file tree Collapse file tree 2 files changed +52
-4
lines changed Original file line number Diff line number Diff line change @@ -8,4 +8,32 @@ generates:
8
8
plugins :
9
9
- ./dist/main/index.js :
10
10
schema : yup
11
- importFrom : ./types
11
+ importFrom : ./types
12
+ directives :
13
+ required :
14
+ msg : required
15
+ # This is example using constraint directive.
16
+ # see: https://github.com/confuser/graphql-constraint-directive
17
+ constraint :
18
+ minLength : min # same as ['min', '$1']
19
+ maxLength : max
20
+ startsWith : ["matches", "/^$1/"]
21
+ endsWith : ["matches", "/$1$/"]
22
+ contains : ["matches", "/$1/"]
23
+ notContains : ["matches", "/^((?!$1).)*$/"]
24
+ pattern : ["matches", "/$1/"]
25
+ format :
26
+ # For example, `@constraint(format: "uri")`. this case $1 will be "uri".
27
+ # Therefore the generator generates yup schema `.url()` followed by `uri: 'url'`
28
+ # If $1 does not match anywhere, the generator will ignore.
29
+ uri : url
30
+ email : email
31
+ uuid : uuid
32
+ # yup does not have `ipv4` API. If you want to add this,
33
+ # you need to add the logic using `yup.addMethod`.
34
+ # see: https://github.com/jquense/yup#addmethodschematype-schema-name-string-method--schema-void
35
+ ipv4 : ipv4
36
+ min : ["min", "$1 - 1"]
37
+ max : ["max", "$1 + 1"]
38
+ exclusiveMin : min
39
+ exclusiveMax : max
Original file line number Diff line number Diff line change @@ -57,8 +57,8 @@ enum EventOptionType {
57
57
}
58
58
59
59
input EventArgumentInput {
60
- name : String !
61
- value : String !
60
+ name : String ! @constraint ( minLength : 5 )
61
+ value : String ! @constraint ( startsWith : " foo " )
62
62
}
63
63
64
64
input HTTPInput {
@@ -72,4 +72,24 @@ enum HTTPMethod {
72
72
}
73
73
74
74
scalar Date
75
- scalar URL
75
+ scalar URL
76
+
77
+ # https://github.com/confuser/graphql-constraint-directive
78
+ directive @constraint (
79
+ # String constraints
80
+ minLength : Int
81
+ maxLength : Int
82
+ startsWith : String
83
+ endsWith : String
84
+ contains : String
85
+ notContains : String
86
+ pattern : String
87
+ format : String
88
+ # Number constraints
89
+ min : Float
90
+ max : Float
91
+ exclusiveMin : Float
92
+ exclusiveMax : Float
93
+ multipleOf : Float
94
+ uniqueTypeName : String
95
+ ) on INPUT_FIELD_DEFINITION | FIELD_DEFINITION
You can’t perform that action at this time.
0 commit comments