Skip to content

Commit

Permalink
Include client directives when inlining fragments (#78)
Browse files Browse the repository at this point in the history
  • Loading branch information
spawnia authored Nov 9, 2022
1 parent 5d6278d commit 20f6ca6
Show file tree
Hide file tree
Showing 56 changed files with 621 additions and 153 deletions.
1 change: 1 addition & 0 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
->notPath('vendor')
->notPath('/examples\/.*\/expected/')
->notPath('/examples\/.*\/generated/')
->notPath('/examples\/.*\/sailor/')
->in(__DIR__)
->name('*.php')
->ignoreDotFiles(true)
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

## v0.26.1

### Fixed

- Include client directives when inlining fragments

## v0.26.0

### Added
Expand Down
2 changes: 1 addition & 1 deletion examples/custom-types/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
}
],
"scripts": {
"move-package": "rsync -r ../../ sailor --exclude examples --exclude vendor --exclude .idea --exclude .build --delete",
"move-package": "rsync -r ../../ sailor --exclude examples --exclude vendor --exclude .idea --exclude .git --exclude .build --delete",
"pre-install-cmd": "@move-package",
"pre-update-cmd": "@move-package"
}
Expand Down
5 changes: 2 additions & 3 deletions examples/custom-types/src/CustomDateTypeConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Spawnia\Sailor\CustomTypesSrc;

use DateTime;
use GraphQL\Type\Definition\ScalarType;
use GraphQL\Type\Definition\Type;
use Nette\PhpGenerator\ClassType;
Expand Down Expand Up @@ -34,7 +33,7 @@ public function typeConverter(): string

public function typeReference(): string
{
return '\\' . DateTime::class;
return '\\' . \DateTime::class;
}

public function generateClasses(): iterable
Expand All @@ -44,7 +43,7 @@ public function generateClasses(): iterable

