From 777e7897374cd128014ad080f13c454b7bf3a91c Mon Sep 17 00:00:00 2001 From: reganlawton Date: Mon, 29 Jun 2020 19:19:39 +1000 Subject: [PATCH] Fix issue with GraphQL and Null coalescing operator --- src/gql/OembedFieldResolver.php | 12 ++---------- src/gql/OembedFieldTypeGenerator.php | 3 ++- src/models/OembedModel.php | 4 ++-- 3 files changed, 6 insertions(+), 13 deletions(-) diff --git a/src/gql/OembedFieldResolver.php b/src/gql/OembedFieldResolver.php index 56c047c..7089138 100644 --- a/src/gql/OembedFieldResolver.php +++ b/src/gql/OembedFieldResolver.php @@ -21,16 +21,8 @@ class OembedFieldResolver extends ObjectType */ protected function resolve($source, $arguments, $context, ResolveInfo $resolveInfo) { - var_dump($source); - die; + $fieldName = $resolveInfo->fieldName; - switch($resolveInfo->fieldName) { - case 'url': -// var_dump($resolveInfo); -// die; - return 'Working'; - default: - return $source->{$resolveInfo->fieldName} ?? null; - } + return $source->$fieldName; } } diff --git a/src/gql/OembedFieldTypeGenerator.php b/src/gql/OembedFieldTypeGenerator.php index 2cafc34..36fc4df 100644 --- a/src/gql/OembedFieldTypeGenerator.php +++ b/src/gql/OembedFieldTypeGenerator.php @@ -14,6 +14,7 @@ use craft\gql\GqlEntityRegistry; use craft\gql\TypeLoader; use GraphQL\Type\Definition\Type; +use wrav\oembed\fields\OembedField; class OembedFieldTypeGenerator implements GeneratorInterface { @@ -30,7 +31,6 @@ public static function generateTypes($context = null): array 'description' => Type::string(), 'url' => Type::string(), 'type' => Type::string(), - 'images' => Type::string(), 'image' => Type::string(), 'imageWidth' => Type::string(), 'imageHeight' => Type::string(), @@ -68,4 +68,5 @@ public static function getName($context = null): string /** @var OembedField $context */ return $context->handle . '_OembedField'; } + } diff --git a/src/models/OembedModel.php b/src/models/OembedModel.php index 8568f62..0c417e2 100755 --- a/src/models/OembedModel.php +++ b/src/models/OembedModel.php @@ -56,7 +56,7 @@ public function __toString() public function __get($name) { if (property_exists($this , $name)) { - return $this->$name; + return $this->$name ?? null; } if ($this->oembed === null) { @@ -69,7 +69,7 @@ public function __get($name) $this->oembed = $oembed; } - return $this->oembed->$name; + return $this->oembed->$name ?? null; }