Skip to content

Add non nullable types to return empty arrays for missing relations #2337

@sebastian-walter

Description

@sebastian-walter

According to the GraphQL specs it is possible to define non nullable types: http://facebook.github.io/graphql/October2016/#sec-Types.Non-Null

According to this source here, this can also be applied for lists: https://graphql.org/learn/schema/#lists-and-non-null

This feature is very helpful when dealing with missing relations, e.g. here:

{
      objectives(func: uid(XXXX))
          uid
          lead {
              uid
              fullName
    }
}

The query result looks currently like this:

  "data": {
    "objectives": [{
        "uid": "XXXXX"
    }]
},

But this would simplify the handling in the frontend since you don't have to deal with the undefined case anymore:

  "data": {
    "objectives": [{
         "uid": "XXXXX",
        "objective_lead": []
    }]
  },

Since this could be done by changing the schema, it would have no effect for existing users of dgraph.

Metadata

Metadata

Assignees

Labels

exp/beginnerSomething most people could solve.kind/enhancementSomething could be better.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions