Skip to content

Commit

Permalink
Merge pull request #47 from wrav/feature/gdpr
Browse files Browse the repository at this point in the history
v1.3.2 - GraphQL changes
  • Loading branch information
reganlawton authored Jun 5, 2020
2 parents 02fe15b + dc69b15 commit eb129e2
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# oEmbed Changelog

## 1.3.2 - 2020-06-05

### Updated
- Fixed GraphQL bug `Internal Server Error: GraphQL fails to get oembed fields` ([#46](https://github.com/wrav/oembed/issues/46)).

## 1.3.1 - 2020-05-08

### Added
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "wrav/oembed",
"description": "A simple plugin to extract media information from websites, like youtube videos, twitter statuses or blog articles.",
"type": "craft-plugin",
"version": "1.3.1",
"version": "1.3.2",
"keywords": [
"craft",
"cms",
Expand Down
2 changes: 1 addition & 1 deletion src/gql/OembedFieldResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ protected function resolve($source, $arguments, $context, ResolveInfo $resolveIn
{
$fieldName = $resolveInfo->fieldName;

return $source->$fieldName;
return $source->$fieldName ?? null;
}
}
40 changes: 39 additions & 1 deletion src/gql/OembedFieldTypeGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@
namespace wrav\oembed\gql;

use craft\gql\base\GeneratorInterface;
use craft\gql\base\SingleGeneratorInterface;
use craft\gql\GqlEntityRegistry;
use craft\gql\TypeLoader;
use GraphQL\Type\Definition\Type;

class OembedFieldTypeGenerator implements GeneratorInterface
class OembedFieldTypeGenerator implements GeneratorInterface, SingleGeneratorInterface
{
/**
* @inheritdoc
Expand Down Expand Up @@ -60,6 +61,43 @@ public static function generateTypes($context = null): array
return [$property];
}



/**
* @inheritdoc
*/
public static function generateType($context = null): ObjectType
{
/** @var OembedField $context */
$typeName = self::getName($context);

$properties = [
'title' => Type::string(),
'description' => Type::string(),
'url' => Type::string(),
'type' => Type::string(),
'images' => Type::string(),
'image' => Type::string(),
'imageWidth' => Type::string(),
'imageHeight' => Type::string(),
'code' => Type::string(),
'width' => Type::string(),
'height' => Type::string(),
'aspectRatio' => Type::string(),
'authorName' => Type::string(),
'authorUrl' => Type::string(),
'providerName' => Type::string(),
'providerUrl' => Type::string(),
];

return GqlEntityRegistry::getEntity($typeName) ?: GqlEntityRegistry::createEntity($typeName, new Element([
'name' => $typeName,
'fields' => function() use ($properties) {
return $properties;
}
]));
}

/**
* @inheritdoc
*/
Expand Down

0 comments on commit eb129e2

Please sign in to comment.