Loading graphql/graphql_compose.graphqls +7 −0 Original line number Diff line number Diff line Loading @@ -291,6 +291,13 @@ type ImageStyle { height: Int } type File { url: String name: String size: Int mime: String } type Text { format: String value: String Loading src/DataManager.php +63 −1 Original line number Diff line number Diff line Loading @@ -862,7 +862,47 @@ class DataManager { ], ], ], ], ], 'file' => [ 'type_sdl' => 'File', 'name_sdl' => 'file', 'isUnion' => FALSE, 'isMultiple' => FALSE, 'isRequired' => FALSE, 'producers' => [ [ 'type' => 'dataProducer', 'id' => 'property_path', 'map' => [ [ 'id' => 'fromValue', 'key' => 'type', 'value' => 'entity:file', ], [ 'id' => 'fromParent', 'key' => 'value', 'value' => NULL, ], [ 'id' => 'fromValue', 'key' => 'path', 'value' => '{field_name}.entity', ], ], ], [ 'type' => 'dataProducer', 'id' => 'field_file', 'map' => [ [ 'id' => 'fromParent', 'key' => 'entity', 'value' => NULL, ], ], ], ], ], # Metatags module Loading Loading @@ -964,6 +1004,28 @@ class DataManager { ], ] ], 'File' => [ 'type_sdl' => 'File', 'isFielddable' => TRUE, 'fields' => [ 'url' => [ 'name_sdl' => 'url', 'type_sdl' => 'String', ], 'name' => [ 'name_sdl' => 'name', 'type_sdl' => 'String', ], 'size' => [ 'name_sdl' => 'size', 'type_sdl' => 'Int', ], 'mime' => [ 'name_sdl' => 'mime', 'type_sdl' => 'String', ], ] ], 'Text' => [ 'type_sdl' => 'Text', 'isFielddable' => TRUE, Loading src/Plugin/GraphQL/DataProducer/Field/FieldFile.php 0 → 100644 +51 −0 Original line number Diff line number Diff line <?php namespace Drupal\graphql_compose\Plugin\GraphQL\DataProducer\Field; use Drupal\Core\Cache\RefinableCacheableDependencyInterface; use Drupal\file\FileInterface; use Drupal\graphql\Plugin\GraphQL\DataProducer\DataProducerPluginBase; /** * Returns an file style derivative of an file. * * @DataProducer( * id = "field_file", * name = @Translation("File"), * description = @Translation("Returns file and derivatives."), * produces = @ContextDefinition("any", * label = @Translation("File properties") * ), * consumes = { * "entity" = @ContextDefinition("entity", * label = @Translation("Entity"), * required = FALSE * ), * } * ) */ class FieldFile extends DataProducerPluginBase { /** * {@inheritDoc} */ public function resolve(FileInterface $entity = NULL, RefinableCacheableDependencyInterface $metadata) { if (!$entity) { return NULL; } $access = $entity->access('view', NULL, TRUE); $metadata->addCacheableDependency($access); if ($access->isAllowed()) { return [ 'url' => \Drupal::service('file_url_generator')->generateAbsoluteString($entity->getFileUri()), 'name' => $entity->getFilename(), 'size' => (int) $entity->getSize(), 'mime' => $entity->getMimeType(), ]; } return NULL; } } Loading
graphql/graphql_compose.graphqls +7 −0 Original line number Diff line number Diff line Loading @@ -291,6 +291,13 @@ type ImageStyle { height: Int } type File { url: String name: String size: Int mime: String } type Text { format: String value: String Loading
src/DataManager.php +63 −1 Original line number Diff line number Diff line Loading @@ -862,7 +862,47 @@ class DataManager { ], ], ], ], ], 'file' => [ 'type_sdl' => 'File', 'name_sdl' => 'file', 'isUnion' => FALSE, 'isMultiple' => FALSE, 'isRequired' => FALSE, 'producers' => [ [ 'type' => 'dataProducer', 'id' => 'property_path', 'map' => [ [ 'id' => 'fromValue', 'key' => 'type', 'value' => 'entity:file', ], [ 'id' => 'fromParent', 'key' => 'value', 'value' => NULL, ], [ 'id' => 'fromValue', 'key' => 'path', 'value' => '{field_name}.entity', ], ], ], [ 'type' => 'dataProducer', 'id' => 'field_file', 'map' => [ [ 'id' => 'fromParent', 'key' => 'entity', 'value' => NULL, ], ], ], ], ], # Metatags module Loading Loading @@ -964,6 +1004,28 @@ class DataManager { ], ] ], 'File' => [ 'type_sdl' => 'File', 'isFielddable' => TRUE, 'fields' => [ 'url' => [ 'name_sdl' => 'url', 'type_sdl' => 'String', ], 'name' => [ 'name_sdl' => 'name', 'type_sdl' => 'String', ], 'size' => [ 'name_sdl' => 'size', 'type_sdl' => 'Int', ], 'mime' => [ 'name_sdl' => 'mime', 'type_sdl' => 'String', ], ] ], 'Text' => [ 'type_sdl' => 'Text', 'isFielddable' => TRUE, Loading
src/Plugin/GraphQL/DataProducer/Field/FieldFile.php 0 → 100644 +51 −0 Original line number Diff line number Diff line <?php namespace Drupal\graphql_compose\Plugin\GraphQL\DataProducer\Field; use Drupal\Core\Cache\RefinableCacheableDependencyInterface; use Drupal\file\FileInterface; use Drupal\graphql\Plugin\GraphQL\DataProducer\DataProducerPluginBase; /** * Returns an file style derivative of an file. * * @DataProducer( * id = "field_file", * name = @Translation("File"), * description = @Translation("Returns file and derivatives."), * produces = @ContextDefinition("any", * label = @Translation("File properties") * ), * consumes = { * "entity" = @ContextDefinition("entity", * label = @Translation("Entity"), * required = FALSE * ), * } * ) */ class FieldFile extends DataProducerPluginBase { /** * {@inheritDoc} */ public function resolve(FileInterface $entity = NULL, RefinableCacheableDependencyInterface $metadata) { if (!$entity) { return NULL; } $access = $entity->access('view', NULL, TRUE); $metadata->addCacheableDependency($access); if ($access->isAllowed()) { return [ 'url' => \Drupal::service('file_url_generator')->generateAbsoluteString($entity->getFileUri()), 'name' => $entity->getFilename(), 'size' => (int) $entity->getSize(), 'mime' => $entity->getMimeType(), ]; } return NULL; } }