diff --git a/app/_config/graphql.yml b/app/_config/graphql.yml deleted file mode 100644 index 82e35d2..0000000 --- a/app/_config/graphql.yml +++ /dev/null @@ -1,37 +0,0 @@ ---- -Name: app-graphql -After: - - app-basics -Only: - classexists: 'SilverStripe\GraphQL\Schema\Schema' ---- - -SilverStripe\Core\Injector\Injector: - SilverStripe\GraphQL\Schema\Registry\PluginRegistry: - constructor: - - 'App\GraphQL\URLLinkablePlugin' - -SilverStripe\Control\Director: - rules: - graphql: - Controller: '%$SilverStripe\GraphQL\Controller.default' - Schema: default - -SilverStripe\GraphQL\Schema\Schema: - schemas: - '*': - config: - max_query_nodes: 250 # default 500 - max_query_depth: 20 # default 15 - max_query_complexity: 200 # default unlimited - default: - src: - - app/_graphql - -SilverStripe\GraphQLDevTools\Controller: - # show two schemas - schemas: - - default - - admin - # default schema that is selected - default_schema: default diff --git a/app/_graphql/bulkLoad.yml b/app/_graphql/bulkLoad.yml deleted file mode 100644 index 6495612..0000000 --- a/app/_graphql/bulkLoad.yml +++ /dev/null @@ -1,16 +0,0 @@ -app: - # Load everything in our MyApp\Models\ namespace that has the Versioned extension - # unless the filename ends with .secret.php - load: - namespaceLoader: - include: - - App\Models\* - extensionLoader: - include: - - SilverStripe\Versioned\Versioned - apply: - fields: - '*': true - operations: - read: true - readOne: true diff --git a/app/_graphql/config.yml b/app/_graphql/config.yml deleted file mode 100644 index 56640f5..0000000 --- a/app/_graphql/config.yml +++ /dev/null @@ -1,30 +0,0 @@ -modelConfig: - Page: - plugins: - inheritance: true - operations: - read: - plugins: - readVersion: false - paginateList: false - readOne: - plugins: - getByLink: - after: filter - - DNADesign\Elemental\Models\ElementalArea: - plugins: - inheritance: true - operations: - read: - plugins: - readVersion: false - paginateList: false - DNADesign\Elemental\Models\BaseElement: - plugins: - inheritance: true - operations: - read: - plugins: - readVersion: false - paginateList: false diff --git a/app/_graphql/enums.yml b/app/_graphql/enums.yml deleted file mode 100644 index e69de29..0000000 diff --git a/app/_graphql/models.yml b/app/_graphql/models.yml deleted file mode 100644 index 495b044..0000000 --- a/app/_graphql/models.yml +++ /dev/null @@ -1,49 +0,0 @@ -Page: - fields: - id: true - className: true - urlSegment: true - parentID: true - title: true - sort: true - CSSClass: true - MainContent: - type: String - showInMenus: Boolean - showInSearch: Boolean - url: - type: String - link: - type: String - requestlink: - type: String - children: "[Page]" - elementalArea: - type: ElementalArea - operations: - read: true - readOne: - plugins: - getByLink: - after: filter - -DNADesign\Elemental\Models\ElementalArea: - fields: - id: true - elements: - plugins: - paginateList: false - operations: - read: true - readOne: true - -DNADesign\Elemental\Models\BaseElement: - fields: - id: true - title: true - showTitle: true - className: true - forTemplate: true - operations: - readOne: true - read: true diff --git a/app/_graphql/schema.yml b/app/_graphql/schema.yml deleted file mode 100644 index 9c996ac..0000000 --- a/app/_graphql/schema.yml +++ /dev/null @@ -1,4 +0,0 @@ -queries: - readMenu: - type: '[PageInterface]' - resolver: [ 'App\GraphQL\MenuResolver', 'resolveMenu' ] diff --git a/app/_graphql/types.yml b/app/_graphql/types.yml deleted file mode 100644 index e69de29..0000000 diff --git a/app/src/GraphQL/MenuResolver.php b/app/src/GraphQL/MenuResolver.php deleted file mode 100644 index 0e75353..0000000 --- a/app/src/GraphQL/MenuResolver.php +++ /dev/null @@ -1,37 +0,0 @@ -filter('ParentID', '0'); - $results = self::getFields($pages); - return $results; - } - - protected static function getFields($pages): array - { - $results = []; - foreach ($pages as $p) { - $results[] = [ - 'id' => $p->ID, - 'title' => $p->Title, - 'children' => self::getFields($p->Children()), - ]; - } - - return $results; - } -} diff --git a/app/src/GraphQL/URLLinkablePlugin.php b/app/src/GraphQL/URLLinkablePlugin.php deleted file mode 100644 index ef9cc23..0000000 --- a/app/src/GraphQL/URLLinkablePlugin.php +++ /dev/null @@ -1,277 +0,0 @@ -getModel()->getSourceClass(); - // Only site trees have the get_by_link capability - if ($class !== SiteTree::class && !is_subclass_of($class, SiteTree::class)) { - return; - } - $singleFieldName = $this->config()->get('single_field_name'); - $listFieldName = $this->config()->get('list_field_name'); - $fieldName = $query->isList() ? $listFieldName : $singleFieldName; - $type = $query->isList() ? '[String]' : 'String'; - $query->addArg($fieldName, $type); - $query->addResolverAfterware( - $config['resolver'] ?? static::config()->get('resolver') - ); - } - - /** - * @param array $context - * @return callable - */ - public static function applyURLFilter($obj, array $args, array $context, ResolveInfo $info) - { - $url = self::getURL($args); - if (!$url) { - return $obj; - } - - $controller = self::getURLController($url); - - $obj = $controller->data(); - $obj->GraphQLContent = self::RenderTemplate($obj, $controller); - - $result = ArrayList::create(); - $result->push($obj); - - return $result; - } - - protected static function getURL($args) - { - $singleFieldName = static::config()->get('single_field_name'); - $listFieldName = static::config()->get('list_field_name'); - - $filterLink = $args['filter'][$singleFieldName] ?? ($args['filter'][$listFieldName] ?? null); - $argLink = $args[$singleFieldName] ?? ($args[$listFieldName] ?? null); - - $linkData = $filterLink ?: $argLink; - if (!$linkData) { - return false; - } - - $url = $linkData['eq']; - if ($url === '/') { - return '/home'; - } - - return $url; - } - - protected static function getURLController($url) - { - $curr = Controller::curr(); - $req = clone $curr->getRequest(); - - $req->setUrl($url); - $req->match('$URLSegment//$Action/$ID/$OtherID', true); - - $controller = ModelAsController::create(); - $controller->setRequest($req); - - // ContentController - $result = $controller->getNestedController(); - $result->setRequest($req); - - /** @var SiteTree $child */ - $action = $req->param('Action'); - - if ($action) { - $child = self::findChild($action, $result); - if ($child) { - $result = $child; - } - } - - return $result; - } - - // look recursively for a child page with URLSegment - protected static function findChild($action, $controller) - { - $req = $controller->getRequest(); - - $child = SiteTree::get()->filter([ - 'ParentID' => $controller->ID, - 'URLSegment' => $action, - ])->first(); - - if ($child) { - $req->shiftAllParams(); - $req->shift(); - - $controller = ModelAsController::controller_for($child); - $controller->setRequest($req); - $action = $req->param('Action'); - - if ($action) { - return self::findChild($action, $controller); - } - } - - return $controller; - } - - // AJAX/GraphQL helper - protected static function RenderTemplate($page, $ctl) - { - $object = $page; - $req = $ctl->getRequest(); - $actionParam = $req->param('Action'); - - Director::set_current_page($object); - - $match = self::findAction($ctl, $req); - $req->match($match['rule'], true); - $action = $match['action']; - - $action = ($action === 'handleAction') ? $actionParam : $action; - - $action = $action && $ctl->hasAction($action) ? $action : 'index'; - - - // find templates - $tpl = 'Page'; - $tpls = SSViewer::get_templates_by_class($object->ClassName, '', \Page::class); - - foreach ($tpls as $tpl) { - if (is_array($tpl)) { - continue; - } - - $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)) { - $tpl = $a_tpl; - break; - } - } - // - - $tpl = is_array($tpl) ? 'Page' : $tpl; - $tpl = ($tpl !== 'Page') ? $tpl : 'Layout/Page'; - - // a little dirty way to make forms working - //Controller::curr()->config()->set('url_segment', $object->AbsoluteLink()); - //$ctl->doInit(); - - $mResult = $ctl->$action($req); - if (is_array($mResult) || is_a($mResult, ArrayData::class)) { - $ctl->customise($mResult); - } - - - $layout = $ctl->renderWith([$tpl.'_'.$action, $tpl]); - - return $ctl - ->customise(['Layout' => $layout]) - ->renderWith('GraphQLPage'); - } - - protected static function findAction($controller, $request) - { - $handlerClass = $controller::class; - - // We stop after RequestHandler; in other words, at ViewableData - while ($handlerClass && $handlerClass != ViewableData::class) { - $urlHandlers = Config::inst()->get($handlerClass, 'url_handlers', Config::UNINHERITED); - - if ($urlHandlers) { - foreach ($urlHandlers as $rule => $action) { - if (isset($_REQUEST['debug_request'])) { - $class = static::class; - $remaining = $request->remaining(); - Debug::message("Testing '{$rule}' with '{$remaining}' on {$class}"); - } - - if ($request->match($rule, true)) { - if (isset($_REQUEST['debug_request'])) { - $class = static::class; - $latestParams = var_export($request->latestParams(), true); - Debug::message( - "Rule '{$rule}' matched to action '{$action}' on {$class}. " . "Latest request params: {$latestParams}" - ); - } - - return [ - 'rule' => $rule, - 'action' => $action, - ]; - } - } - } - - $handlerClass = get_parent_class($handlerClass ?? ''); - } - return null; - } -} diff --git a/app/src/Pages/Page.php b/app/src/Pages/Page.php index 314b884..269b437 100644 --- a/app/src/Pages/Page.php +++ b/app/src/Pages/Page.php @@ -97,26 +97,6 @@ class Page extends SiteTree return str_replace(['\\'], '-', $this->getField('ClassName')); } - // AJAX/GraphQL helper - public function MainContent() - { - $object = $this; - return isset($object->GraphQLContent) ? $object->GraphQLContent : null; - } - - public function getRequestLink($action = null) - { - $curr = Controller::curr(); - if ($curr::class === GraphQLController::class) { - $vars = json_decode($curr->getRequest()->getBody(), true)['variables']; - if (isset($vars['url'])) { - return $vars['url']; - } - } - - return null; - } - protected function onBeforeWrite() { parent::onBeforeWrite();