Skip to content

Commit

Permalink
Merge pull request #8 from rdey/feature/validation-errors
Browse files Browse the repository at this point in the history
Move error state to under extensions
  • Loading branch information
nicholasruunu committed Mar 5, 2024
2 parents 3d7ad0d + 6babcf9 commit 887cdc7
Show file tree
Hide file tree
Showing 13 changed files with 179 additions and 155 deletions.
31 changes: 18 additions & 13 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,43 @@ on:
pull_request:
branches:
- "*.*"
- master
- main
push:
branches:
- "*.*"
- master
- main

jobs:
tests:
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
strategy:
fail-fast: false
matrix:
php-version:
- '8.0'
- '8.1'
- '8.2'
symfony-version:
- '5.4.*'
- '6.0.*'
- '6.2.*'
- '6.4.*'
dependencies:
- 'lowest'
- 'highest'
remove-dependencies: [ '' ]
coverage: [ 'none' ]
exclude:
- php-version: '8.0'
symfony-version: '6.2.*'
- php-version: '8.0'
symfony-version: '6.4.*'
include:
- php-version: '8.0'
symfony-version: '5.4.*'
dependencies: 'lowest'
remove-dependencies: '--dev symfony/validator doctrine/orm doctrine/annotations'
- php-version: '8.0'
- php-version: '8.1'
symfony-version: '5.4.*'
dependencies: 'lowest'
coverage: "pcov"
Expand All @@ -47,10 +55,6 @@ jobs:
php-version: "${{ matrix.php-version }}"
coverage: "${{ matrix.coverage }}"

- name: "Change stability"
if: "matrix.stability != ''"
run: perl -pi -e 's/^}$/,"minimum-stability":"'"${{ matrix.minimum-stability }}"'"}/' composer.json && cat composer.json

- name: "Webonyx GraphQL version"
if: "matrix.graphql-version != ''"
run: composer require "webonyx/graphql-php:${{ matrix.graphql-version }}" --dev --no-update
Expand All @@ -60,24 +64,25 @@ jobs:
run: composer remove --no-update ${{ matrix.remove-dependencies }}

- name: "Install dependencies"
uses: ramsey/composer-install@1.3.0
uses: "ramsey/composer-install@v2"
with:
dependency-versions: ${{ matrix.dependencies }}
env:
SYMFONY_REQUIRE: "${{ matrix.symfony-version }}"

- name: "Run tests"
run: composer test
run: composer run test

- name: "Upload coverage results to Coveralls"
if: "matrix.coverage == 'pcov'"
env:
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
wget https://github.com/php-coveralls/php-coveralls/releases/download/v2.5.1/php-coveralls.phar
wget https://github.com/php-coveralls/php-coveralls/releases/download/v2.6.0/php-coveralls.phar
php php-coveralls.phar --coverage_clover=build/logs/clover.xml -v
coding-standard:
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
name: Coding Standard
steps:
- name: "Checkout"
Expand All @@ -96,7 +101,7 @@ jobs:
run: composer check-cs

static-analysis:
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
name: "Static analysis"
steps:
- name: "Checkout"
Expand Down
49 changes: 0 additions & 49 deletions Dockerfile

This file was deleted.

