NEW Generate description from class_description when scaffolding types from DataObject#633
Conversation
maxime-rainville
left a comment
There was a problem hiding this comment.
I considered allowing developers to override the description in their schema definition, but opted against it because it felt like subverting the class_description API. It would have look something like that.
SilverStripe\FrameworkTest\Model\Company:
description: "My overridden description"
fields: '*'
operations:
'*': true
I also considered provided description for the scaffolded queries and mutations, but opted against it because the description would have been so painfully obvious, it didn't seem worth it. e.g. readOneCompany: Retrieve a Company
| /** | ||
| * Implementors of this interface can provide a description for a model type | ||
| */ | ||
| interface ModelTypeDescription |
There was a problem hiding this comment.
This probably should be in SchemaModelInterface but that would be a breaking change.
| array_map('strtolower', $model->getBlacklistedFields()) : | ||
| []; | ||
|
|
||
| if ($model instanceof ModelTypeDescription) { |
There was a problem hiding this comment.
This mimics the approach above that is used with ModelBlacklist.
There was a problem hiding this comment.
Honestly, I didn't find any obviously great place to park those test. The existing tests don't seem to be targeted at specific classes.
…s from DataObject
5e06cf4 to
97f9aa9
Compare
|
|
||
| public function getTypeDescription(): ?string | ||
| { | ||
| return $this->dataObject->classDescription() ?? null; |
There was a problem hiding this comment.
| return $this->dataObject->classDescription() ?? null; | |
| return $this->dataObject->i18nClassDescription() ?? null; |
Unless there's a good reason to not use i18n here?
There was a problem hiding this comment.
Not overly fuss either way.
I would argue that the description in the GraphQL schema is more like developer doc than CMS user doc. We don't normally localise the dev doc.
We also don't provide a way to localise the description when manually defining types or queries.
types:
Monkey:
description: "This description will only be available in English and can't be translated."
fields:
name:
type: String
age:
type: Int
species:
type: StringIt's worth pointing out that the description is set when you build your schema. The description will then be stored in the .graphql-generated folder. So if Friedrich has his CMS locale set to German and decides to rebuild the schema, everyone else will get their GraphQL schema description in German whether they like or not.
| []; | ||
|
|
||
| if ($model instanceof ModelTypeDescription) { | ||
| $this->setDescription($model->getTypeDescription()); |
There was a problem hiding this comment.
Seems fine - if $config['description'] has been set this will be overridden in applyConfig which gives developers a way to override this if they super duper want to.
Description
Update the schema DatObject scaffolding logic to read the description from DataObjects and use that to populate the GraphQL schema description for the resulting types.
Manual testing steps
class_descriptionto a Test DataObject./dev/graphql/ideIssues
Pull request checklist