Skip to content

Commit

Permalink
fix resolve on connection edge
Browse files Browse the repository at this point in the history
  • Loading branch information
chrissm79 committed Aug 28, 2016
1 parent bb57e25 commit 0f44dd6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/Schema/Registrars/EdgeRegistrar.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@
namespace Nuwave\Lighthouse\Schema\Registrars;

use ReflectionClass;
use GraphQL\Type\Definition\ObjectType;
use Nuwave\Lighthouse\Schema\Registrars\BaseRegistrar;
use Nuwave\Lighthouse\Schema\Generators\EdgeTypeGenerator;
use Nuwave\Lighthouse\Support\Interfaces\ConnectionEdge;
use Nuwave\Lighthouse\Support\Definition\Fields\EdgeField;
use GraphQL\Type\Definition\ObjectType;
use Nuwave\Lighthouse\Support\Traits\GlobalIdTrait;

class EdgeRegistrar extends BaseRegistrar
{
use GlobalIdTrait;

/**
* Collection of registered type instances.
*
Expand Down Expand Up @@ -52,7 +55,7 @@ public function instance($name, $fresh = false, ObjectType $type = null)
}

if ($name instanceof ConnectionEdge) {
$intance = $this->createEdge($name);
$instance = $this->createEdge($name);
$this->instances->put($instanceName, $instance);

return $instance;
Expand Down Expand Up @@ -91,8 +94,12 @@ protected function createEdge(ConnectionEdge $edge)

return new EdgeField([
'type' => $this->createInstance($edge->name(), $graphqlType),
'resolve' => function ($payload) {
return call_user_func_array([$edge, 'cursor'], [$payload]);
'resolve' => function ($payload) use ($edge) {
$model = $edge->edge($payload);
$cursor = call_user_func_array([$edge, 'cursor'], [$payload]);
$model->relayCursor = $this->encodeGlobalId('arrayconnection', $cursor);

return $model;
},
]);
}
Expand Down
8 changes: 8 additions & 0 deletions src/Support/Interfaces/ConnectionEdge.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ public function name();
*/
public function type();

/**
* Extract edge from payload.
*
* @param mixed $payload
* @return mixed
*/
public function edge($payload);

/**
* Resolve cursor.
*
Expand Down

0 comments on commit 0f44dd6

Please sign in to comment.