GraphQL error: Non-nullable field was not present in result from Dgraph

I tend to disagree with this. I believe that there should be a distinguishing factor between a type that generates required inputs and a type that generates required fields.

If this is only supported by a custom mutation then all generated mutations for types that reference this type may allow invalid input.

type Post {
  id: ID
  title: String
  author: Person!
}

This would correctly prevent from adding a new post if I did not supply the author, but it would also throw errors if I am authorized to query the post, but am restricted from querying the Person.


Since a developer cannot control the generated inputs outside of @search, I propose a change that all required fields are only used for generated input types and the generated schema types do not have any required fields.

This would not be a breaking change in that any where a field in the input schema is marked as required should still be there in the responses unless there are unique cases as above, which the developer can code around without having to handle erroneous errors.

I propose the generated input for the schema above should make the following changes:

type Post {
  id: ID
  title: String
  author(filter: PersonFilter): Person # notice not required
}
input AddPostInput {
  title: String
  author: PersonRef! # notice still required
}

I am thinking this could be done somewhat simply when generating the schema for any type or interface object remove all exclamation marks ! after the inputs have been generated.

@pawan what do you think?