Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/Type/Json.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@
// phpcs:disable SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingAnyTypeHint
public string|null $description = 'The `json` scalar type represents json data.';

public function parseLiteral(ASTNode $valueNode, array|null $variables = null): string
public function parseLiteral(ASTNode $valueNode, array|null $variables = null): array|null
{
// @codeCoverageIgnoreStart
if (! $valueNode instanceof StringValueNode) {
throw new Error('Query error: Can only parse strings got: ' . $valueNode->kind, $valueNode);
}

return $valueNode->value;
return $this->parseValue($valueNode->value);
// @codeCoverageIgnoreEnd
}

Expand All @@ -54,6 +54,12 @@

public function serialize(mixed $value): string|null
{
return json_encode($value);
$return = json_encode($value);

if (! $return) {
return null;

Check warning on line 60 in src/Type/Json.php

View check run for this annotation

Codecov / codecov/patch

src/Type/Json.php#L60

Added line #L60 was not covered by tests
}

return $return;
}
}
4 changes: 2 additions & 2 deletions test/Feature/Type/JsonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ public function testParseLiteral(): void
{
$jsonType = new Json();
$node = new StringValueNode([]);
$node->value = 'search string';
$node->value = '{"field": "value"}';
$result = $jsonType->parseLiteral($node);

$this->assertTrue(true);
$this->assertEquals(['field' => 'value'], $result);
}

public function testContains(): void
Expand Down
Loading