Hi there, just wanted to bump this thread a bit as I think it deserves more attention.
Let’s assume my application is deployed with a “finished” schema and dgraph is running successfully doing it’s thing.
Now we can push new features in very short timeframes like we could never do before (because dgraph-gql is just awesome). New features will ultimately almost always bring new data to the database.
Now of course I could set the default values in the application layer. This however is error prone and in every new *.tsx I write I have to remember for which fields of which types I have to define default values. This can get out of hands very quickly.
Secondly, assume this schema:
type UserPermissions {
...
canUseFeatures: [String!]! # new field
}
So, I added the field canUseFeatures to my type which is required (!). When I migrate this schema to my existing database, currently all existing nodes will have null on that field. Querying those nodes will result in error: canUseFeatures has to be specified! (or something along these lines). The graphql schema validation fails.
Therefore, I once again propose to add a @default directive that is either used to:
- Set the corresponding field when the client is not specifying a value in the
addTypemutation - Set the corresponding field to the default value for all existing nodes of the type in question.