forked from spawnia/sailor
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle fields omitted through
@skip
or @include
- Loading branch information
1 parent
3c167f4
commit 17d6d74
Showing
7 changed files
with
173 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Spawnia\Sailor\Simple\Operations; | ||
|
||
/** | ||
* @extends \Spawnia\Sailor\Operation<\Spawnia\Sailor\Simple\Operations\SkipNonNullable\SkipNonNullableResult> | ||
*/ | ||
class SkipNonNullable extends \Spawnia\Sailor\Operation | ||
{ | ||
/** | ||
* @param bool $value | ||
*/ | ||
public static function execute($value): SkipNonNullable\SkipNonNullableResult | ||
{ | ||
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 SkipNonNullable($value: Boolean!) { | ||
__typename | ||
nonNullable @skip(if: $value) | ||
}'; | ||
} | ||
|
||
public static function endpoint(): string | ||
{ | ||
return 'simple'; | ||
} | ||
|
||
public static function config(): string | ||
{ | ||
return \Safe\realpath(__DIR__ . '/../../sailor.php'); | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
examples/simple/expected/Operations/SkipNonNullable/SkipNonNullable.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Spawnia\Sailor\Simple\Operations\SkipNonNullable; | ||
|
||
/** | ||
* @property string $nonNullable | ||
* @property string $__typename | ||
*/ | ||
class SkipNonNullable extends \Spawnia\Sailor\ObjectLike | ||
{ | ||
/** | ||
* @param string $nonNullable | ||
*/ | ||
public static function make($nonNullable): self | ||
{ | ||
$instance = new self; | ||
|
||
if ($nonNullable !== self::UNDEFINED) { | ||
$instance->nonNullable = $nonNullable; | ||
} | ||
$instance->__typename = 'Query'; | ||
|
||
return $instance; | ||
} | ||
|
||
protected function converters(): array | ||
{ | ||
static $converters; | ||
|
||
return $converters ??= [ | ||
'nonNullable' => new \Spawnia\Sailor\Convert\NonNullConverter(new \Spawnia\Sailor\Convert\StringConverter), | ||
'__typename' => new \Spawnia\Sailor\Convert\NonNullConverter(new \Spawnia\Sailor\Convert\StringConverter), | ||
]; | ||
} | ||
|
||
public static function endpoint(): string | ||
{ | ||
return 'simple'; | ||
} | ||
|
||
public static function config(): string | ||
{ | ||
return \Safe\realpath(__DIR__ . '/../../../sailor.php'); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
examples/simple/expected/Operations/SkipNonNullable/SkipNonNullableErrorFreeResult.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Spawnia\Sailor\Simple\Operations\SkipNonNullable; | ||
|
||
class SkipNonNullableErrorFreeResult extends \Spawnia\Sailor\ErrorFreeResult | ||
{ | ||
public SkipNonNullable $data; | ||
|
||
public static function endpoint(): string | ||
{ | ||
return 'simple'; | ||
} | ||
|
||
public static function config(): string | ||
{ | ||
return \Safe\realpath(__DIR__ . '/../../../sailor.php'); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
examples/simple/expected/Operations/SkipNonNullable/SkipNonNullableResult.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Spawnia\Sailor\Simple\Operations\SkipNonNullable; | ||
|
||
class SkipNonNullableResult extends \Spawnia\Sailor\Result | ||
{ | ||
public ?SkipNonNullable $data = null; | ||
|
||
protected function setData(\stdClass $data): void | ||
{ | ||
$this->data = SkipNonNullable::fromStdClass($data); | ||
} | ||
|
||
/** | ||
* Useful for instantiation of successful mocked results. | ||
* | ||
* @return static | ||
*/ | ||
public static function fromData(SkipNonNullable $data): self | ||
{ | ||
$instance = new static; | ||
$instance->data = $data; | ||
|
||
return $instance; | ||
} | ||
|
||
public function errorFree(): SkipNonNullableErrorFreeResult | ||
{ | ||
return SkipNonNullableErrorFreeResult::fromResult($this); | ||
} | ||
|
||
public static function endpoint(): string | ||
{ | ||
return 'simple'; | ||
} | ||
|
||
public static function config(): string | ||
{ | ||
return \Safe\realpath(__DIR__ . '/../../../sailor.php'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters