-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Exclude fields from certain operations when not authenticated. (#65)
- Loading branch information
1 parent
42b0a73
commit 6ec8e7e
Showing
6 changed files
with
64 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
namespace Enjin\Platform\Middlewares; | ||
|
||
use Closure; | ||
use GraphQL\Executor\ExecutionResult; | ||
use GraphQL\Language\AST\OperationDefinitionNode; | ||
use GraphQL\Language\Parser; | ||
use GraphQL\Type\Schema; | ||
use Rebing\GraphQL\Support\ExecutionMiddleware\AbstractExecutionMiddleware; | ||
use Rebing\GraphQL\Support\OperationParams; | ||
|
||
class OperationDefinitionNodeStore extends AbstractExecutionMiddleware | ||
{ | ||
/** | ||
* The current request's Operation Definition Node. | ||
*/ | ||
public static OperationDefinitionNode $operationDefinitionNode; | ||
|
||
/** | ||
* Handle's middleware logic. | ||
*/ | ||
public function handle(string $schemaName, Schema $schema, OperationParams $params, $rootValue, $contextValue, Closure $next): ExecutionResult | ||
{ | ||
$documentNode = Parser::parse($params->query); | ||
$operationName = $params->operation; | ||
static::$operationDefinitionNode = collect($documentNode->definitions) | ||
->when($operationName, fn ($collection) => $collection->where('name.value', '=', $operationName)) | ||
->first(); | ||
|
||
return $next($schemaName, $schema, $params, $rootValue, $contextValue); | ||
} | ||
|
||
/** | ||
* Get the current request's operation name. | ||
*/ | ||
public static function getOperationName() | ||
{ | ||
return static::$operationDefinitionNode | ||
->getSelectionSet() | ||
->selections | ||
->offsetGet(0) | ||
->name->value; | ||
} | ||
} |