-
-
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
Execution middleware #762
Execution middleware #762
Conversation
@mfn can you take a look when you have some time! |
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 like 👍
Not sure were we end up with this, but I see this as a promising start! Also: so little code 😱
I think we should try hard with the actual data we pass and I fully accept further breaking changes for the upcoming 8 release cycle; it's the best time now.
Feel free to react to the feedback already, but I definitely need more time to play around with this. Now that we've something working, it's really best probably to try / see implement:
- APC
- detect_unused_variables
- …
to better understand what is / what is not possible and what's missing etc.
Thanks for the initiative 🙏
src/GraphQL.php
Outdated
if (1 === count($middlewareResponse)) { | ||
return $middlewareResponse; | ||
} |
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.
What is this doing exactly? Is it for the case of already returning a response?
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.
this catches, if you returning directly in the middleware.
After thinking about it this might not be enough to know for sure that it was a response that has been returned, will investigate further
src/GraphQL.php
Outdated
@@ -118,6 +119,17 @@ public function schema($schema = null): Schema | |||
*/ | |||
public function query($query, ?array $variables = [], array $opts = []): array | |||
{ | |||
$middlewareResponse = app()->make(Pipeline::class) | |||
->send([$query, $variables]) |
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 we should add $opts
here too.
Or, well at least the most important bit would be the schemaName
.
TBH I despise the whole signature of this query
method, it just does not make any sense to me.
I think the one from \Rebing\GraphQL\GraphQLController::executeQuery makes much more sense:
executeQuery(string $schemaName, OperationParams $params):
with the addition of being able to carry over the parsed query (either freshly parsed or retrieved e.g. from APQ).
src/GraphQL.php
Outdated
*/ | ||
public function executionMiddleware(): array | ||
{ | ||
return config('graphql.execution_middleware', []); |
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 it's important we consider the schema name / per schema execution middleware too (*), something like:
return
config("graphql.$schemaName.execution_middleware") ??
config('graphql.execution_middleware') ??
[];
(*) which isn't in this context yet, I know
Just thinking out loud, no need to do anything right now: No matter how we name this middleware, we probably should rename
for both "kinds" of middlewares? Maybe moving both to |
I will try to move them to the middleware |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
The $opts[schema] supports ad-hoc schemas, i.e. not just a name referencing the config, thus the boilerplate. I'm wonder if this is truly needed and playing with the idea to actually remove support for this.
I don't see it useful being publicly available, it's more of an internal helper which can be overriden if necessary.
I tried to move the apc part but got into problems with the queryContext missing a query string, to fix this the query context needs to be added to the Graphql class instead of the controller. But maybe we can let the apc be at is!? |
All good man, the feature is the most important thing for me😊 Like it alot that everything is a brick that you can choose to add or remove. |
Some of the previous breaking changes for the next major release have become obsolete due to the further refactoring.
CHANGELOG.md
Outdated
@@ -94,6 +94,7 @@ CHANGELOG | |||
new: `public function queryAndReturnResult($query, ?array $variables = [], array $opts = []): ExecutionResult` | |||
|
|||
### Added | |||
- The primary execution of the GraphQL requested is now modeled via middlewares [\#762 / crissi and mfn](https://github.com/rebing/graphql-laravel/pull/762) |
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.
@crissi I don't want it to go unmentioned I also mentioned me as secondary author, is this fine with you?
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.
all good 🙂
I've recently changed the behaviour that invalid schemas are not silently ignored anymore when building the routes => #766
That would be my first idea… |
IMHO this is more readable and also gives clearer diffs in case of mismatches
The surrounding code has changed enough to not require this anymore.
I ran it on a private project with ~5k GraphQL tests, multiple schemas and custom context with no issues (except adapting the config to inject the context via middleware now) |
thanks , error 40:) |
do we need a getter and setter on OperationParams for the variables? now there is only the public variables |
I wanted to stick to and follow I'm not really happy how
Do you mean it works for you? |
Yes works fine😊 |
Ok, I think I'll go ahead and merge this then later today. I still want to work on a better handling of the three middlewares now supported (http laravel, execution, resolve) but I'll do this in a follow-up PRs |
Summary
Execution hook/middleware based on #753
TODO
Type of change:
Checklist:
composer fix-style