Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GraphQL] Fix introspection (graphql-php / GraphiQL) #1886

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
10 changes: 10 additions & 0 deletions features/bootstrap/GraphqlContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Behat\Gherkin\Node\PyStringNode;
use Behatch\Context\RestContext;
use Behatch\HttpCall\Request;
use GraphQL\Type\Introspection;

/**
* Context for GraphQL.
Expand Down Expand Up @@ -95,6 +96,15 @@ public function ISendTheGraphqlRequestWithOperation(string $operation)
$this->sendGraphqlRequest();
}

/**
* @When I send the query to introspect the schema
*/
public function ISendTheQueryToIntrospectTheSchema()
{
$this->graphqlRequest = ['query' => Introspection::getIntrospectionQuery()];
$this->sendGraphqlRequest();
}

private function sendGraphqlRequest()
{
$this->request->setHttpHeader('Accept', null);
Expand Down
13 changes: 3 additions & 10 deletions features/graphql/introspection.feature
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,13 @@ Feature: GraphQL introspection support
And the JSON node "errors[0].message" should be equal to "GraphQL query is not valid"

Scenario: Introspect the GraphQL schema
When I send the following GraphQL request:
"""
{
__schema {
types {
name
}
}
}
"""
When I send the query to introspect the schema
Then the response status code should be 200
And the response should be in JSON
And the header "Content-Type" should be equal to "application/json"
And the JSON node "data.__schema.types" should exist
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"

Scenario: Introspect types
When I send the following GraphQL request:
Expand Down
38 changes: 0 additions & 38 deletions features/graphql/mutation.feature
Original file line number Diff line number Diff line change
Expand Up @@ -106,44 +106,6 @@ Feature: GraphQL mutation support
And the JSON node "data.createDummy.arrayData[1]" should be equal to baz
And the JSON node "data.createDummy.clientMutationId" should be equal to "myId"

Scenario: Create an item with an embedded field
When I send the following GraphQL request:
"""
mutation {
createRelatedDummy(input: {_id: 2, symfony: "symfony", embeddedDummy: {dummyName: "Embedded"}, clientMutationId: "myId"}) {
id
clientMutationId
}
}
"""
Then the response status code should be 200
And the response should be in JSON
And the header "Content-Type" should be equal to "application/json"
And the JSON node "data.createRelatedDummy.id" should be equal to "/related_dummies/2"
And the JSON node "data.createRelatedDummy.clientMutationId" should be equal to "myId"

Scenario: Create an item and update a nested resource through a mutation
When I send the following GraphQL request:
"""
mutation {
createRelationEmbedder(input: {paris: "paris", krondstadt: "Krondstadt", anotherRelated: {id: 2, symfony: "laravel"}, clientMutationId: "myId"}) {
id
anotherRelated {
id
symfony
}
clientMutationId
}
}
"""
Then the response status code should be 200
And the response should be in JSON
And the header "Content-Type" should be equal to "application/json"
And the JSON node "data.createRelationEmbedder.id" should be equal to "/relation_embedders/1"
And the JSON node "data.createRelationEmbedder.anotherRelated.id" should be equal to "/related_dummies/2"
And the JSON node "data.createRelationEmbedder.anotherRelated.symfony" should be equal to "laravel"
And the JSON node "data.createRelationEmbedder.clientMutationId" should be equal to "myId"

Scenario: Delete an item through a mutation
When I send the following GraphQL request:
"""
Expand Down
187 changes: 0 additions & 187 deletions src/GraphQl/Type/Definition/InputUnionType.php

This file was deleted.

31 changes: 5 additions & 26 deletions src/GraphQl/Type/SchemaBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use ApiPlatform\Core\Exception\ResourceClassNotFoundException;
use ApiPlatform\Core\GraphQl\Resolver\Factory\ResolverFactoryInterface;
use ApiPlatform\Core\GraphQl\Serializer\ItemNormalizer;
use ApiPlatform\Core\GraphQl\Type\Definition\InputUnionType;
use ApiPlatform\Core\GraphQl\Type\Definition\IterableType;
use ApiPlatform\Core\Metadata\Property\Factory\PropertyMetadataFactoryInterface;
use ApiPlatform\Core\Metadata\Property\Factory\PropertyNameCollectionFactoryInterface;
Expand Down Expand Up @@ -343,24 +342,13 @@ private function convertType(Type $type, bool $input = false, string $mutationNa
break;
case Type::BUILTIN_TYPE_ARRAY:
case Type::BUILTIN_TYPE_ITERABLE:
$graphqlType = $this->getIterableType();
if (!isset($this->graphqlTypes['#iterable'])) {
$this->graphqlTypes['#iterable'] = new IterableType();
}
$graphqlType = $this->graphqlTypes['#iterable'];
break;
case Type::BUILTIN_TYPE_OBJECT:
if ($input && $depth > 0) {
if (!isset($this->graphqlTypes['#stringIterableUnionInput'])) {
$this->graphqlTypes['#stringIterableUnionInput'] = new InputUnionType([
'name' => 'StringIterableUnionInput',
'description' => 'Resource\'s IRI or data (embedded entities or when updating a related existing resource)',
'types' => [
GraphQLType::string(),
$this->getIterableType(),
],
]);
}
$graphqlType = $this->graphqlTypes['#stringIterableUnionInput'];
break;
}
if (is_a($type->getClassName(), \DateTimeInterface::class, true)) {
if (($input && $depth > 0) || is_a($type->getClassName(), \DateTimeInterface::class, true)) {
$graphqlType = GraphQLType::string();
break;
}
Expand Down Expand Up @@ -511,15 +499,6 @@ private function getResourcePaginatedCollectionType(string $resourceClass, Graph
return $this->graphqlTypes[$resourceClass]['connection'] = new ObjectType($configuration);
}

private function getIterableType(): IterableType
{
if (!isset($this->graphqlTypes['#iterable'])) {
$this->graphqlTypes['#iterable'] = new IterableType();
}

return $this->graphqlTypes['#iterable'];
}

private function isCollection(Type $type): bool
{
return $type->isCollection() && Type::BUILTIN_TYPE_OBJECT === $type->getBuiltinType();
Expand Down
Loading