0

I have defined a mutation like below with email field marked as mandatory

type Mutation {
    bookTicket (person: PersonInput! ,email: String!): Ticket
}

input PersonInput{
    personId: ID!
    name: String!
    date: String!
    comment: String
}

When I try to execute the mutation through GraphIQl UI withou passing email field the UI doesn't throw validation error and the calls the endpoint with empty value for the email field .

mutation($personInput:PersonInput!, $email :String!){
    bookTicket(person:$personInput,email: $email){
        id
    }
}


Variables
{
    "personInput": {
        "personId": "111",
        "name": "test",
        "date": "10-Oct-2018",
        "comment": "Book"
    }

}

If I try to run the mutation with inline variables the validation works fine and shows exception that email cannot be empty .

 mutation{
     bookTicket(person:{personId: "111",  name: "test", date: "10-Oct- 
     2018",comment: "Book"}
     email:""){
        id
     }
 }

Can anyone help me on why the validation doesn't work in the first case ?

  • I'm not sure of what's going on, but maybe this info might be helpful in your investigation: An empty string will pass the mandatory check (String!), so, your 2nd example, the one where email has the value of "", would pass this validation check, and the error you're getting is probably thrown by business code? I couldn't reproduce the scenario of your 1st example, where email is not defined. That should definitely fail the validation check, and that's what I am experiencing on my tests. I get this error: "Field 'email' of variable 'email' has coerced Null value for NonNull type 'String!'" – felipe_gdr Oct 21 '18 at 09:03
  • 1
    thank you for the help ,I was able to resolve it by adding check in datafetcher , looks like issue was caused by some custom code which altered the default behavior . – VINEET TALEKAR Oct 23 '18 at 11:47

0 Answers0