Skip to content

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

Conversation

snaksa
Copy link

@snaksa snaksa commented Jan 20, 2020

Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Documented? yes
Fixed tickets #526
License MIT

Added targetType property to the Mutation type so that different schemas can be created and mutations can be attached to them.

@snaksa snaksa requested a review from Vincz January 20, 2020 21:00
@snaksa snaksa force-pushed the add-mutation-target-type-property branch from 8e2b613 to beff4de Compare January 20, 2020 21:14
@snaksa snaksa force-pushed the add-mutation-target-type-property branch from beff4de to 3a7f24c Compare January 20, 2020 21:32
Copy link
Collaborator

@Vincz Vincz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a good start !

@@ -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;
Copy link
Collaborator

Choose a reason for hiding this comment

The 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.

@@ -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';
Copy link
Collaborator

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.

Copy link
Author

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?

Copy link
Collaborator

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:

query {
    getDroid(id: 'HKB-3') { // Return a Droid
        getVictims {
            name
        }
    }
}

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 :)

@Vincz
Copy link
Collaborator

Vincz commented Jun 27, 2020

Ping @snaksa !
Hey man, any update about this ? :-)

@Vincz
Copy link
Collaborator

Vincz commented Jul 12, 2020

Closing in favor of #710

@Vincz Vincz closed this Jul 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants