diff --git a/src/Types/CategoryGroup.php b/src/Types/CategoryGroup.php index 4339ac44..049af914 100644 --- a/src/Types/CategoryGroup.php +++ b/src/Types/CategoryGroup.php @@ -11,15 +11,16 @@ class CategoryGroup extends ObjectType { static $type; function __construct($group, $token) { - $fieldService = \Yii::$container->get(\markhuot\CraftQL\Services\FieldService::class); - $fields = array_merge(\markhuot\CraftQL\Types\Category::baseFields(), $fieldService->getFields($group->fieldLayoutId, $token)); - parent::__construct([ 'name' => ucfirst($group->handle).'Category', 'interfaces' => [ \markhuot\CraftQL\Types\Category::interface() ], - 'fields' => $fields, + 'fields' => function () use ($group, $token) { + $fieldService = \Yii::$container->get(\markhuot\CraftQL\Services\FieldService::class); + $fields = array_merge(\markhuot\CraftQL\Types\Category::baseFields(), $fieldService->getFields($group->fieldLayoutId, $token)); + return $fields; + }, 'id' => $group->id, ]); }