diff --git a/composer.json b/composer.json index 43efccd5386..183e8abf5ea 100644 --- a/composer.json +++ b/composer.json @@ -67,7 +67,7 @@ "symfony/validator": "^3.3 || ^4.0", "symfony/web-profiler-bundle": "^3.3 || ^4.0", "symfony/yaml": "^3.3 || ^4.0", - "webonyx/graphql-php": "^0.10.2" + "webonyx/graphql-php": "^0.11.5" }, "conflict": { "symfony/dependency-injection": "<3.4" diff --git a/features/bootstrap/GraphqlContext.php b/features/bootstrap/GraphqlContext.php index fc31e4efc3c..e8fed58bb88 100644 --- a/features/bootstrap/GraphqlContext.php +++ b/features/bootstrap/GraphqlContext.php @@ -77,6 +77,14 @@ public function ISendTheFollowingGraphqlRequest(PyStringNode $request) $this->sendGraphqlRequest(); } + /** + * @When I post the following GraphQL request: + */ + public function IPostTheFollowingGraphqlRequest(PyStringNode $request) + { + $this->postGraphqlRequest($request); + } + /** * @When I send the GraphQL request with variables: */ @@ -100,4 +108,12 @@ private function sendGraphqlRequest() $this->request->setHttpHeader('Accept', null); $this->restContext->iSendARequestTo('GET', '/graphql?'.http_build_query($this->graphqlRequest)); } + + private function postGraphqlRequest($body) + { + $this->request->setHttpHeader('Accept', null); + $this->request->setHttpHeader('Content-Type', 'application/json'); + + $this->restContext->iSendARequestTo('POST', '/graphql', $body); + } } diff --git a/features/graphql/introspection.feature b/features/graphql/introspection.feature index 063519d60e2..182a2bc6756 100644 --- a/features/graphql/introspection.feature +++ b/features/graphql/introspection.feature @@ -168,6 +168,17 @@ Feature: GraphQL introspection support And the JSON node "data.__schema.queryType.fields[0].args[0].type.ofType.name" should be equal to "ID" And the JSON node "data.__schema.queryType.fields[0].args[0].type.ofType.kind" should be equal to "SCALAR" + Scenario: GraphiQL can print the documentation + When I post the following GraphQL request: + """ + {"query":"\n query IntrospectionQuery {\n __schema {\n queryType { name }\n mutationType { name }\n subscriptionType { name }\n types {\n ...FullType\n }\n directives {\n name\n description\n locations\n args {\n ...InputValue\n }\n }\n }\n }\n\n fragment FullType on __Type {\n kind\n name\n description\n fields(includeDeprecated: true) {\n name\n description\n args {\n ...InputValue\n }\n type {\n ...TypeRef\n }\n isDeprecated\n deprecationReason\n }\n inputFields {\n ...InputValue\n }\n interfaces {\n ...TypeRef\n }\n enumValues(includeDeprecated: true) {\n name\n description\n isDeprecated\n deprecationReason\n }\n possibleTypes {\n ...TypeRef\n }\n }\n\n fragment InputValue on __InputValue {\n name\n description\n type { ...TypeRef }\n defaultValue\n }\n\n fragment TypeRef on __Type {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n }\n }\n }\n }\n }\n }\n }\n }\n"} + """ + Then the response status code should be 200 + And the header "Content-Type" should be equal to "application/json" + And the JSON node "data.__schema.queryType.name" should be equal to "Query" + And the JSON node "data.__schema.mutationType.name" should be equal to "Mutation" + And the JSON node "data.__schema.types[0].kind" should be equal to "OBJECT" + Scenario: Introspect an Iterable type field When I send the following GraphQL request: """ diff --git a/src/Bridge/Symfony/Bundle/Resources/public/init-graphiql.js b/src/Bridge/Symfony/Bundle/Resources/public/init-graphiql.js index 8225078b3e8..47001fc72d0 100644 --- a/src/Bridge/Symfony/Bundle/Resources/public/init-graphiql.js +++ b/src/Bridge/Symfony/Bundle/Resources/public/init-graphiql.js @@ -61,8 +61,13 @@ function graphQLFetcher(graphQLParams) { return response.text(); }).then(function (responseBody) { try { - return JSON.parse(responseBody); + var jsonResponse = JSON.parse(responseBody); + if (jsonResponse.errors !== undefined) { + console.error('An error occured when fetching the query:', jsonResponse.errors); + } + return jsonResponse; } catch (error) { + console.error(responseBody); return responseBody; } }); diff --git a/src/GraphQl/Type/Definition/InputUnionType.php b/src/GraphQl/Type/Definition/InputUnionType.php index de5a70c96b7..b3aafe3acea 100644 --- a/src/GraphQl/Type/Definition/InputUnionType.php +++ b/src/GraphQl/Type/Definition/InputUnionType.php @@ -18,7 +18,7 @@ use GraphQL\Type\Definition\InputObjectType; use GraphQL\Type\Definition\InputType; use GraphQL\Type\Definition\LeafType; -use GraphQL\Type\Definition\Type; +use GraphQL\Type\Definition\UnionType; use GraphQL\Utils\Utils; /** @@ -28,23 +28,20 @@ * * @author Alan Poulain */ -final class InputUnionType extends Type implements InputType, LeafType +final class InputUnionType extends UnionType implements InputType, LeafType { /** * @var InputObjectType[] */ private $types; - /** - * @var array - */ - private $config; - /** * @throws InvariantViolation */ public function __construct(array $config) { + parent::__construct($config); + if (!isset($config['name'])) { $config['name'] = $this->tryInferName(); } @@ -85,8 +82,6 @@ public function getTypes(): array */ public function assertValid() { - parent::assertValid(); - $types = $this->getTypes(); Utils::invariant(\count($types) > 0, "{$this->name} types must not be empty");