Skip to content

Commit

Permalink
docs and a format argument
Browse files Browse the repository at this point in the history
  • Loading branch information
markhuot committed Nov 21, 2017
1 parent afb6deb commit eb2dd68
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,36 @@ The above approach, typically, requires separate requests for the source content
}
```

## Transforms

You can ask CraftQL for image transforms by specifying an argument to any asset field. If you have defined named transforms within the Craft UI you can reference the transform by its handle,

```graphql
{
entries {
...on Post {
imageFieldHandle {
thumbnail: url(transform: thumb)
}
}
}
}
```

You can also specify the exact crop by using the `crop`, `fit`, or `stretch` arguments as specified in the [Craft docs](https://craftcms.com/docs/image-transforms).

```graphql
{
entries {
...on Post {
imageFieldHandle {
poster: url(crop: {width: 1280, height: 720, position: topLeft, quality: 50, format: 'jpg'})
}
}
}
}
```

## Drafts

Drafts are best fetched through an edge node on the `entriesConnection` query. You can get all drafts for an entry with the following query,
Expand Down
18 changes: 18 additions & 0 deletions src/Types/Volume.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class Volume extends ObjectType {
static $transformEnum;
static $cropInputObject;
static $positionInputEnum;
static $formatInputEnum;

function __construct($volume, $token) {
$fieldService = \Yii::$container->get(\markhuot\CraftQL\Services\FieldService::class);
Expand Down Expand Up @@ -68,6 +69,22 @@ static function positionInputEnum() {
]);
}

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

return static::$formatInputEnum = new EnumType([
'name' => 'CropFormatInputEnum',
'values' => [
'jpg' => 'JPG',
'gif' => 'GIF',
'png' => 'PNG',
'Auto' => 'Auto',
],
]);
}

static function cropInputObject() {
if (!empty(static::$cropInputObject)) {
return static::$cropInputObject;
Expand All @@ -80,6 +97,7 @@ static function cropInputObject() {
'height' => ['type' => Type::int()],
'quality' => ['type' => Type::int()],
'position' => ['type' => static::positionInputEnum()],
'format' => ['type' => static::formatInputEnum()],
],
]);
}
Expand Down

0 comments on commit eb2dd68

Please sign in to comment.