protected function decorateTypeConverterClass(Type $type, ClassType $class, Method $fromGraphQL, Method $toGraphQL): ClassType
{
$dateTimeClass = DateTime::class;
$dateTimeClass = \DateTime::class;
$format = self::FORMAT;

$fromGraphQL->setReturnType($dateTimeClass);
Expand Down
7 changes: 2 additions & 5 deletions examples/custom-types/src/Enum.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,15 @@

namespace Spawnia\Sailor\CustomTypesSrc;

use InvalidArgumentException;
use ReflectionClass;

abstract class Enum
{
public string $value;

public function __construct(string $value)
{
$reflection = new ReflectionClass($this);
$reflection = new \ReflectionClass($this);
if (! in_array($value, $reflection->getConstants())) {
throw new InvalidArgumentException('Unexpect enum value: ' . $value);
throw new \InvalidArgumentException('Unexpect enum value: ' . $value);
}

$this->value = $value;
Expand Down
2 changes: 1 addition & 1 deletion examples/input/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
}
],
"scripts": {
"move-package": "rsync -r ../../ sailor --exclude examples --exclude vendor --exclude .idea --exclude .build --delete",
"move-package": "rsync -r ../../ sailor --exclude examples --exclude vendor --exclude .idea --exclude .git --exclude .build --delete",
"pre-install-cmd": "@move-package",
"pre-update-cmd": "@move-package"
}
Expand Down
2 changes: 1 addition & 1 deletion examples/install/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
}
],
"scripts": {
"move-package": "rsync -r ../../ sailor --exclude examples --exclude vendor --exclude .idea --exclude .build --delete",
"move-package": "rsync -r ../../ sailor --exclude examples --exclude vendor --exclude .idea --exclude .git --exclude .build --delete",
"pre-install-cmd": "@move-package",
"pre-update-cmd": "@move-package"
}
Expand Down
2 changes: 1 addition & 1 deletion examples/php-keywords/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
}
],
"scripts": {
"move-package": "rsync -r ../../ sailor --exclude examples --exclude vendor --exclude .idea --exclude .build --delete",
"move-package": "rsync -r ../../ sailor --exclude examples --exclude vendor --exclude .idea --exclude .git --exclude .build --delete",
"pre-install-cmd": "@move-package",
"pre-update-cmd": "@move-package"
}
Expand Down
2 changes: 1 addition & 1 deletion examples/polymorphic/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
}
],
"scripts": {
"move-package": "rsync -r ../../ sailor --exclude examples --exclude vendor --exclude .idea --exclude .build --delete",
"move-package": "rsync -r ../../ sailor --exclude examples --exclude vendor --exclude .idea --exclude .git --exclude .build --delete",
"pre-install-cmd": "@move-package",
"pre-update-cmd": "@move-package"
}
Expand Down
2 changes: 1 addition & 1 deletion examples/simple/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
}
],
"scripts": {
"move-package": "rsync -r ../../ sailor --exclude examples --exclude vendor --exclude .idea --exclude .build --delete",
"move-package": "rsync -r ../../ sailor --exclude examples --exclude vendor --exclude .idea --exclude .git --exclude .build --delete",
"pre-install-cmd": "@move-package",
"pre-update-cmd": "@move-package"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

declare(strict_types=1);

namespace Spawnia\Sailor\Simple\Operations;

/**
* @extends \Spawnia\Sailor\Operation<\Spawnia\Sailor\Simple\Operations\ClientDirectiveFragmentSpreadQuery\ClientDirectiveFragmentSpreadQueryResult>
*/
class ClientDirectiveFragmentSpreadQuery extends \Spawnia\Sailor\Operation
{
/**
* @param bool $value
*/
public static function execute($value): ClientDirectiveFragmentSpreadQuery\ClientDirectiveFragmentSpreadQueryResult
{
return self::executeOperation(
$value,
);
}

protected static function converters(): array
{
static $converters;

return $converters ??= [
['value', new \Spawnia\Sailor\Convert\NonNullConverter(new \Spawnia\Sailor\Convert\BooleanConverter)],
];
}

public static function document(): string
{
return /* @lang GraphQL */ 'query ClientDirectiveFragmentSpreadQuery($value: Boolean!) {
__typename
... on Query @skip(if: $value) {
twoArgs
}
}';
}

public static function endpoint(): string
{
return 'simple';
}

public static function config(): string
{
return \Safe\realpath(__DIR__ . '/../../sailor.php');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

declare(strict_types=1);

namespace Spawnia\Sailor\Simple\Operations\ClientDirectiveFragmentSpreadQuery;

/**
* @property string $__typename
* @property string|null $twoArgs
*/
class ClientDirectiveFragmentSpreadQuery extends \Spawnia\Sailor\ObjectLike
{
/**
* @param string|null $twoArgs
*/
public static function make($twoArgs = 'Special default value that allows Sailor to differentiate between explicitly passing null and not passing a value at all.'): self
{
$instance = new self;

$instance->__typename = 'Query';
if ($twoArgs !== self::UNDEFINED) {
$instance->twoArgs = $twoArgs;
}

return $instance;
}

protected function converters(): array
{
static $converters;

return $converters ??= [
'__typename' => new \Spawnia\Sailor\Convert\NonNullConverter(new \Spawnia\Sailor\Convert\StringConverter),
'twoArgs' => new \Spawnia\Sailor\Convert\NullConverter(new \Spawnia\Sailor\Convert\IDConverter),
];
}

public static function endpoint(): string
{
return 'simple';
}

public static function config(): string
{
return \Safe\realpath(__DIR__ . '/../../../sailor.php');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

namespace Spawnia\Sailor\Simple\Operations\ClientDirectiveFragmentSpreadQuery;

class ClientDirectiveFragmentSpreadQueryErrorFreeResult extends \Spawnia\Sailor\ErrorFreeResult
{
public ClientDirectiveFragmentSpreadQuery $data;

public static function endpoint(): string
{
return 'simple';
}

public static function config(): string
{
return \Safe\realpath(__DIR__ . '/../../../sailor.php');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

declare(strict_types=1);

namespace Spawnia\Sailor\Simple\Operations\ClientDirectiveFragmentSpreadQuery;

class ClientDirectiveFragmentSpreadQueryResult extends \Spawnia\Sailor\Result
{
public ?ClientDirectiveFragmentSpreadQuery $data = null;

protected function setData(\stdClass $data): void
{
$this->data = ClientDirectiveFragmentSpreadQuery::fromStdClass($data);
}

/**
* Useful for instantiation of successful mocked results.
*
* @return static
*/
public static function fromData(ClientDirectiveFragmentSpreadQuery $data): self
{
$instance = new static;
$instance->data = $data;

return $instance;
}

public function errorFree(): ClientDirectiveFragmentSpreadQueryErrorFreeResult
{
return ClientDirectiveFragmentSpreadQueryErrorFreeResult::fromResult($this);
}

public static function endpoint(): string
{
return 'simple';
}

public static function config(): string
{
return \Safe\realpath(__DIR__ . '/../../../sailor.php');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

declare(strict_types=1);

namespace Spawnia\Sailor\Simple\Operations;

/**
* @extends \Spawnia\Sailor\Operation<\Spawnia\Sailor\Simple\Operations\ClientDirectiveInlineFragmentQuery\ClientDirectiveInlineFragmentQueryResult>
*/
class ClientDirectiveInlineFragmentQuery extends \Spawnia\Sailor\Operation
{
/**
* @param bool $value
*/
public static function execute($value): ClientDirectiveInlineFragmentQuery\ClientDirectiveInlineFragmentQueryResult
{
return self::executeOperation(
$value,
);
}

protected static function converters(): array
{
static $converters;

return $converters ??= [
['value', new \Spawnia\Sailor\Convert\NonNullConverter(new \Spawnia\Sailor\Convert\BooleanConverter)],
];
}

public static function document(): string
{
return /* @lang GraphQL */ 'query ClientDirectiveInlineFragmentQuery($value: Boolean!) {
__typename
... on Query @skip(if: $value) {
twoArgs
}
}';
}

public static function endpoint(): string
{
return 'simple';
}

public static function config(): string
{
return \Safe\realpath(__DIR__ . '/../../sailor.php');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

declare(strict_types=1);

namespace Spawnia\Sailor\Simple\Operations\ClientDirectiveInlineFragmentQuery;

/**
* @property string $__typename
* @property string|null $twoArgs
*/
class ClientDirectiveInlineFragmentQuery extends \Spawnia\Sailor\ObjectLike
{
/**
* @param string|null $twoArgs
*/
public static function make($twoArgs = 'Special default value that allows Sailor to differentiate between explicitly passing null and not passing a value at all.'): self
{
$instance = new self;

$instance->__typename = 'Query';
if ($twoArgs !== self::UNDEFINED) {
$instance->twoArgs = $twoArgs;
}

return $instance;
}

protected function converters(): array
{
static $converters;

return $converters ??= [
'__typename' => new \Spawnia\Sailor\Convert\NonNullConverter(new \Spawnia\Sailor\Convert\StringConverter),
'twoArgs' => new \Spawnia\Sailor\Convert\NullConverter(new \Spawnia\Sailor\Convert\IDConverter),
];
}

public static function endpoint(): string
{
return 'simple';
}

public static function config(): string
{
return \Safe\realpath(__DIR__ . '/../../../sailor.php');
}
}
Loading

0 comments on commit 20f6ca6

Please sign in to comment.