@@ -1064,6 +1064,71 @@ module.exports.test = function (setup, implType) {
1064
1064
} )
1065
1065
} )
1066
1066
1067
+ describe ( 'other directives' , function ( ) {
1068
+ const query = `mutation createBook($input: BookInput, $skipTest: Boolean!) {
1069
+ createBook(input: $input) {
1070
+ title @skip(if: $skipTest)
1071
+ }
1072
+ }`
1073
+
1074
+ before ( async function ( ) {
1075
+ this . typeDefs = `
1076
+ type Query {
1077
+ books: [Book]
1078
+ }
1079
+ type Book {
1080
+ title: String
1081
+ }
1082
+ type Mutation {
1083
+ createBook(input: BookInput): Book
1084
+ }
1085
+ input BookInput {
1086
+ title: String! @constraint(minLength: 3)
1087
+ }`
1088
+
1089
+ this . request = await setup ( this . typeDefs )
1090
+ } )
1091
+
1092
+ it ( 'should pass' , async function ( ) {
1093
+ const { body, statusCode } = await this . request
1094
+ . post ( '/graphql' )
1095
+ . set ( 'Accept' , 'application/json' )
1096
+ . send ( { query, variables : { input : { title : 'he💩' } , skipTest : false } } )
1097
+
1098
+ strictEqual ( statusCode , 200 )
1099
+ deepStrictEqual ( body , { data : { createBook : null } } )
1100
+ } )
1101
+
1102
+ it ( 'should fail' , async function ( ) {
1103
+ const { body, statusCode } = await this . request
1104
+ . post ( '/graphql' )
1105
+ . set ( 'Accept' , 'application/json' )
1106
+ . send ( { query, variables : { input : { title : 'a💩' } , skipTest : false } } )
1107
+
1108
+ isStatusCodeError ( statusCode , implType )
1109
+ strictEqual ( body . errors [ 0 ] . message ,
1110
+ 'Variable "$input" got invalid value "a💩" at "input.title"' + valueByImplType ( implType , '; Expected type "title_String_NotNull_minLength_3"' ) + '. Must be at least 3 characters in length' )
1111
+ } )
1112
+
1113
+ if ( isSchemaWrapperImplType ( implType ) ) {
1114
+ it ( 'should throw custom error' , async function ( ) {
1115
+ const request = await setup ( this . typeDefs , formatError )
1116
+ const { body, statusCode } = await request
1117
+ . post ( '/graphql' )
1118
+ . set ( 'Accept' , 'application/json' )
1119
+ . send ( { query, variables : { input : { title : 'a💩' } , skipTest : false } } )
1120
+
1121
+ strictEqual ( statusCode , 400 )
1122
+ deepStrictEqual ( body . errors [ 0 ] , {
1123
+ message : 'Must be at least 3 characters in length' ,
1124
+ code : 'ERR_GRAPHQL_CONSTRAINT_VALIDATION' ,
1125
+ fieldName : 'title' ,
1126
+ context : [ { arg : 'minLength' , value : 3 } ]
1127
+ } )
1128
+ } )
1129
+ }
1130
+ } )
1131
+
1067
1132
if ( isSchemaWrapperImplType ( implType ) ) {
1068
1133
describe ( '#uniqueTypeName' , function ( ) {
1069
1134
before ( async function ( ) {
0 commit comments