Currently the scaffolder relies on introspection for computed "fields", (i.e. custom getters) that are exposed on graphql dataobject types. This introspection is quite crude, and relies on these functions being deterministic, when they often are not. The scaffolder invokes the method on a singleton and checks the return type. In many instances, with a singleton lacking so much state, these getters return null, or some other primitive value that isn't really what the schema should be using, for instance:
public function getPrimaryCategory()
{
return $this->Categories()->filter('Featured', true)->first();
}
A singleton will return null in this case, but clearly the intention is that in the schema this field is represented as a Category.
Possible solutions
Expand the fields setting to deeper nesting (currently Name: Description map)
fields:
Title:
description: The title of the product
type: String
PrimaryCategory:
type: MyApp\Category
- NonSpecificField #Relies on introspection
Or... Stop treating getters as implicit fields, and create a new setting for them
fields:
- Title
- Content
computed:
PrimaryCategory: MyApp\Category
Currently the scaffolder relies on introspection for computed "fields", (i.e. custom getters) that are exposed on graphql dataobject types. This introspection is quite crude, and relies on these functions being deterministic, when they often are not. The scaffolder invokes the method on a singleton and checks the return type. In many instances, with a singleton lacking so much state, these getters return null, or some other primitive value that isn't really what the schema should be using, for instance:
A singleton will return null in this case, but clearly the intention is that in the schema this field is represented as a
Category
.Possible solutions
fields
setting to deeper nesting (currently Name: Description map)PRs