No input field null validation on non nullable fields

@MichelDiz

I think the problem here is that putting an ! at the end of a field in a schema seems to have no consequences. It should throw an error if that field does not exist. Quoting the GraphQL Specs:

Here, we’re using a String type and marking it as Non-Null by adding an exclamation mark, ! after the type name. This means that our server always expects to return a non-null value for this field, and if it ends up getting a null value that will actually trigger a GraphQL execution error, letting the client know that something has gone wrong.

The Non-Null type modifier can also be used when defining arguments for a field, which will cause the GraphQL server to return a validation error if a null value is passed as that argument, whether in the GraphQL string or in the variables

This is 100% a bug and needs to be fixed.

(Side not, the docs need to be updated as there is no mention of the effects of ! in dgraph graphql)


I don’t think we need another package to fix an internal problem. However, we could technically also solve the problem by using @auth rules:

type User @auth(
    add: { rule:  "queryPosts(filter: { has: [name, description] }) { id }",
    update: { rule: "won't work here..."
) {

However, as I stated in the below post, this will only work on add and not update, as they will easily be editable until we can create update rules based on the update after value as well as the update before value.

J

2 Likes