Skip to content

Commit

Permalink
Fix issue with GraphQL and Null coalescing operator
Browse files Browse the repository at this point in the history
  • Loading branch information
reganlawton committed Jun 29, 2020
1 parent 415866e commit 777e789
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 13 deletions.
12 changes: 2 additions & 10 deletions src/gql/OembedFieldResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
3 changes: 2 additions & 1 deletion src/gql/OembedFieldTypeGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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(),
Expand Down Expand Up @@ -68,4 +68,5 @@ public static function getName($context = null): string
/** @var OembedField $context */
return $context->handle . '_OembedField';
}

}
4 changes: 2 additions & 2 deletions src/models/OembedModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -69,7 +69,7 @@ public function __get($name)
$this->oembed = $oembed;
}

return $this->oembed->$name;
return $this->oembed->$name ?? null;
}


Expand Down

0 comments on commit 777e789

Please sign in to comment.