Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 48 additions & 1 deletion src/Types/EntryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use markhuot\CraftQL\Builders\InterfaceBuilder;
use markhuot\CraftQL\FieldBehaviors\EntryQueryArguments;
use markhuot\CraftQL\Helpers\StringHelper;
use Craft;

class EntryInterface extends InterfaceBuilder {

Expand All @@ -26,13 +27,59 @@ function boot() {
$this->addStringField('uri');
$this->addStringField('url');

$this->addStringField('fullUri')
->resolve(function($root, $args) {
$site = Craft::$app->sites->getSiteById($root->siteId);
return $root->uri ? rtrim(
str_replace(
'__home__',
'',
str_replace(
'@web',
'',
$site->baseUrl . $root->uri
)
),
'/'
) : null;
});

$this->addField('site')->type(Site::class);

$this->addField('supportedSites')->lists()->type(Site::class)
->resolve(function ($root, $args) {
return array_map(function ($site) {
return Craft::$app->sites->getSiteById($site['siteId']);
}, $root['supportedSites']);
});

$this->addField('alternateEntries')->lists()->type(EntryInterfaceAlternate::class)
->resolve(function ($root, $args) {
return array_map(function ($site) use ($root) {
$entry = Craft::$app->entries->getEntryById($root->id, $site['siteId']);
return (object) [
'entry' => $entry,
'isSelf' => $root->siteId == $entry->siteId
];
}, $root['supportedSites']);
// return array_filter($allEntries, function($entry) {
// return $entry->enabled;
// });
});

$this->addStringField('language')
->resolve(function($root, $args) {
$site = Craft::$app->sites->getSiteById($root->siteId);
return $site->language;
});

if ($this->request->token()->can('query:sections')) {
$this->addField('section')->type(Section::class);
$this->addField('type')->type(EntryType::class);
}

$this->addField('ancestors')->lists()->type(EntryInterface::class);

$this->addField('children')
->lists()
->type(EntryInterface::class)
Expand Down
18 changes: 18 additions & 0 deletions src/Types/EntryInterfaceAlternate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace markhuot\CraftQL\Types;

use GraphQL\Type\Definition\ObjectType;
use GraphQL\Type\Definition\InterfaceType;
use GraphQL\Type\Definition\EnumType;
use GraphQL\Type\Definition\Type;
use markhuot\CraftQL\Builders\Schema;

class EntryInterfaceAlternate extends Schema {

function boot() {
$this->addField('entry')->type(EntryInterface::class);
$this->addBooleanField('isSelf')->nonNull();
}

}