Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
spawnia committed Apr 13, 2022
2 parents 69eef54 + bb06ef5 commit 18af0f8
Show file tree
Hide file tree
Showing 32 changed files with 1,219 additions and 59 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

### Added

- Support fragments

### Fixed

- Merge fields between diverging subtrees within inline fragments

## v0.19.0

### Added
Expand Down
71 changes: 71 additions & 0 deletions examples/polymorphic/expected/Operations/NodeWithFragments.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php

declare(strict_types=1);

namespace Spawnia\Sailor\Polymorphic\Operations;

/**
* @extends \Spawnia\Sailor\Operation<\Spawnia\Sailor\Polymorphic\Operations\NodeWithFragments\NodeWithFragmentsResult>
*/
class NodeWithFragments extends \Spawnia\Sailor\Operation
{
/**
* @param string $id
*/
public static function execute($id): NodeWithFragments\NodeWithFragmentsResult
{
return self::executeOperation(
$id,
);
}

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

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

public static function document(): string
{
return /* @lang GraphQL */ 'query NodeWithFragments($id: ID!) {
__typename
node(id: $id) {
__typename
node {
__typename
node {
__typename
id
... on User {
id
}
}
}
... on Task {
done
node {
__typename
node {
__typename
... on User {
name
}
}
}
}
... on Post {
id
title
}
}
}';
}

