So we would have three options here going forward:
Option A:
directive @default(value: AllowedTypes!) on FIELD_DEFINITION
type Foo {
bar: String! @default(value: "helloworld")
}
Generated mutation:
type Mutation {
addFoo(bar: String): Foo #note that bar is optional
}
If no bar
is specified when adding new nodes (or for existing nodes that didn’t have this field), the query:
query {
queryFoo {
bar
}
}
will return:
{
QueryFoo: [
{
bar: "helloworld"
},
{
bar: "helloworld"
}
]
}
Option B:
directive @default(value: AllowedTypes!) on FIELD
type Foo {
bar: String!
}
Query:
query {
queryFoo {
bar @default(value: "lol")
}
}
This would allow for more flexibility (i.e. different default values in different environments).
Option C:
Both! Combine the ease of mind of Option A with the flexibility of Option B. We just have to figure out good names for the directives then.
Opinions?
@pawan did you have time to discuss this internally?