Skip to content

Commit

Permalink
tests working
Browse files Browse the repository at this point in the history
  • Loading branch information
markhuot committed Jan 11, 2018
1 parent 7620809 commit 2bc9cab
Show file tree
Hide file tree
Showing 13 changed files with 68 additions and 173 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1,2 +1,3 @@
vendor
.DS_Store
.idea
2 changes: 1 addition & 1 deletion src/Builders/Field.php
Expand Up @@ -29,7 +29,7 @@ protected function boot() {
}

function addArgumentsByLayoutId(int $fieldLayoutId) {
$fieldService = \Yii::$container->get('fieldService');
$fieldService = \Yii::$container->get('craftQLFieldService');
$arguments = $fieldService->getMutationArguments($fieldLayoutId, $this->request, $this);
return $this->arguments = array_merge($this->arguments, $arguments);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Builders/Schema.php
Expand Up @@ -145,7 +145,7 @@ function addUnionField($field): BaseField {
}

function addFieldsByLayoutId(int $fieldLayoutId) {
$fieldService = \Yii::$container->get('fieldService');
$fieldService = \Yii::$container->get('craftQLFieldService');
$fields = $fieldService->getFields($fieldLayoutId, $this->request, $this);
return $this->fields = array_merge($this->fields, $fields);
}
Expand Down
24 changes: 12 additions & 12 deletions src/Console/ToolsController.php
Expand Up @@ -238,16 +238,16 @@ public function actionSeed()

$matrixField = new \craft\fields\Matrix();
$matrixField->groupId = $groupModel->id;
$matrixField->name = 'Body Enhanced';
$matrixField->handle = 'bodyEnhanced';
$matrixField->name = 'Rich Content';
$matrixField->handle = 'richContent';
$matrixField->required = false;
$matrixField->sortOrder = 0;
$matrixField->setBlockTypes([
'new1' => [
'name' => 'Text',
'handle' => 'text',
'fields' => [
[
'new1' => [
'type' => \craft\fields\PlainText::class,
'name' => 'Content',
'handle' => 'textContent',
Expand All @@ -260,14 +260,14 @@ public function actionSeed()
'name' => 'Related Cotnent',
'handle' => 'relatedContent',
'fields' => [
[
'new1' => [
'type' => \craft\fields\PlainText::class,
'name' => 'Heading',
'handle' => 'heading',
'instructions' => null,
'required' => false,
],
[
'new2' => [
'type' => \craft\fields\Entries::class,
'name' => 'Related Entry',
'handle' => 'matrixRelatedEntry',
Expand Down Expand Up @@ -327,12 +327,12 @@ public function actionSeed()
$categoryGroup->name = 'Story Types';
$categoryGroup->handle = 'storyTypes';
$categoryGroup->maxLevels = null;
$siteSettings = new \craft\models\CategoryGroup_SiteSettings();
$siteSettings->siteId = 1;
$siteSettings->hasUrls = true;
$siteSettings->uriFormat = 'type/{slug}';
$siteSettings->template = 'type/_story';
$categoryGroup->setSiteSettings([1 => $siteSettings]);
$groupSiteSettings = new \craft\models\CategoryGroup_SiteSettings();
$groupSiteSettings->siteId = 1;
$groupSiteSettings->hasUrls = true;
$groupSiteSettings->uriFormat = 'type/{slug}';
$groupSiteSettings->template = 'type/_story';
$categoryGroup->setSiteSettings([1 => $groupSiteSettings]);
Craft::$app->getCategories()->saveGroup($categoryGroup);

$categoryField = new \craft\fields\Categories();
Expand All @@ -359,7 +359,7 @@ public function actionSeed()
$entriesField,
$multiSelectField,
$assetsField,
// $matrixField,
$matrixField,
$emptyMatrixField,
$emptyMatrixBlockField,
$categoryField,
Expand Down
2 changes: 1 addition & 1 deletion src/FieldBehaviors/EntryMutationArguments.php
Expand Up @@ -53,7 +53,7 @@ function initEntryMutationArguments() {
unset($fields['typeId']);
unset($fields['authorId']);

$fieldService = \Yii::$container->get('fieldService');
$fieldService = \Yii::$container->get('craftQLFieldService');

foreach ($fields as $handle => &$value) {
$callback = $this->owner->getArgument($handle)->getOnSave();
Expand Down
23 changes: 20 additions & 3 deletions src/FieldBehaviors/EntryQueryArguments.php
Expand Up @@ -2,11 +2,14 @@

namespace markhuot\CraftQL\FieldBehaviors;

use markhuot\CraftQL\Builders\Field;
use yii\base\Behavior;
use GraphQL\Type\Definition\Type;

class EntryQueryArguments extends Behavior {

static $inputObjectType;

function initEntryQueryArguments() {
$this->owner->addStringArgument('after');
$this->owner->addIntArgument('ancestorOf');
Expand All @@ -32,8 +35,8 @@ function initEntryQueryArguments() {
$this->owner->addIntArgument('positionedBefore');
$this->owner->addStringArgument('postDate');
$this->owner->addIntArgument('prevSiblingOf');
// $this->owner->addStringArgument('relatedTo' => Type::listOf(static::relatedToInputObject()),
// $this->owner->addStringArgument('orRelatedTo' => Type::listOf(static::relatedToInputObject()),
$this->owner->addStringArgument('relatedTo')->lists()->type($this->relatedToInputObject());
$this->owner->addStringArgument('orRelatedTo')->lists()->type($this->relatedToInputObject());
$this->owner->addStringArgument('search');
$this->owner->addStringArgument('section')->lists()->type($this->owner->getRequest()->sections()->enum());
$this->owner->addIntArgument('siblingOf');
Expand All @@ -43,9 +46,23 @@ function initEntryQueryArguments() {
$this->owner->addStringArgument('type')->lists()->type($this->owner->getRequest()->entryTypes()->enum());
$this->owner->addStringArgument('uri');

$fieldService = \Yii::$container->get('fieldService');
$fieldService = \Yii::$container->get('craftQLFieldService');
$arguments = $fieldService->getQueryArguments($this->owner->getRequest());
$this->owner->addArguments($arguments, false);
}

function relatedToInputObject() {
if (!empty(static::$inputObjectType)) {
return static::$inputObjectType;
}

$type = $this->owner->createInputObjectType('RelatedToInputType');
$type->addIntField('element');
$type->addIntField('sourceElement');
$type->addIntField('targetElement');
$type->addStringField('field');
$type->addStringField('sourceLocale');
return static::$inputObjectType = $type;
}

}
3 changes: 2 additions & 1 deletion src/Listeners/GetAssetsFieldSchema.php
Expand Up @@ -8,6 +8,7 @@
use GraphQL\Type\Definition\InputObjectType;
use markhuot\CraftQL\Types\Volume;
use markhuot\CraftQL\Types\VolumeInterface;
use markhuot\CraftQL\Events\GetFieldSchema;

class GetAssetsFieldSchema
{
Expand All @@ -17,7 +18,7 @@ class GetAssetsFieldSchema
* @param \markhuot\CraftQL\Events\GetFieldSchema $event
* @return void
*/
function handle($event) {
function handle(GetFieldSchema $event) {
$event->handled = true;

$field = $event->sender;
Expand Down
10 changes: 9 additions & 1 deletion src/Listeners/GetDateFieldSchema.php
Expand Up @@ -17,7 +17,15 @@ function handle($event) {
$event->handled = true;

$event->schema->addDateField($event->sender);

$event->query->addStringArgument($event->sender);
$event->mutation->addIntArgument($event->sender);

// @TODO make this timezone aware. if you send a unixtime stamp it should be for GMT
$event->mutation->addIntArgument($event->sender)
// ->onSave(function($value) {
// var_dump($value);
// die;
// })
;
}
}
2 changes: 1 addition & 1 deletion src/Listeners/GetMatrixFieldSchema.php
Expand Up @@ -27,7 +27,7 @@ function handle($event) {
return ucfirst($field->handle).ucfirst($block->handle);
});

$fieldService = \Yii::$container->get('fieldService');
$fieldService = \Yii::$container->get('craftQLFieldService');

$blockTypes = $field->getBlockTypes();

Expand Down
2 changes: 1 addition & 1 deletion src/Plugin.php
Expand Up @@ -34,7 +34,7 @@ function init() {
}

// make sure there's only one instance of our field service
Craft::$container->setSingleton('fieldService', \markhuot\CraftQL\Services\FieldService::class);
Craft::$container->setSingleton('craftQLFieldService', \markhuot\CraftQL\Services\FieldService::class);

$headers = !empty($this->getSettings()->headers) && is_array($this->getSettings()->headers) ? $this->getSettings()->headers : [];

Expand Down
4 changes: 3 additions & 1 deletion src/Types/EntryDraftConnection.php
Expand Up @@ -11,7 +11,9 @@ class EntryDraftConnection extends EntryConnection {

function boot() {
parent::boot();
$this->getField('edges')->type(EntryDraftEdge::class);

$this->getField('edges')
->type(EntryDraftEdge::class);
}

}
134 changes: 0 additions & 134 deletions src/Types/Volume.php
Expand Up @@ -20,138 +20,4 @@ function getName(): string {
return ucfirst($this->context->handle).'Volume';
}

// /**
// * An input object (for argument lists) that controls how any
// * related elements are searched.
// *
// * @var InputObjectType
// */
// static $relatedToInputObject;

// static function baseInputArgs() {
// return [
// 'id' => ['type' => Type::int()],
// 'authorId' => ['type' => Type::int()],
// 'title' => ['type' => Type::string()],
// ];
// }

// /**
// * An input object to query entries by relationship
// *
// * @return InputObjectType
// */
// static function relatedToInputObject() {
// if (static::$relatedToInputObject) {
// return static::$relatedToInputObject;
// }

// return static::$relatedToInputObject = new InputObjectType([
// 'name' => 'RelatedTo',
// 'fields' => [
// 'element' => Type::id(),
// 'sourceElement' => Type::id(),
// 'targetElement' => Type::id(),
// 'field' => Type::string(),
// 'sourceLocale' => Type::string(),
// ],
// ]);
// }

static function args($request) {
return [
'after' => Type::string(),
'ancestorOf' => Type::int(),
'ancestorDist' => Type::int(),
'archived' => Type::boolean(),
'authorGroup' => Type::string(),
'authorGroupId' => Type::int(),
'authorId' => Type::listOf(Type::int()),
'before' => Type::string(),
'level' => Type::int(),
'localeEnabled' => Type::boolean(),
'descendantOf' => Type::int(),
'descendantDist' => Type::int(),
'fixedOrder' => Type::boolean(),
'id' => Type::listOf(Type::int()),
'limit' => Type::int(),
'site' => Type::string(),
'siteId' => Type::int(),
'nextSiblingOf' => Type::int(),
'offset' => Type::int(),
'order' => Type::string(),
'positionedAfter' => Type::id(),
'positionedBefore' => Type::id(),
'postDate' => Type::string(),
'prevSiblingOf' => Type::id(),
// 'relatedTo' => Type::listOf(static::relatedToInputObject()),
// 'orRelatedTo' => Type::listOf(static::relatedToInputObject()),
'search' => Type::string(),
'section' => Type::listOf($request->sections()->enum()),
'siblingOf' => Type::int(),
'slug' => Type::string(),
'status' => Type::string(),
'title' => Type::string(),
// 'type' => Type::listOf($request->entryTypes()->enum()),
'uri' => Type::string(),
];
}

// function getGraphQLMutationArgs($request) {
// $fieldService = \Yii::$container->get('fieldService');

// return array_merge(\markhuot\CraftQL\Types\Entry::baseInputArgs(), $fieldService->getGraphQLMutationArgs($this->config['craftType']->fieldLayoutId, $request));
// }

// function handle() {
// return $this->config['craftType']->handle;
// }

// function upsert($request) {
// return function ($root, $args) use ($request) {
// if (!empty($args['id'])) {
// $criteria = Entry::find();
// $criteria->id($args['id']);
// $entry = $criteria->one();
// if (!$entry) {
// throw new \Exception('Could not find an entry with id '.$args['id']);
// }
// }
// else {
// $entry = new Entry();
// $entry->sectionId = $this->config['craftType']->section->id;
// $entry->typeId = $this->config['craftType']->id;
// }

// if (isset($args['authorId'])) {
// $entry->authorId = $args['authorId'];
// }

// if (isset($args['title'])) {
// $entry->title = $args['title'];
// }

// $fields = $args;
// unset($fields['id']);
// unset($fields['title']);
// unset($fields['sectionId']);
// unset($fields['typeId']);
// unset($fields['authorId']);

// $fieldService = \Yii::$container->get('fieldService');

// foreach ($fields as $handle => &$value) {
// $field = Craft::$app->fields->getFieldByHandle($handle);
// $value = $fieldService->mutateValueForField($request, $field, $value, $entry);
// // $value = $field->upsert($value, $entry);
// }

// $entry->setFieldValues($fields);

// Craft::$app->elements->saveElement($entry);

// return $entry;
// };
// }

}

0 comments on commit 2bc9cab

Please sign in to comment.