mmacneil / ASPNetCoreGraphQL

Sample project demonstrating a GraphQL service built with ASP.NET Core 2.2, Entity Framework Core and graphql-dotnet.
https://fullstackmark.com/post/17/building-a-graphql-api-with-aspnet-core-2-and-entity-framework-core
MIT License
265 stars 123 forks source link

Adding player with non-nullable data is allowed! #4

Open omar84 opened 5 years ago

omar84 commented 5 years ago

adding a player with mutation:

mutation ($player: PlayerInput!){
  createPlayer(player: $player){
    id
    name
    birthDate
  }
}

and variables:

{
  "player":{
    "name":"test"
  }
}

creates the player, with no validation for any field.

then reading the player generates the following error:

{
  "data": {
    "player": {
      "name": "test",
      "birthDate": "0001-01-01",
      "birthPlace": null,
      "weightLbs": 0
    }
  },
  "errors": [
    {
      "message": "GraphQL.ExecutionError: Cannot return null for non-null type. Field: birthPlace, Type: String!.\r\n   at GraphQL.Execution.ExecutionStrategy.ValidateNodeResult(ExecutionContext context, ExecutionNode node)\r\n   at GraphQL.Execution.ExecutionStrategy.ExecuteNodeAsync(ExecutionContext context, ExecutionNode node)",
      "locations": [
        {
          "line": 5,
          "column": 5
        }
      ],
      "path": [
        "player",
        "birthPlace"
      ]
    }
  ]
}

can you add validation please so that bad data can not be saved?