Hi Guys,
i want to get a hooked page property into my graphql schema. Does anybody know how i can configure/implement this?
/* the examble from https://processwire.com/docs/modules/hooks/#how-can-i-add-a-new-property-via-a-hook */
wire()->addHookProperty('Page::intro', function($event) {
$page = $event->object;
$intro = substr(strip_tags($page->body), 0, 255);
$lastPeriodPos = strrpos($intro, '.');
if($lastPeriod !== false) $intro = substr($intro, 0, $lastPeriodPos);
$event->return = $intro;
});
I am playing around with the getQueryFields-Hook but I don't know what to do next:
wire()->addHookAfter('ProcessGraphQL::getQueryFields', function ($event) {
$types = $event->return;
foreach($types as $type) {
if($type['name'] === 'mytype') {
/** @var ObjectType $pageType */
$pageType = $type['type']->getField('list')->getType()->getOfType();
$fields = $pageType->getFields();
// ????
// and here i will add some fields
}
}
$event->return = $types;
});