Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Prev Previous commit
Next Next commit
feat(graphql): allow to enable/disable the introspection query
  • Loading branch information
epourail committed Aug 8, 2023
commit ad911b7dcda50491ec52cdcd0d1181dc8ed3096f
12 changes: 9 additions & 3 deletions src/GraphQl/Executor.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use GraphQL\Executor\ExecutionResult;
use GraphQL\GraphQL;
use GraphQL\Type\Schema;
use GraphQL\Validator\DocumentValidator;
use GraphQL\Validator\Rules\DisableIntrospection;

/**
Expand All @@ -27,16 +28,21 @@ final class Executor implements ExecutorInterface
{
public function __construct(private readonly bool $graphQlIntrospectionEnabled = true)
{
DocumentValidator::addRule(
new DisableIntrospection(
$this->graphQlIntrospectionEnabled ? DisableIntrospection::DISABLED : DisableIntrospection::ENABLED
)
);
}

/**
* {@inheritdoc}
*/
public function executeQuery(Schema $schema, $source, mixed $rootValue = null, mixed $context = null, array $variableValues = null, string $operationName = null, callable $fieldResolver = null, array $validationRules = null): ExecutionResult
{
$validationRules[] = new DisableIntrospection(
$this->graphQlIntrospectionEnabled ? DisableIntrospection::DISABLED : DisableIntrospection::ENABLED
);
// $validationRules[] = new DisableIntrospection(
// $this->graphQlIntrospectionEnabled ? DisableIntrospection::DISABLED : DisableIntrospection::ENABLED
// );

return GraphQL::executeQuery($schema, $source, $rootValue, $context, $variableValues, $operationName, $fieldResolver, $validationRules);
}
Expand Down