FIX: GraphQL is Missing

This commit is contained in:
Tony Air 2021-11-23 15:19:28 +02:00
parent 9a0c41500d
commit f9b9eb6f74
6 changed files with 104 additions and 92 deletions

View File

@ -1,8 +1,10 @@
<?php
namespace A2nt\CMSNiceties\GraphQL;
if (!class_exists('SilverStripe\GraphQL\TypeCreator', true)) {
return;
}
use GraphQL\Type\Definition\ResolveInfo;
use GraphQL\Type\Definition\Type;
@ -20,7 +22,7 @@ class ElementTypeCreator extends TypeCreator
public function fields()
{
return [
'_id' => ['type' => Type::nonNull(Type::id()),'resolve' => static function($object) {
'_id' => ['type' => Type::nonNull(Type::id()),'resolve' => static function ($object) {
return $object->ID;
}],
'ID' => ['type' => Type::nonNull(Type::id())],
@ -28,7 +30,7 @@ class ElementTypeCreator extends TypeCreator
'ParentID' => ['type' => Type::id()],
'Render' => [
'type' => Type::string(),
'resolve' => static function($object, array $args, $context, ResolveInfo $info) {
'resolve' => static function ($object, array $args, $context, ResolveInfo $info) {
return $object->getController()->forTemplate()->HTML();
}
],

View File

@ -1,8 +1,10 @@
<?php
namespace A2nt\CMSNiceties\GraphQL;
if (!class_exists('SilverStripe\GraphQL\TypeCreator', true)) {
return;
}
use GraphQL\Type\Definition\Type;
use SilverStripe\GraphQL\TypeCreator;

View File

@ -1,8 +1,10 @@
<?php
namespace A2nt\CMSNiceties\GraphQL;
if (!class_exists('SilverStripe\GraphQL\TypeCreator', true)) {
return;
}
use GraphQL\Type\Definition\ResolveInfo;
use GraphQL\Type\Definition\Type;
@ -32,25 +34,25 @@ class PageTypeCreator extends TypeCreator
->setSortableFields(['ID', 'Title']);
return [
'_id' => ['type' => Type::nonNull(Type::id()),'resolve' => static function($object) {
'_id' => ['type' => Type::nonNull(Type::id()),'resolve' => static function ($object) {
return $object->ID;
}],
'ID' => ['type' => Type::nonNull(Type::id())],
'Title' => ['type' => Type::string()],
'Content' => ['type' => Type::string()],
'Link' => ['type' => Type::string(), 'resolve' => static function($object) {
'Link' => ['type' => Type::string(), 'resolve' => static function ($object) {
return $object->Link();
}],
'URLSegment' => ['type' => Type::string()],
'ParentID' => ['type' => Type::id()],
'ClassName' => ['type' => Type::string()],
'CSSClass' => ['type' => Type::string(), 'resolve' => static function($object) {
'CSSClass' => ['type' => Type::string(), 'resolve' => static function ($object) {
return $object->CSSClass();
}],
'Summary' => ['type' => Type::string(), 'resolve' => static function($object) {
'Summary' => ['type' => Type::string(), 'resolve' => static function ($object) {
return $object->Summary();
}],
'HTML' => ['type' => Type::string(), 'resolve' => static function($object) {
'HTML' => ['type' => Type::string(), 'resolve' => static function ($object) {
// get action from request
$action = null;
@ -67,18 +69,18 @@ class PageTypeCreator extends TypeCreator
\Page::class
);
foreach ($tpls as $tpl){
if(is_array($tpl)){
foreach ($tpls as $tpl) {
if (is_array($tpl)) {
continue;
}
$a_tpl = explode('\\',$tpl);
$a_tpl = explode('\\', $tpl);
$last_name = array_pop($a_tpl);
$a_tpl[] = 'Layout';
$a_tpl[] = $last_name;
$a_tpl = implode('\\', $a_tpl);
if(SSViewer::hasTemplate($a_tpl)){
if (SSViewer::hasTemplate($a_tpl)) {
break;
}
}
@ -109,7 +111,7 @@ class PageTypeCreator extends TypeCreator
'Elements' => [
'type' => $elementsConnection->toType(),
'args' => $elementsConnection->args(),
'resolve' => static function($object, array $args, $context, ResolveInfo $info) use ($elementsConnection) {
'resolve' => static function ($object, array $args, $context, ResolveInfo $info) use ($elementsConnection) {
return $elementsConnection->resolveList(
$object->ElementalArea()->Elements(),
$args,

View File

@ -1,8 +1,10 @@
<?php
namespace A2nt\CMSNiceties\GraphQL;
if (!class_exists('SilverStripe\GraphQL\Pagination\PaginatedQueryCreator', true)) {
return;
}
use GraphQL\Type\Definition\ResolveInfo;
use GraphQL\Type\Definition\Type;

View File

@ -1,8 +1,10 @@
<?php
namespace A2nt\CMSNiceties\GraphQL;
if (!class_exists('SilverStripe\GraphQL\Pagination\PaginatedQueryCreator', true)) {
return;
}
use GraphQL\Type\Definition\ResolveInfo;
use GraphQL\Type\Definition\Type;
@ -31,7 +33,7 @@ class PaginatedReadPagesQueryCreator extends PaginatedQueryCreator
if (isset($args['Link'])) {
$link = $args['Link'];
if(SiteTree::has_extension('\TractorCow\Fluent\Extension\FluentSiteTreeExtension')) {
if (SiteTree::has_extension('\TractorCow\Fluent\Extension\FluentSiteTreeExtension')) {
$arr = array_filter(explode('/', $args['Link']));
$locale = \TractorCow\Fluent\Model\Locale::get()->filter('URLSegment', array_shift($arr))->first();

View File

@ -1,8 +1,10 @@
<?php
namespace A2nt\CMSNiceties\GraphQL;
if (!class_exists('SilverStripe\GraphQL\QueryCreator', true)) {
return;
}
use GraphQL\Type\Definition\ResolveInfo;
use GraphQL\Type\Definition\Type;