public static function endpoint(): string
{
return 'polymorphic';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

declare(strict_types=1);

namespace Spawnia\Sailor\Polymorphic\Operations\NodeWithFragments\Node\Node\Node;

/**
* @property string $id
* @property string $__typename
*/
class Post extends \Spawnia\Sailor\ObjectLike
{
/**
* @param string $id
*/
public static function make($id): self
{
$instance = new self;

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

return $instance;
}

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

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

public static function endpoint(): string
{
return 'polymorphic';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

declare(strict_types=1);

namespace Spawnia\Sailor\Polymorphic\Operations\NodeWithFragments\Node\Node\Node;

/**
* @property string $id
* @property string $__typename
*/
class Task extends \Spawnia\Sailor\ObjectLike
{
/**
* @param string $id
*/
public static function make($id): self
{
$instance = new self;

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

return $instance;
}

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

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

public static function endpoint(): string
{
return 'polymorphic';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

declare(strict_types=1);

namespace Spawnia\Sailor\Polymorphic\Operations\NodeWithFragments\Node\Node\Node;

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

if ($id !== self::UNDEFINED) {
$instance->id = $id;
}
$instance->__typename = 'Node';
if ($name !== self::UNDEFINED) {
$instance->name = $name;
}

return $instance;
}

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

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

public static function endpoint(): string
{
return 'polymorphic';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

declare(strict_types=1);

namespace Spawnia\Sailor\Polymorphic\Operations\NodeWithFragments\Node\Node;

/**
* @property string $__typename
* @property \Spawnia\Sailor\Polymorphic\Operations\NodeWithFragments\Node\Node\Node\User|\Spawnia\Sailor\Polymorphic\Operations\NodeWithFragments\Node\Node\Node\Task|\Spawnia\Sailor\Polymorphic\Operations\NodeWithFragments\Node\Node\Node\Post|null $node
*/
class Post extends \Spawnia\Sailor\ObjectLike
{
/**
* @param \Spawnia\Sailor\Polymorphic\Operations\NodeWithFragments\Node\Node\Node\User|\Spawnia\Sailor\Polymorphic\Operations\NodeWithFragments\Node\Node\Node\Task|\Spawnia\Sailor\Polymorphic\Operations\NodeWithFragments\Node\Node\Node\Post|null $node
*/
public static function make($node = '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 = 'Node';
if ($node !== self::UNDEFINED) {
$instance->node = $node;
}

return $instance;
}

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

return $converters ??= [
'__typename' => new \Spawnia\Sailor\Convert\NonNullConverter(new \Spawnia\Sailor\Convert\StringConverter),
'node' => new \Spawnia\Sailor\Convert\NullConverter(new \Spawnia\Sailor\Convert\PolymorphicConverter([
'User' => '\\Spawnia\\Sailor\\Polymorphic\\Operations\\NodeWithFragments\\Node\\Node\\Node\\User',
'Task' => '\\Spawnia\\Sailor\\Polymorphic\\Operations\\NodeWithFragments\\Node\\Node\\Node\\Task',
'Post' => '\\Spawnia\\Sailor\\Polymorphic\\Operations\\NodeWithFragments\\Node\\Node\\Node\\Post',
])),
];
}

public static function endpoint(): string
{
return 'polymorphic';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

declare(strict_types=1);

namespace Spawnia\Sailor\Polymorphic\Operations\NodeWithFragments\Node\Node;

/**
* @property string $__typename
* @property \Spawnia\Sailor\Polymorphic\Operations\NodeWithFragments\Node\Node\Node\User|\Spawnia\Sailor\Polymorphic\Operations\NodeWithFragments\Node\Node\Node\Task|\Spawnia\Sailor\Polymorphic\Operations\NodeWithFragments\Node\Node\Node\Post|null $node
*/
class Task extends \Spawnia\Sailor\ObjectLike
{
/**
* @param \Spawnia\Sailor\Polymorphic\Operations\NodeWithFragments\Node\Node\Node\User|\Spawnia\Sailor\Polymorphic\Operations\NodeWithFragments\Node\Node\Node\Task|\Spawnia\Sailor\Polymorphic\Operations\NodeWithFragments\Node\Node\Node\Post|null $node
*/
public static function make($node = '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 = 'Node';
if ($node !== self::UNDEFINED) {
$instance->node = $node;
}

return $instance;
}

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

return $converters ??= [
'__typename' => new \Spawnia\Sailor\Convert\NonNullConverter(new \Spawnia\Sailor\Convert\StringConverter),
'node' => new \Spawnia\Sailor\Convert\NullConverter(new \Spawnia\Sailor\Convert\PolymorphicConverter([
'User' => '\\Spawnia\\Sailor\\Polymorphic\\Operations\\NodeWithFragments\\Node\\Node\\Node\\User',
'Task' => '\\Spawnia\\Sailor\\Polymorphic\\Operations\\NodeWithFragments\\Node\\Node\\Node\\Task',
'Post' => '\\Spawnia\\Sailor\\Polymorphic\\Operations\\NodeWithFragments\\Node\\Node\\Node\\Post',
])),
];
}

public static function endpoint(): string
{
return 'polymorphic';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

declare(strict_types=1);

namespace Spawnia\Sailor\Polymorphic\Operations\NodeWithFragments\Node\Node;

/**
* @property string $__typename
* @property \Spawnia\Sailor\Polymorphic\Operations\NodeWithFragments\Node\Node\Node\User|\Spawnia\Sailor\Polymorphic\Operations\NodeWithFragments\Node\Node\Node\Task|\Spawnia\Sailor\Polymorphic\Operations\NodeWithFragments\Node\Node\Node\Post|null $node
*/
class User extends \Spawnia\Sailor\ObjectLike
{
/**
* @param \Spawnia\Sailor\Polymorphic\Operations\NodeWithFragments\Node\Node\Node\User|\Spawnia\Sailor\Polymorphic\Operations\NodeWithFragments\Node\Node\Node\Task|\Spawnia\Sailor\Polymorphic\Operations\NodeWithFragments\Node\Node\Node\Post|null $node
*/
public static function make($node = '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 = 'Node';
if ($node !== self::UNDEFINED) {
$instance->node = $node;
}

return $instance;
}

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

return $converters ??= [
'__typename' => new \Spawnia\Sailor\Convert\NonNullConverter(new \Spawnia\Sailor\Convert\StringConverter),
'node' => new \Spawnia\Sailor\Convert\NullConverter(new \Spawnia\Sailor\Convert\PolymorphicConverter([
'User' => '\\Spawnia\\Sailor\\Polymorphic\\Operations\\NodeWithFragments\\Node\\Node\\Node\\User',
'Task' => '\\Spawnia\\Sailor\\Polymorphic\\Operations\\NodeWithFragments\\Node\\Node\\Node\\Task',
'Post' => '\\Spawnia\\Sailor\\Polymorphic\\Operations\\NodeWithFragments\\Node\\Node\\Node\\Post',
])),
];
}

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

0 comments on commit 18af0f8

Please sign in to comment.