Skip to content
This repository has been archived by the owner on Feb 10, 2019. It is now read-only.

Add setup method to field #374

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
15 changes: 14 additions & 1 deletion src/Folklore/GraphQL/Support/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@
class Field extends Fluent
{

/**
* Override this in your queries or mutations
* to setup models for authorize, authenticated, resolve
*/
public function setup($root, $args, $context)
{
return true;
}

/**
* Override this in your queries or mutations
* to provide custom authorization
Expand Down Expand Up @@ -47,13 +56,17 @@ protected function getResolver()
return null;
}

$setup = array($this, 'setup');
$resolver = array($this, 'resolve');
$authenticate = [$this, 'authenticated'];
$authorize = [$this, 'authorize'];

return function () use ($resolver, $authorize, $authenticate) {
return function () use ($setup, $resolver, $authorize, $authenticate) {
$args = func_get_args();

//Setup
call_user_func_array($setup, $args);

// Authenticated
if (call_user_func_array($authenticate, $args) !== true) {
throw new AuthorizationError('Unauthenticated');
Expand Down