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

Update / Cleanup #1122

Merged
merged 10 commits into from
May 26, 2023
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
5 changes: 5 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,19 @@ jobs:
php-version:
- '8.0'
- '8.1'
- '8.2'
symfony-version:
- '5.4.*'
- '6.0.*'
- '6.2.*'
dependencies:
- 'lowest'
- 'highest'
remove-dependencies: [ '' ]
coverage: [ 'none' ]
exclude:
- php-version: '8.0'
symfony-version: '6.2.*'
include:
- php-version: '8.0'
symfony-version: '5.4.*'
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"symfony/http-kernel": "^5.4 || ^6.0",
"symfony/options-resolver": "^5.4 || ^6.0",
"symfony/property-access": "^5.4 || ^6.0",
"webonyx/graphql-php": "^15.0"
"webonyx/graphql-php": "^15.4"
},
"suggest": {
"nelmio/cors-bundle": "For more flexibility when using CORS prefight",
Expand Down Expand Up @@ -91,7 +91,7 @@
"static-analysis": [
"phpstan analyse --ansi --memory-limit=1G"
],
"install-cs": "test -f php-cs-fixer.phar || wget https://github.com/FriendsOfPHP/PHP-CS-Fixer/releases/download/v3.11.0/php-cs-fixer.phar -O php-cs-fixer.phar",
"install-cs": "test -f php-cs-fixer.phar || wget https://github.com/FriendsOfPHP/PHP-CS-Fixer/releases/download/v3.17.0/php-cs-fixer.phar -O php-cs-fixer.phar",
"fix-cs": [
"@install-cs",
"@php php-cs-fixer.phar fix --diff -v --allow-risky=yes --ansi"
Expand Down
2 changes: 1 addition & 1 deletion phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ parameters:

-
message: "#^Call to method disableOriginalConstructor\\(\\) on an unknown class PHPUnit_Framework_MockObject_MockBuilder\\.$#"
count: 1
count: 2
path: tests/ExpressionLanguage/TestCase.php

-
Expand Down
6 changes: 5 additions & 1 deletion src/Command/GraphQLDumpSchemaCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use GraphQL\Utils\SchemaPrinter;
use InvalidArgumentException;
use Overblog\GraphQLBundle\Request\Executor as RequestExecutor;
use Overblog\GraphQLBundle\Resolver\TypeResolver;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
Expand All @@ -27,11 +28,14 @@ final class GraphQLDumpSchemaCommand extends Command
private RequestExecutor $requestExecutor;
private string $baseExportPath;

public function __construct(string $baseExportPath, RequestExecutor $requestExecutor)
public function __construct(string $baseExportPath, RequestExecutor $requestExecutor, TypeResolver $typeResolver)
{
parent::__construct();
$this->baseExportPath = $baseExportPath;
$this->requestExecutor = $requestExecutor;

// Disable exception when an unresolvable types is encoutered. Schema dump will try to access the Query, Mutation and Subscription types and will fail if they are not defined.
$typeResolver->setIgnoreUnresolvableException(true);
}

public function getRequestExecutor(): RequestExecutor
Expand Down
4 changes: 2 additions & 2 deletions src/Definition/Builder/SchemaBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function __construct(TypeResolver $typeResolver, bool $enableValidation =
$this->enableValidation = $enableValidation;
}

public function getBuilder(string $name, ?string $queryAlias, ?string $mutationAlias = null, ?string $subscriptionAlias = null, array $types = []): Closure
public function getBuilder(string $name, ?string $queryAlias, string $mutationAlias = null, string $subscriptionAlias = null, array $types = []): Closure
{
return function () use ($name, $queryAlias, $mutationAlias, $subscriptionAlias, $types): ExtensibleSchema {
static $schema = null;
Expand All @@ -38,7 +38,7 @@ public function getBuilder(string $name, ?string $queryAlias, ?string $mutationA
/**
* @param string[] $types
*/
public function create(string $name, ?string $queryAlias, ?string $mutationAlias = null, ?string $subscriptionAlias = null, array $types = []): ExtensibleSchema
public function create(string $name, ?string $queryAlias, string $mutationAlias = null, string $subscriptionAlias = null, array $types = []): ExtensibleSchema
{
$this->typeResolver->setCurrentSchemaName($name);
$query = $this->typeResolver->resolve($queryAlias);
Expand Down
2 changes: 1 addition & 1 deletion src/Definition/Type/PhpEnumType.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public function parseValue($value): mixed
return parent::parseValue($value);
}

public function parseLiteral(Node $valueNode, ?array $variables = null): mixed
public function parseLiteral(Node $valueNode, array $variables = null): mixed
{
if ($this->enumClass) {
if (!$valueNode instanceof EnumValueNode) {
Expand Down
4 changes: 2 additions & 2 deletions src/Executor/Executor.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ public function execute(
$contextValue = null,
$variableValues = null,
$operationName = null,
?callable $fieldResolver = null,
?array $validationRules = null
callable $fieldResolver = null,
array $validationRules = null
): ExecutionResult {
if (!method_exists($promiseAdapter, 'wait')) {
throw new RuntimeException(
Expand Down
4 changes: 2 additions & 2 deletions src/Executor/ExecutorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function execute(
$contextValue = null,
$variableValues = null,
$operationName = null,
?callable $fieldResolver = null,
?array $validationRules = null
callable $fieldResolver = null,
array $validationRules = null
): ExecutionResult;
}
2 changes: 1 addition & 1 deletion src/ExpressionLanguage/ExpressionFunction.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class ExpressionFunction extends BaseExpressionFunction
{
protected string $gqlServices = '$'.TypeGenerator::GRAPHQL_SERVICES;

public function __construct(string $name, callable $compiler, ?callable $evaluator = null)
public function __construct(string $name, callable $compiler, callable $evaluator = null)
{
if (null === $evaluator) {
$evaluator = new EvaluatorIsNotAllowedException($name);
Expand Down
2 changes: 1 addition & 1 deletion src/Generator/TypeBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ private function buildScalarCallback($callback, string $fieldName)
*
* @throws GeneratorException
*/
private function buildResolve($resolve, ?array $groups = null): GeneratorInterface
private function buildResolve($resolve, array $groups = null): GeneratorInterface
{
if (is_callable($resolve) && is_array($resolve)) {
return Collection::numeric($resolve);
Expand Down
4 changes: 2 additions & 2 deletions src/Generator/TypeGeneratorOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ public function __construct(
string $namespace,
?string $cacheDir,
bool $useClassMap = true,
?string $cacheBaseDir = null,
?int $cacheDirMask = null
string $cacheBaseDir = null,
int $cacheDirMask = null
) {
$this->namespace = $namespace;
$this->cacheDir = $cacheDir;
Expand Down
2 changes: 1 addition & 1 deletion src/Relay/Connection/ConnectionBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ final class ConnectionBuilder
* @phpstan-param ConnectionFactoryFunc|null $connectionCallback
* @phpstan-param EdgeFactoryFunc|null $edgeCallback
*/
public function __construct(?CursorEncoderInterface $cursorEncoder = null, ?callable $connectionCallback = null, ?callable $edgeCallback = null)
public function __construct(CursorEncoderInterface $cursorEncoder = null, callable $connectionCallback = null, callable $edgeCallback = null)
{
$this->cursorEncoder = $cursorEncoder ?? new Base64CursorEncoder();
$this->connectionCallback = $connectionCallback ?? static fn (array $edges, PageInfoInterface $pageInfo): Connection => new Connection($edges, $pageInfo);
Expand Down
4 changes: 3 additions & 1 deletion src/Relay/Connection/Output/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Overblog\GraphQLBundle\Relay\Connection\Output;

use AllowDynamicProperties;
use GraphQL\Executor\Promise\Promise;
use Overblog\GraphQLBundle\Relay\Connection\ConnectionInterface;
use Overblog\GraphQLBundle\Relay\Connection\EdgeInterface;
Expand All @@ -14,6 +15,7 @@
*
* @phpstan-implements ConnectionInterface<T>
*/
#[AllowDynamicProperties]
class Connection implements ConnectionInterface
{
use DeprecatedPropertyPublicAccessTrait;
Expand All @@ -24,7 +26,7 @@ class Connection implements ConnectionInterface
protected ?PageInfoInterface $pageInfo;

/** @var int|Promise|null Total count or promise that returns the total count */
protected $totalCount = null;
protected $totalCount;

/**
* @param EdgeInterface<T>[] $edges
Expand Down
4 changes: 2 additions & 2 deletions src/Relay/Node/PluralIdentifyingRootFieldDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ public function toMappingDefinition(array $config): array
$argName = $config['argName'];

return [
'type' => "[${config['outputType']}]",
'args' => [$argName => ['type' => "[${config['inputType']}!]!"]],
'type' => "[{$config['outputType']}]",
'args' => [$argName => ['type' => "[{$config['inputType']}!]!"]],
'resolve' => sprintf(
"@=query('relay_plural_identifying_field', args.$argName, context, info, resolveSingleInputCallback(%s))",
$this->cleanResolveSingleInput($config['resolveSingleInput'])
Expand Down
6 changes: 3 additions & 3 deletions src/Request/Executor.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function __construct(
ExecutorInterface $executor,
PromiseAdapter $promiseAdapter,
EventDispatcherInterface $dispatcher,
?callable $defaultFieldResolver = null
callable $defaultFieldResolver = null
) {
$this->executor = $executor;
$this->promiseAdapter = $promiseAdapter;
Expand Down Expand Up @@ -171,8 +171,8 @@ private function preExecute(
string $requestString,
ArrayObject $contextValue,
$rootValue = null,
?array $variableValue = null,
?string $operationName = null
array $variableValue = null,
string $operationName = null
): ExecutorArgumentsEvent {
// @phpstan-ignore-next-line (only for Symfony 4.4)
$this->dispatcher->dispatch(new ExecutorContextEvent($contextValue), Events::EXECUTOR_CONTEXT);
Expand Down
2 changes: 1 addition & 1 deletion src/Resolver/ResolverMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function isResolvable(string $typeName, string $fieldName): bool
/**
* {@inheritdoc}
*/
public function covered(?string $typeName = null)
public function covered(string $typeName = null)
{
$loadedMap = $this->getLoadedMap();
$covered = [];
Expand Down
2 changes: 1 addition & 1 deletion src/Resolver/ResolverMapInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,5 @@ public function isResolvable(string $typeName, string $fieldName): bool;
*
* @return array
*/
public function covered(?string $typeName = null);
public function covered(string $typeName = null);
}
2 changes: 1 addition & 1 deletion src/Resolver/ResolverMaps.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function isResolvable(string $typeName, string $fieldName): bool
/**
* {@inheritdoc}
*/
public function covered(?string $typeName = null)
public function covered(string $typeName = null)
{
$covered = [];
foreach ($this->resolverMaps as $resolverMap) {
Expand Down
10 changes: 8 additions & 2 deletions src/Resolver/TypeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class TypeResolver extends AbstractResolver
private array $cache = [];
private ?string $currentSchemaName = null;
private EventDispatcherInterface $dispatcher;
private bool $ignoreUnresolvableException = false;

public function setDispatcher(EventDispatcherInterface $dispatcher): void
{
Expand All @@ -27,6 +28,11 @@ public function setCurrentSchemaName(?string $currentSchemaName): void
$this->currentSchemaName = $currentSchemaName;
}

public function setIgnoreUnresolvableException(bool $ignoreUnresolvableException): void
{
$this->ignoreUnresolvableException = $ignoreUnresolvableException;
}

/**
* @param mixed $solution
*/
Expand Down Expand Up @@ -60,10 +66,10 @@ public function resolve($alias): ?Type
return $this->cache[$alias];
}

private function baseType(string $alias): Type
private function baseType(string $alias): ?Type
{
$type = $this->getSolution($alias);
if (null === $type) {
if (null === $type && !$this->ignoreUnresolvableException) {
throw new UnresolvableException(
sprintf('Could not find type with alias "%s". Did you forget to define it?', $alias)
);
Expand Down
1 change: 1 addition & 0 deletions src/Resources/config/commands.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ services:
arguments:
- "%kernel.cache_dir%/../.."
- '@Overblog\GraphQLBundle\Request\Executor'
- '@Overblog\GraphQLBundle\Resolver\TypeResolver'
tags:
- { name: console.command, command: graphql:dump-schema, alias: "graph:dump-schema" }

Expand Down
29 changes: 26 additions & 3 deletions src/Security/Security.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,42 @@
namespace Overblog\GraphQLBundle\Security;

use LogicException;
use Symfony\Bundle\SecurityBundle\Security as BundleSecurity;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Security\Core\Security as CoreSecurity;
use Symfony\Component\Security\Core\User\UserInterface;

use function array_reduce;

final class Security
if (Kernel::VERSION_ID >= 60200) {
final class Security extends BaseSecurity
{
public function __construct(?BundleSecurity $security)
{
parent::__construct($security);
}
}
} else {
final class Security extends BaseSecurity
{
public function __construct(?CoreSecurity $security)
{
parent::__construct($security);
}
}
}

abstract class BaseSecurity
{
/**
* @var CoreSecurity
* @var CoreSecurity|BundleSecurity
*/
private $coreSecurity;

public function __construct(?CoreSecurity $security)
/**
* @param CoreSecurity|BundleSecurity $security
*/
public function __construct($security)
{
// @phpstan-ignore-next-line
$this->coreSecurity = $security ?? new class() {
Expand Down
6 changes: 4 additions & 2 deletions src/Validator/ValidationNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Overblog\GraphQLBundle\Validator;

use AllowDynamicProperties;
use GraphQL\Type\Definition\InputObjectType;
use GraphQL\Type\Definition\NamedType;
use GraphQL\Type\Definition\ObjectType;
Expand All @@ -24,6 +25,7 @@
* It also contains variables of the resolver context, in which this class was
* instantiated.
*/
#[AllowDynamicProperties]
final class ValidationNode
{
private const KNOWN_VAR_NAMES = ['value', 'args', 'context', 'info'];
Expand All @@ -49,8 +51,8 @@ final class ValidationNode
public function __construct(
ObjectType|InputObjectType $type,
string $field = null,
?ValidationNode $parent = null,
?ResolverArgs $resolverArgs = null
ValidationNode $parent = null,
ResolverArgs $resolverArgs = null
) {
$this->__type = $type;
$this->__fieldName = $field;
Expand Down
1 change: 1 addition & 0 deletions tests/Config/Parser/fixtures/annotations/Enum/Color.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

/**
* @GQL\Enum
*
* @GQL\EnumValue(name="RED", description="The color red")
*/
#[GQL\Enum]
Expand Down
2 changes: 2 additions & 0 deletions tests/Config/Parser/fixtures/annotations/Enum/Race.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@

/**
* @GQL\Enum
*
* @GQL\EnumValue(name="CHISS", description="The Chiss race")
* @GQL\EnumValue(name="ZABRAK", deprecationReason="The Zabraks have been wiped out")
*
* @GQL\Description("The list of races!")
*/
#[GQL\Enum]
Expand Down
1 change: 1 addition & 0 deletions tests/Config/Parser/fixtures/annotations/Input/Planet.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

/**
* @GQL\Input
*
* @GQL\Description("Planet Input type description")
*/
#[GQL\Input]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ final class InvalidDoctrineRelationGuessing
{
/**
* @ORM\OneToOne(targetEntity="MissingType")
*
* @GQL\Field
*/
#[GQL\Field]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ final class InvalidDoctrineTypeGuessing
{
/**
* @ORM\Column(type="invalidType")
*
* @GQL\Field
*
* @var mixed
Expand Down
Loading