From 924bfa11673ef4a8b0a42678f3ef854224e0e383 Mon Sep 17 00:00:00 2001 From: Tyler Getsay Date: Thu, 30 Aug 2018 10:28:23 -0400 Subject: [PATCH] add setup method to field --- src/Folklore/GraphQL/Support/Field.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) 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');