19 changes: 5 additions & 14 deletions src/Config/Parser/GraphQLParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
use function call_user_func;
use function explode;
use function file_get_contents;
use function get_class;
use function in_array;
use function preg_replace;
use function sprintf;
Expand Down Expand Up @@ -62,12 +61,10 @@ public static function parse(SplFileInfo $file, ContainerBuilder $container, arr
* @var ObjectTypeDefinitionNode|InputObjectTypeDefinitionNode|EnumTypeDefinitionNode|DirectiveDefinitionNode $typeDef
*/
if (isset($typeDef->kind) && in_array($typeDef->kind, array_keys(self::DEFINITION_TYPE_MAPPING))) {
/**
* @var class-string<NodeInterface> $class
*/
/** @var class-string<NodeInterface> $class */
$class = sprintf('\\%s\\GraphQL\\ASTConverter\\%sNode', __NAMESPACE__, ucfirst(self::DEFINITION_TYPE_MAPPING[$typeDef->kind]));
$typesConfig[$typeDef->name->value] = call_user_func([$class, 'toConfig'], $typeDef);
} else if (self::isAllowedDirectiveDefinition($typeDef)) {
} elseif (self::isAllowedDirectiveDefinition($typeDef)) {

Check failure on line 67 in src/Config/Parser/GraphQLParser.php

View workflow job for this annotation

GitHub Actions / Static analysis

Parameter #1 $typeDef of static method Redeye\GraphQLBundle\Config\Parser\GraphQLParser::isAllowedDirectiveDefinition() expects GraphQL\Language\AST\EnumTypeDefinitionNode|GraphQL\Language\AST\InputObjectTypeDefinitionNode|GraphQL\Language\AST\ObjectTypeDefinitionNode, GraphQL\Language\AST\DirectiveDefinitionNode|GraphQL\Language\AST\EnumTypeDefinitionNode|GraphQL\Language\AST\InputObjectTypeDefinitionNode|GraphQL\Language\AST\ObjectTypeDefinitionNode given.
// Allow a directive named resolve
} else {
self::throwUnsupportedDefinitionNode($typeDef);
Expand All @@ -82,7 +79,7 @@ public static function parse(SplFileInfo $file, ContainerBuilder $container, arr
*/
private static function isAllowedDirectiveDefinition($typeDef): bool
{
if (!(isset($typeDef->kind) && $typeDef->kind == NodeKind::DIRECTIVE_DEFINITION && isset($typeDef->name))) {
if (!(isset($typeDef->kind) && NodeKind::DIRECTIVE_DEFINITION == $typeDef->kind && isset($typeDef->name))) {
return false;
}

Expand All @@ -101,13 +98,7 @@ private static function isAllowedDirectiveDefinition($typeDef): bool

private static function throwUnsupportedDefinitionNode(DefinitionNode $typeDef): void
{
$path = explode('\\', get_class($typeDef));
throw new InvalidArgumentException(
sprintf(
'%s definition is not supported right now, attempting to define %s.',
preg_replace('@DefinitionNode$@', '', array_pop($path)),
$typeDef->name
)
);
$path = explode('\\', $typeDef::class);
throw new InvalidArgumentException(sprintf('%s definition is not supported right now.', preg_replace('@DefinitionNode$@', '', array_pop($path))));
}
}
6 changes: 5 additions & 1 deletion src/Controller/ProfilerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\HttpKernel\Profiler\Profiler;
use Symfony\Component\Routing\RouterInterface;
use Twig\Environment;
Expand Down Expand Up @@ -53,6 +54,9 @@ public function __invoke(Request $request, string $token): Response

$profile = $this->profiler->loadProfile($token);

// Type hint as int for the $limit argument of the find method was updated in Symfony 5.4.22 and 6.2.8
$limit = (Kernel::VERSION_ID >= 60208 || (Kernel::MAJOR_VERSION === 5 && Kernel::VERSION_ID >= 50422)) ? 100 : '100'; // @phpstan-ignore-line

$tokens = array_map(function ($tokenData) {
$profile = $this->profiler->loadProfile($tokenData['token']);
if (!$profile->hasCollector('graphql')) {
Expand All @@ -61,7 +65,7 @@ public function __invoke(Request $request, string $token): Response
$tokenData['graphql'] = $profile->getCollector('graphql');

return $tokenData;
}, $this->profiler->find(null, $this->queryMatch ?: $this->endpointUrl, 100, 'POST', null, null, null)); // @phpstan-ignore-line
}, $this->profiler->find(null, $this->queryMatch ?: $this->endpointUrl, $limit, 'POST', null, null, null)); // @phpstan-ignore-line

$schemas = [];
foreach ($this->requestExecutor->getSchemasNames() as $schemaName) {
Expand Down
2 changes: 1 addition & 1 deletion src/EventListener/ValidationErrorsListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function onErrorFormatting(ErrorFormattingEvent $event): void

if ($previous && $previous instanceof InvalidArgumentsError) {
$formattedError = $event->getFormattedError();
$formattedError['state'] = $previous->toState();
$formattedError['extensions']['state'] = $previous->toState();
}
}
}
2 changes: 1 addition & 1 deletion src/Transformer/ArgumentsTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public function getArguments(array $mapping, $data, ResolveInfo $info)
}

if (!empty($exceptions)) {
throw new InvalidArgumentsError($exceptions);
throw new InvalidArgumentsError($exceptions, 'Validation error');
}

return $args;
Expand Down
Loading

0 comments on commit 887cdc7

Please sign in to comment.