Skip to content
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
2 changes: 1 addition & 1 deletion Command/GraphQLDumpSchemaCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
->execute($request, [], $schemaName)
->toArray();

$file = $input->getOption('file') ?: $container->getParameter('kernel.root_dir').sprintf('/../var/schema%s.json', $schemaName? '.'.$schemaName:'');
$file = $input->getOption('file') ?: $container->getParameter('kernel.root_dir').sprintf('/../var/schema%s.json', $schemaName ? '.'.$schemaName : '');

$schema = json_encode($result['data']);

Expand Down
2 changes: 1 addition & 1 deletion Error/ErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
use GraphQL\Error;
use GraphQL\Executor\ExecutionResult;
use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;
use Psr\Log\LogLevel;
use Psr\Log\NullLogger;

class ErrorHandler
{
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -891,6 +891,7 @@ Expression | Description | Scope
**value** | Resolver value | only available in resolve context
**args** | Resolver args array | only available in resolve context
**info** | Resolver GraphQL\Type\Definition\ResolveInfo Object | only available in resolve context
**context** | context is defined by your application on the top level of query execution (useful for storing current user, environment details, etc) | only available in resolve context
**childrenComplexity** | Selection field children complexity | only available in complexity context

[For more details on expression syntax](http://symfony.com/doc/current/components/expression_language/syntax.html)
Expand Down
8 changes: 8 additions & 0 deletions Relay/Connection/Output/ConnectionBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,17 @@ public static function connectionFromArraySlice($arraySlice, $args, array $meta)
$endOffset = min($sliceEnd, $beforeOffset, $arrayLength);

if (is_numeric($first)) {
if ($first < 0) {
throw new \InvalidArgumentException('Argument "first" must be a non-negative integer');
}
$endOffset = min($endOffset, $startOffset + $first);
}

if (is_numeric($last)) {
if ($last < 0) {
throw new \InvalidArgumentException('Argument "last" must be a non-negative integer');
}

$startOffset = max($startOffset, $endOffset - $last);
}

Expand Down
9 changes: 9 additions & 0 deletions Relay/Connection/Paginator.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
<?php

/*
* This file is part of the OverblogGraphQLBundle package.
*
* (c) Overblog <http://github.com/overblog/>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Overblog\GraphQLBundle\Relay\Connection;

use Overblog\GraphQLBundle\Definition\Argument;
Expand Down
2 changes: 1 addition & 1 deletion Relay/Mutation/InputDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function toMappingDefinition(array $config)
'fields' => array_merge(
$inputFields,
[
'clientMutationId' => ['type' => 'String!'],
'clientMutationId' => ['type' => 'String'],
]
),
],
Expand Down
2 changes: 1 addition & 1 deletion Relay/Mutation/PayloadDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function toMappingDefinition(array $config)
'fields' => array_merge(
$outputFields,
[
'clientMutationId' => ['type' => 'String!'],
'clientMutationId' => ['type' => 'String'],
]
),
],
Expand Down
6 changes: 2 additions & 4 deletions Request/Executor.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ public function __construct(
ErrorHandler $errorHandler = null,
$hasDebugInfo = false,
callable $executor = null
)
{
) {
$this->dispatcher = $dispatcher;
$this->throwException = (bool) $throwException;
$this->errorHandler = $errorHandler;
Expand All @@ -67,7 +66,6 @@ public function __construct(
if (null === $this->executor) {
$this->executor = self::DEFAULT_EXECUTOR;
}

}

public function setExecutor(callable $executor)
Expand Down Expand Up @@ -152,7 +150,7 @@ public function execute(array $data, array $context = [], $schemaName = null)
isset($data[ParserInterface::PARAM_OPERATION_NAME]) ? $data[ParserInterface::PARAM_OPERATION_NAME] : null
);

if (!is_object($executionResult) || !$executionResult instanceof ExecutionResult) {
if (!is_object($executionResult) || !$executionResult instanceof ExecutionResult) {
throw new \RuntimeException(sprintf('Execution result should be an object instantiating "%s".', 'GraphQL\\Executor\\ExecutionResult'));
}

Expand Down
12 changes: 10 additions & 2 deletions Tests/DependencyInjection/Compiler/FakeCompilerPass.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
<?php

/*
* This file is part of the OverblogGraphQLBundle package.
*
* (c) Overblog <http://github.com/overblog/>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Overblog\GraphQLBundle\Tests\DependencyInjection\Compiler;

use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;

/**
* Class FakeCompilerPass
* @package DependencyInjection\Compiler
* Class FakeCompilerPass.
*/
class FakeCompilerPass implements CompilerPassInterface
{
Expand Down
11 changes: 10 additions & 1 deletion Tests/DependencyInjection/Compiler/FakeInjectedService.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
<?php

/*
* This file is part of the OverblogGraphQLBundle package.
*
* (c) Overblog <http://github.com/overblog/>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Overblog\GraphQLBundle\Tests\DependencyInjection\Compiler;

/**
* Class FakeInjectedService
* Class FakeInjectedService.
*/
class FakeInjectedService
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
<?php

/*
* This file is part of the OverblogGraphQLBundle package.
*
* (c) Overblog <http://github.com/overblog/>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Overblog\GraphQLBundle\Tests\DependencyInjection\Compiler;

use Overblog\GraphQLBundle\DependencyInjection\Compiler\ResolverTaggedServiceMappingPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;

/**
* Class ResolverTaggedServiceMappingPassTest
* @package DependencyInjection
* Class ResolverTaggedServiceMappingPassTest.
*/
class ResolverTaggedServiceMappingPassTest extends \PHPUnit_Framework_TestCase
{
Expand All @@ -27,13 +35,13 @@ public function setUp()

$container->register(
'overblog_graphql.resolver_resolver',
"Overblog\\GraphQLBundle\\Resolver\\ResolverResolver"
'Overblog\\GraphQLBundle\\Resolver\\ResolverResolver'
);

$testResolver = new Definition('Overblog\GraphQLBundle\Tests\DependencyInjection\Compiler\ResolverTestService');
$testResolver
->addTag( 'overblog_graphql.resolver', [
'alias' => 'test_resolver', 'method' => 'doSomethingWithContainer'
->addTag('overblog_graphql.resolver', [
'alias' => 'test_resolver', 'method' => 'doSomethingWithContainer',
]);

$container->setDefinition('test_resolver', $testResolver);
Expand All @@ -43,9 +51,9 @@ public function setUp()

private function addCompilerPassesAndCompile()
{
$this->container->addCompilerPass(new ResolverTaggedServiceMappingPass());
$this->container->addCompilerPass(new FakeCompilerPass());
$this->container->compile();
$this->container->addCompilerPass(new ResolverTaggedServiceMappingPass());
$this->container->addCompilerPass(new FakeCompilerPass());
$this->container->compile();
}

public function testCompilationWorksPassConfigDirective()
Expand Down
12 changes: 10 additions & 2 deletions Tests/DependencyInjection/Compiler/ResolverTestService.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
<?php

/*
* This file is part of the OverblogGraphQLBundle package.
*
* (c) Overblog <http://github.com/overblog/>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace DependencyInjection\Compiler;

use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerAwareTrait;

/**
* Class ResolverTestService
* @package DependencyInjection\Compiler
* Class ResolverTestService.
*/
class ResolverTestService implements ContainerAwareInterface
{
Expand Down
1 change: 0 additions & 1 deletion Tests/Functional/Controller/GraphControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ public function testEndpointWithEmptyJsonBodyQuery()
$client->getResponse()->getContent();
}


/**
* @expectedException \Symfony\Component\HttpKernel\Exception\BadRequestHttpException
* @expectedExceptionMessage POST body sent invalid JSON
Expand Down
25 changes: 4 additions & 21 deletions Tests/Functional/Relay/Mutation/MutationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,6 @@ public function testContainsCorrectInput()
type {
name
kind
ofType {
name
kind
}
}
}
}
Expand All @@ -115,12 +111,8 @@ public function testContainsCorrectInput()
[
'name' => 'clientMutationId',
'type' => [
'name' => null,
'kind' => 'NON_NULL',
'ofType' => [
'name' => 'String',
'kind' => 'SCALAR',
],
'name' => 'String',
'kind' => 'SCALAR',
],
],
],
Expand All @@ -142,10 +134,6 @@ public function testContainsCorrectPayload()
type {
name
kind
ofType {
name
kind
}
}
}
}
Expand All @@ -162,18 +150,13 @@ public function testContainsCorrectPayload()
'type' => [
'name' => 'Int',
'kind' => 'SCALAR',
'ofType' => null,
],
],
[
'name' => 'clientMutationId',
'type' => [
'name' => null,
'kind' => 'NON_NULL',
'ofType' => [
'name' => 'String',
'kind' => 'SCALAR',
],
'name' => 'String',
'kind' => 'SCALAR',
],
],

Expand Down
24 changes: 24 additions & 0 deletions Tests/Relay/Connection/Output/ConnectionBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,30 @@ public function testRespectsLastAndAfterAndBeforeExactlyRight()
$this->assertEquals($expected, $actual);
}

/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage Argument "first" must be a non-negative integer
*/
public function testThrowsAnErrorIfFirstLessThan0()
{
ConnectionBuilder::connectionFromArray(
$this->letters,
['first' => -1]
);
}

/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage Argument "last" must be a non-negative integer
*/
public function testThrowsAnErrorIfLastLessThan0()
{
ConnectionBuilder::connectionFromArray(
$this->letters,
['last' => -1]
);
}

public function testReturnsNoElementsIfFirstIs0()
{
$actual = ConnectionBuilder::connectionFromArray(
Expand Down
12 changes: 11 additions & 1 deletion Tests/Relay/Connection/PaginatorTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
<?php

/*
* This file is part of the OverblogGraphQLBundle package.
*
* (c) Overblog <http://github.com/overblog/>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Overblog\GraphQLBundle\Tests\Relay\Connection;

use Overblog\GraphQLBundle\Definition\Argument;
Expand Down Expand Up @@ -28,7 +37,7 @@ public function testForwardAfter()
return array_fill(0, 6, 'item');
});

$this->assertCount(5, $paginator->forward(new Argument(['first' => 5, 'after' => base64_encode('arrayconnection:5') ]))->edges);
$this->assertCount(5, $paginator->forward(new Argument(['first' => 5, 'after' => base64_encode('arrayconnection:5')]))->edges);
}

public function testBackward()
Expand Down Expand Up @@ -88,6 +97,7 @@ public function testAuto()
$countCalled = false;
$result = $paginator->auto(new Argument(['last' => 5]), function () use (&$countCalled) {
$countCalled = true;

return 10;
});

Expand Down
8 changes: 6 additions & 2 deletions Tests/Request/ExecutorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ public function setUp()
*/
public function testInvalidExecutorReturnNotObject()
{
$this->executor->setExecutor(function() { return false; });
$this->executor->setExecutor(function () {
return false;
});
$this->executor->execute($this->request);
}

Expand All @@ -56,7 +58,9 @@ public function testInvalidExecutorReturnNotObject()
*/
public function testInvalidExecutorReturnInvalidObject()
{
$this->executor->setExecutor(function() { return new \stdClass(); });
$this->executor->setExecutor(function () {
return new \stdClass();
});
$this->executor->execute($this->request);
}

Expand Down