-
-
Notifications
You must be signed in to change notification settings - Fork 266
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
[LUMEN] Fix multiple schemas on query/mutation #599
Conversation
$schema arg received in query function is always null and if we have only one element in $routeParameters, $schema remain empty, then the query always hit default schema.
it appears to fail at dependency installation with composer, in this travis Job :
But the fact is, I didn't change anything in composer.json or composer-lock file ... is it something that happens frequently ? |
Hmm, not frequently but it can… |
The culprit was that the integration tests use |
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 don't think the fix is correct, see my feedback…
@@ -29,7 +29,7 @@ public function query(Request $request, string $schema = null): JsonResponse | |||
// If there are multiple route params we can expect that there | |||
// will be a schema name that has to be built | |||
$routeParameters = $this->getRouteParameters($request); | |||
if (count($routeParameters) > 1) { | |||
if (count($routeParameters) > 0) { |
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 don't think the fix is correct here and should rather be within \Rebing\GraphQL\GraphQLController::getRouteParameters
, can you investigate?
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 don't think the fix is correct here and should rather be within
\Rebing\GraphQL\GraphQLController::getRouteParameters
, can you investigate?
Thanks mfn for having a look at my PR :) I don't see what can be fixed in the getRouteParameters as it already handle the Lumen case, and return the only one element in the route param available ..
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.
Yes, so my impression is "if it's broken with Lumen, it need to be fixed in the Lumen code path".
This change here affects all environments == also Laravel, so I'm not confident this is correct (as no one reported problems with Laravel).
Could I explain my position / concerns?
thanks
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.
Ok I get your point.
The situation here is kind of tricky because with Lumen and only one element in the route URL, the schema is never assigned, and the default schema will always be picked.
Could I write something like this instead :
$routeParameters = $this->getRouteParameters($request);
if (count($routeParameters) > Helpers::isLumen() ? 0 : 1) {
$schema = implode('/', $routeParameters);
}
This fix wouldn't be necessary if we could pass a schema name directly into function arg :
public function query(Request $request, string $schema = null): JsonResponse {}
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.
if (count($routeParameters) > Helpers::isLumen() ? 0 : 1) {
But you can to the same fix within getRouteParameters
in a lumen specific code path, no?
This fix wouldn't be necessary if we could pass a schema name directly into function arg :
That would probably require adapting the routes.php
=> I'm open to that, but would see some concrete code.
Also we would definitely need a test for this.
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.
Sorry I'm on two parallel tasks, and I'm fairly new to PHP so I may be annoying. But my feeling here is that the count($routeParameters) > 1
is not right, why would we want to take default schema, if there is one path element anyway ? it still seems valid.
EDIT : I took the time to test a Laravel boilerplate project with graphQL, and saw that we receive the exact same thing from the getRouteParameters method. for instance, if I access a ping query on "test" schema, I will in both case (Laravel and Lumen) receive an array of one element : array("test').
So I decided to fix the root problem and send schema name in query. After a bit of code exploring I didnt found yet the place it's specified 😫
I'll focus on this today, and I'll update the PR to reflect that and update tests
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.
Ok I took some time again to look at the code, and I finally found something amazing 😲
Into graphql.php config file, if you replace the academic {graphql_schema?}
with {schema}
in Lumen, it works so hard that I can't even think about how many hours I lost trying to wrap my head around it. I spotted the good place to log into RoutesRequests.php file from Lumen Framework, and I saw that the pattern given as a config key 'routes' in graphql.php was used to insert a into the parameters the schema with this form (e.g private schema ) :
["private": "private"]
Now if we change the config key to {schema}
it will then automatically add into parameters :
["schema": "private"]
Hence, the GraphQLController gets hit with correct schema value.
🗡 🗡 I could easily do Sepukku, if we were 600 years back in the past
Jokes aside, I will close this non-sense PR as it works with Lumen, BUT I will open another PR to update documentation about that.
Summary
$schema
arg received in query function is alwaysnull
and if we have only one element in$routeParameters
,$schema
remain empty, then the query always hit default schema.Type of change
switching condition to fill
$schema
, fromif (count($routeParameters) > 1)
toif (count($routeParameters) > 0)
Checklist
composer fix-style
Links