Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GraphQL] No BC for types #3654

Merged
merged 2 commits into from
Jul 23, 2020
Merged
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
55 changes: 40 additions & 15 deletions src/GraphQl/Type/Definition/IterableType.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,44 @@
use GraphQL\Type\Definition\ScalarType;
use GraphQL\Utils\Utils;

if (\PHP_VERSION_ID >= 70200) {
trait IterableTypeParseLiteralTrait
{
/**
* {@inheritdoc}
*
* @param ObjectValueNode|ListValueNode|IntValueNode|FloatValueNode|StringValueNode|BooleanValueNode|NullValueNode $valueNode
*/
public function parseLiteral(/*Node */$valueNode, ?array $variables = null)
{
if ($valueNode instanceof ObjectValueNode || $valueNode instanceof ListValueNode) {
return $this->parseIterableLiteral($valueNode);
}

// Intentionally without message, as all information already in wrapped Exception
throw new \Exception();
}
}
} else {
trait IterableTypeParseLiteralTrait
{
/**
* {@inheritdoc}
*
* @param ObjectValueNode|ListValueNode|IntValueNode|FloatValueNode|StringValueNode|BooleanValueNode|NullValueNode $valueNode
*/
public function parseLiteral(Node $valueNode, ?array $variables = null)
{
if ($valueNode instanceof ObjectValueNode || $valueNode instanceof ListValueNode) {
return $this->parseIterableLiteral($valueNode);
}

// Intentionally without message, as all information already in wrapped Exception
throw new \Exception();
}
}
}

/**
* Represents an iterable type.
*
Expand All @@ -35,6 +73,8 @@
*/
final class IterableType extends ScalarType implements TypeInterface
{
use IterableTypeParseLiteralTrait;

public function __construct()
{
$this->name = 'Iterable';
Expand Down Expand Up @@ -72,21 +112,6 @@ public function parseValue($value)
return $value;
}

/**
* {@inheritdoc}
*
* @param ObjectValueNode|ListValueNode|IntValueNode|FloatValueNode|StringValueNode|BooleanValueNode|NullValueNode $valueNode
*/
public function parseLiteral(Node $valueNode, ?array $variables = null)
{
if ($valueNode instanceof ObjectValueNode || $valueNode instanceof ListValueNode) {
return $this->parseIterableLiteral($valueNode);
}

// Intentionally without message, as all information already in wrapped Exception
throw new \Exception();
}

/**
* @param StringValueNode|BooleanValueNode|IntValueNode|FloatValueNode|ObjectValueNode|ListValueNode|ValueNode $valueNode
*/
Expand Down
34 changes: 26 additions & 8 deletions src/GraphQl/Type/Definition/UploadType.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,39 @@
use GraphQL\Utils\Utils;
use Symfony\Component\HttpFoundation\File\UploadedFile;

if (\PHP_VERSION_ID >= 70200) {
trait UploadTypeParseLiteralTrait
{
/**
* {@inheritdoc}
*/
public function parseLiteral(/*Node */$valueNode, array $variables = null)
{
throw new Error('`Upload` cannot be hardcoded in query, be sure to conform to GraphQL multipart request specification.', $valueNode);
}
}
} else {
trait UploadTypeParseLiteralTrait
{
/**
* {@inheritdoc}
*/
public function parseLiteral(Node $valueNode, array $variables = null)
{
throw new Error('`Upload` cannot be hardcoded in query, be sure to conform to GraphQL multipart request specification.', $valueNode);
}
}
}

/**
* Represents an upload type.
*
* @author Mahmood Bazdar <mahmood@bazdar.me>
*/
final class UploadType extends ScalarType implements TypeInterface
{
use UploadTypeParseLiteralTrait;

public function __construct()
{
$this->name = 'Upload';
Expand Down Expand Up @@ -58,12 +84,4 @@ public function parseValue($value): UploadedFile

return $value;
}

/**
* {@inheritdoc}
*/
public function parseLiteral(Node $valueNode, array $variables = null)
{
throw new Error('`Upload` cannot be hardcoded in query, be sure to conform to GraphQL multipart request specification.', $valueNode);
}
}