diff --git a/src/Folklore/GraphQL/Support/Field.php b/src/Folklore/GraphQL/Support/Field.php index b730b0e3..64026a80 100644 --- a/src/Folklore/GraphQL/Support/Field.php +++ b/src/Folklore/GraphQL/Support/Field.php @@ -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 @@ -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');