From ff63e07b05e5973af0a0c646f8ca4da2a4809f71 Mon Sep 17 00:00:00 2001 From: Daniel Tschinder Date: Sun, 11 Feb 2018 18:19:52 +0100 Subject: [PATCH] Improve introspection types + new getIntrospectionQuery() This adds a new function `getIntrospectionQuery()` which allows for some minor configuration over the resulting query text: to exclude descriptions if your use case does not require them. ref: graphql/graphql-js#1113 --- src/Type/Introspection.php | 117 ++++-------------- tests/Type/EnumTypeTest.php | 1 - tests/Type/IntrospectionTest.php | 2 +- tests/Validator/AbstractQuerySecurityTest.php | 2 +- 4 files changed, 23 insertions(+), 99 deletions(-) diff --git a/src/Type/Introspection.php b/src/Type/Introspection.php index 7326ea4..57be002 100644 --- a/src/Type/Introspection.php +++ b/src/Type/Introspection.php @@ -37,11 +37,25 @@ class Introspection private static $map = []; /** + * Options: + * - descriptions + * Whether to include descriptions in the introspection result. + * Default: true + * + * @param array $options * @return string */ - public static function getIntrospectionQuery($includeDescription = true) + public static function getIntrospectionQuery($options = []) { - $withDescription = <<<'EOD' + if (is_bool($options)) { + trigger_error('Calling Introspection::getIntrospectionQuery(boolean) is deprecated. Please use Introspection::getIntrospectionQuery(["descriptions" => boolean]).', E_USER_DEPRECATED); + $descriptions = $options; + } else { + $descriptions = !array_key_exists('descriptions', $options) || $options['descriptions'] === true; + } + $descriptionField = $descriptions ? 'description' : ''; + + return << false]); $expected = array ( 'data' => array ( diff --git a/tests/Validator/AbstractQuerySecurityTest.php b/tests/Validator/AbstractQuerySecurityTest.php index 885fc99..7e5e36b 100644 --- a/tests/Validator/AbstractQuerySecurityTest.php +++ b/tests/Validator/AbstractQuerySecurityTest.php @@ -53,7 +53,7 @@ abstract class AbstractQuerySecurityTest extends \PHPUnit_Framework_TestCase protected function assertIntrospectionQuery($maxExpected) { - $query = Introspection::getIntrospectionQuery(true); + $query = Introspection::getIntrospectionQuery(); $this->assertMaxValue($query, $maxExpected); }