Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Imager #232

Open
wants to merge 11 commits into
base: 2.x
Choose a base branch
from
Open
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## dev-master

- (none)
- Added Imager support

## 1.3.1 - 2019-01-29

Expand Down
167 changes: 167 additions & 0 deletions seeds/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ type BlogPost implements EntryInterface, ElementInterface {
testTableField: [TestTableFieldTable]
testUrlField: String
testAssetsField(filename: String, fixedOrder: Boolean, folderId: Int, height: Int, id: Int, kind: String, limit: Int, locale: String, offset: Int, order: String, search: String, size: Int, title: String, sourceId: Int, width: Int, testBlockCheckboxesField: TestBlockCheckboxesFieldEnum, testBlockPlainTextField: String, testBlockTableField: String, testCategoryField: String, testCategoryNestingField: String, testCheckboxes: TestCheckboxesEnum, testCheckboxesWithOneBadValue: TestCheckboxesWithOneBadValueEnum, testDateAndTimeField: String, testDateField: String, testDropdownField: TestDropdownFieldEnum, testEmailField: String, testLightswitchField: Boolean, testLightswitchOnField: Boolean, testMultiSelectField: TestMultiSelectFieldEnum, testNumberField: Int, testNumberFloatField: Float, testNumberMaxField: Int, testPlainText: String, testPlainTextWithCharacterLimit: String, testRadioButtonField: TestRadioButtonFieldEnum, testTableField: String, testTagField: Int, testTimeField: String, testUrlField: String): [VolumeInterface]
testAssetsFieldImager: [ImagerTransformedImages]
testCategoryField: [TestCategoryGroupCategory]
testCategoryFieldConnection: CategoryConnection
testCategoryNestingField: [TestNestedCategoryGroupCategory]
Expand Down Expand Up @@ -297,6 +298,172 @@ type GlobalsSet {
testSecondGlobalSet: TestSecondGlobalSet
}

enum ImagerBlendModeEnum {
blend
darken
lighten
modulate
multiply
overlay
screen
}

enum ImagerChannelEnum {
red
green
blue
}

input ImagerColorBlendEffect {
color: String
opacity: Float
}

enum ImagerDitherEnum {
no
riemersma
floydsteinberg
}

input ImagerEffects {
grayscale: Boolean
negative: Boolean
blur: Float
sharpen: Boolean
gamma: Float
colorize: String
colorBlend: ImagerColorBlendEffect
tint: [ImagerTintEffect]
sepia: Int
contrast: Float
modulate: [Int]
normalize: Boolean
contrastStretch: [Float]
posterize: ImagerPosterizeEffect
unsharpMask: [Float]
clut: String
quantize: [Int]
levels: ImagerLevelsEffect
}

enum ImagerFormatEnum {
jpg
png
gif
webp
}

enum ImagerInterlaceEnum {
none
line
plane
partition
}

input ImagerLevelsEffect {
blackPoint: Float
gamma: Float
whitePoint: Float
channel: ImagerChannelEnum
}

enum ImagerModeEnum {
crop
fit
stretch
croponly
letterbox
}

input ImagerPosterizeEffect {
levels: Float
dither: ImagerDitherEnum
}

enum ImagerResizeFilterEnum {
point
box
triangle
hermite
hanning
hamming
blackman
gaussian
quadratic
cubic
catrom
mitchell
lanczos
bessel
sinc
}

enum ImagerSilhouetteTypeEnum {
curve
}

input ImagerTintEffect {
color: String
}

input ImagerTransformOptions {
format: ImagerFormatEnum
width: Int
height: Int
ratio: Float
position: String
ignoreFocalPoint: Boolean
mode: ImagerModeEnum
cropZoom: Float
frames: String
jpegQuality: Int
pngCompressionLevel: Int
webpQuality: Int
allowUpscale: Boolean
resizeFilter: ImagerResizeFilterEnum
interlace: ImagerInterlaceEnum
watermark: ImagerWatermark
effects: ImagerEffects
preEffects: ImagerEffects
}

type ImagerTransformedImageModel {
url: String
path: String
extension: String
mimetype: String
width: String
height: String
size: String
}

type ImagerTransformedImages {
images(transforms: [ImagerTransformOptions]!): [ImagerTransformedImageModel]
placeholder(type: ImagerTypeEnum, width: Int, height: Int, color: String, fgColor: String, size: String, silhouetteType: ImagerSilhouetteTypeEnum): String
}

enum ImagerTypeEnum {
svg
gif
silhouette
}

input ImagerWatermark {
image: String
width: Int
height: Int
opacity: Int
blendMode: ImagerBlendModeEnum
position: ImagerWatermarkPosition
}

input ImagerWatermarkPosition {
left: Int
right: Int
top: Int
bottom: Int
}

type MultiOptionFieldData {
selected: [OptionFieldDataOptions]
options: [OptionFieldDataOptions]
Expand Down
8 changes: 6 additions & 2 deletions src/Builders/EnumField.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@

namespace markhuot\CraftQL\Builders;

use markhuot\CraftQL\Request;

class EnumField extends Field {

function boot() {
function __construct(Request $request, string $name, string $prefix='') {
parent::__construct($request, $name);

$this->type = (new EnumObject($this->request))
->name(ucfirst($this->getName()).'Enum');
->name($prefix.ucfirst($this->getName()).'Enum');
$this->request->registerType($this->type->getName(), $this->type);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Builders/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ class Field extends BaseBuilder {
function __construct(Request $request, string $name) {
$this->request = $request;
$this->name = $name;
$this->boot();
}

protected function boot() {
Expand Down Expand Up @@ -53,6 +52,7 @@ function createInputObjectType($name): InputSchema {
}

function getConfig() {
$this->boot();
$type = $this->getTypeConfig();

if ($this->isList) {
Expand Down
6 changes: 3 additions & 3 deletions src/Builders/HasArgumentsAttribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,13 @@ function addDateArgument($name): Argument {
return $this->addArgument($name)->type($this->request->getType('Timestamp'));
}

function addEnumArgument($name): EnumField {
function addEnumArgument($name, $prefix=''): EnumField {
if (is_a($name, CraftField::class)) {
return $this->arguments[] = (new EnumField($this->request, $name->handle))
return $this->arguments[] = (new EnumField($this->request, $name->handle, $prefix))
->description($name->instructions);
}

return $this->arguments[] = (new EnumField($this->request, $name));
return $this->arguments[] = (new EnumField($this->request, $name, $prefix));
}

function getArguments(): array {
Expand Down
7 changes: 6 additions & 1 deletion src/Builders/InputSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class InputSchema extends BaseBuilder {

protected static $objects;

function __construct($request, $name) {
function __construct($request, $name=null) {
$this->request = $request;
$this->name = $name;
}
Expand Down Expand Up @@ -40,7 +40,12 @@ function createInputObjectType($name): InputSchema {
return $inputSchema;
}

function boot() {

}

function getArguments() {
$this->boot();
$this->bootBehaviors();
return $this->getArgumentConfig();
}
Expand Down
6 changes: 3 additions & 3 deletions src/Builders/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,13 @@ function addFloatField($field): BaseField {
return $this->addField($field)->type(Type::float());
}

function addEnumField($field): BaseField {
function addEnumField($field, $prefix=''): BaseField {
if (is_a($field, CraftField::class)) {
return $this->fields[] = (new EnumField($this->request, $field->handle))
return $this->fields[] = (new EnumField($this->request, $field->handle, $prefix))
->description($field->instructions);
}

return $this->fields[] = new EnumField($this->request, $field);
return $this->fields[] = new EnumField($this->request, $field, $prefix);
}

function addDateField($field): BaseField {
Expand Down
5 changes: 4 additions & 1 deletion src/Builders/UnionField.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
use GraphQL\Type\Definition\Type;
use GraphQL\Type\Definition\ObjectType;
use GraphQL\Type\Definition\UnionType;
use markhuot\CraftQL\Request;

class UnionField extends Field {

function boot() {
function __construct(Request $request, string $name) {
parent::__construct($request, $name);

$this->type = (new Union($this->request))
->name(ucfirst($this->getName()).'Union');
$this->request->registerType($this->type->getName(), $this->type);
Expand Down
7 changes: 7 additions & 0 deletions src/Events/GetFieldSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,11 @@ class GetFieldSchema extends Event {
*/
public $mutation;

/**
* Whether the event should continue to the default field handler
*
* @var bool
*/
public $preventDefault = false;

}
2 changes: 1 addition & 1 deletion src/Listeners/GetAssetsFieldSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class GetAssetsFieldSchema
* @return void
*/
function handle(GetFieldSchema $event) {
$event->handled = true;
$event->preventDefault = true;

$field = $event->sender;
$schema = $event->schema;
Expand Down
2 changes: 1 addition & 1 deletion src/Listeners/GetCategoriesFieldSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class GetCategoriesFieldSchema
* @return void
*/
function handle(GetFieldSchema $event) {
$event->handled = true;
$event->preventDefault = true;

$field = $event->sender;

Expand Down
2 changes: 1 addition & 1 deletion src/Listeners/GetColorFieldSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class GetColorFieldSchema
* @return void
*/
function handle($event) {
$event->handled = true;
$event->preventDefault = true;

$color = $event->schema->createObjectType('Color');
$color->addStringField('hex')->resolve(function (ColorData $root) { return $root->getHex(); });
Expand Down
2 changes: 1 addition & 1 deletion src/Listeners/GetDateFieldSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class GetDateFieldSchema
* @return void
*/
function handle($event) {
$event->handled = true;
$event->preventDefault = true;

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

Expand Down
4 changes: 3 additions & 1 deletion src/Listeners/GetDefaultFieldSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ class GetDefaultFieldSchema
* @return void
*/
function handle($event) {
$event->handled = true;
if ($event->preventDefault) {
return;
}

$event->schema->addStringField($event->sender);
$event->query->addStringArgument($event->sender);
Expand Down
2 changes: 1 addition & 1 deletion src/Listeners/GetEntriesFieldSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class GetEntriesFieldSchema
* @return void
*/
function handle($event) {
$event->handled = true;
$event->preventDefault = true;

$request = $event->schema->request;
$field = $event->sender;
Expand Down
Loading