-
Notifications
You must be signed in to change notification settings - Fork 222
Add targetType property to Mutation #639
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
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -289,8 +289,22 @@ private static function typeAnnotationToGQLConfiguration( | |
$isRootMutation = ($rootMutationType && $gqlName === $rootMutationType); | ||
$currentValue = ($isRootQuery || $isRootMutation) ? \sprintf("service('%s')", self::formatNamespaceForExpression($reflectionEntity->getName())) : 'value'; | ||
|
||
$queryType = $isRootMutation ? 'Mutation' : 'Query'; | ||
|
||
if (isset($configs['definitions']['schema'])) { | ||
$mutationTypes = []; | ||
|
||
foreach ($configs['definitions']['schema'] as $key => $value) { | ||
if (isset($configs['definitions']['schema'][$key]['mutation'])) { | ||
$mutationTypes[] = $configs['definitions']['schema'][$key]['mutation']; | ||
} | ||
} | ||
|
||
$queryType = \in_array($gqlName, $mutationTypes) ? 'Mutation' : 'Query'; | ||
} | ||
|
||
$gqlConfiguration = self::graphQLTypeConfigFromAnnotation($classAnnotation, $classAnnotations, $properties, $methods, $reflectionEntity->getNamespaceName(), $currentValue); | ||
$providerFields = self::getGraphQLFieldsFromProviders($reflectionEntity->getNamespaceName(), $isRootMutation ? 'Mutation' : 'Query', $gqlName, ($isRootQuery || $isRootMutation)); | ||
$providerFields = self::getGraphQLFieldsFromProviders($reflectionEntity->getNamespaceName(), $queryType, $gqlName, ($isRootQuery || $isRootMutation)); | ||
$gqlConfiguration['config']['fields'] = $providerFields + $gqlConfiguration['config']['fields']; | ||
|
||
if ($classAnnotation instanceof GQL\Relay\Edge) { | ||
|
@@ -673,7 +687,7 @@ private static function getGraphQLFieldsFromProviders(string $namespace, string | |
continue; | ||
} | ||
|
||
$annotationTarget = 'Query' === $annotationName ? $annotation->targetType : null; | ||
$annotationTarget = \in_array($annotationName, ['Query', 'Mutation']) ? $annotation->targetType : null; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With providers, $annotationName will always be either Query or Mutation, so this line is useless. |
||
if (!$annotationTarget && $isRoot) { | ||
$annotationTarget = $targetType; | ||
} | ||
|
This file contains hidden or 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 hidden or 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
14 changes: 14 additions & 0 deletions
14
tests/Config/Parser/fixtures/annotations/Type/AlternativeMutation.php
This file contains hidden or 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,14 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Overblog\GraphQLBundle\Tests\Config\Parser\fixtures\annotations\Type; | ||
|
||
use Overblog\GraphQLBundle\Annotation as GQL; | ||
|
||
/** | ||
* @GQL\Type | ||
*/ | ||
class AlternativeMutation | ||
{ | ||
} |
14 changes: 14 additions & 0 deletions
14
tests/Config/Parser/fixtures/annotations/Type/AlternativeQuery.php
This file contains hidden or 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,14 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Overblog\GraphQLBundle\Tests\Config\Parser\fixtures\annotations\Type; | ||
|
||
use Overblog\GraphQLBundle\Annotation as GQL; | ||
|
||
/** | ||
* @GQL\Type | ||
*/ | ||
class AlternativeQuery | ||
{ | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this part is incomplete and confusing. The Query and Mutation types are considered "root" regardless of the schema, so they should behave the same way (the $currentValue for example).
Also, if we can target whatever type with the @query, the @mutation should only target "root" Mutations.
I think we should check this and raise an exception if something other than a Mutation is targeted by a
@Mutation
.Then we should change the isRootQuery & isRootMutation to check in all schema.
And the last part are the default Query / Mutation.
Now, we must decide what we want to target if there is no targetType provided. We used to target the root query and mutation of the
default
schema. Now, we can have multiple schemas and we are not sure that we have one with the name "default". So, my suggestion would be to target the one with name "default" if it exists, and if not the first one of the list of schemas.And the last parameter of
getGraphQLFieldsFromProviders
should be rename$isDefault
as it is used to know if the current type is the default one (the one targeted when no targetType is defined).The tests should also be updated accordingly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your feedback! I will try to implement the changes you mentioned tomorrow. I am new to using this bundle and I have some troubles understanding what do you mean by: the @mutation should only target "root" Mutations. Do you mean that there might be targetType set to something other than mutation type? And how can a @query target whatever type we choose? This confuses me a little and I guess everything will clear in my head once I understand this concept. Can you guide me to a piece of documentation that explains this and I might have missed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea of the @Provider is to be able to add query or mutation from various services.
In the case of Query, we can target the "root" Query (ie. The Query define at the key "query" in the schema configuration)...or...any other type (for example, I could target the type "Droid" like in the test fixtures) and the effect will be that I'll have a new queryable field on type Droid.
Let's say I want to provide a "getVictims" query on the Droid type, it would be queried like that for example:
In the case of Mutation, the GraphQL specs says that mutations must be defined on the Mutation object (ie. The "root" mutation define at the key "mutation" in the schema config). So I couldn't target the Droid with my mutation. So the targetType should always be a root Mutation as Mutation are always "root".
Hope it'll help :)