-
-
Notifications
You must be signed in to change notification settings - Fork 266
resolve method can use dependency injection #520
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
Merged
mfn
merged 3 commits into
rebing:master
from
crissi:resolve_method_can_use_dependency_injection
Nov 25, 2019
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
crissi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
declare(strict_types=1); | ||
|
||
namespace Rebing\GraphQL\Tests\Support\Objects; | ||
|
||
class ClassToInject | ||
{ | ||
} |
38 changes: 38 additions & 0 deletions
38
tests/Support/Queries/PostQueryWithNonInjectableTypehintsQuery.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,38 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rebing\GraphQL\Tests\Support\Queries; | ||
|
||
use GraphQL\Type\Definition\Type; | ||
use Rebing\GraphQL\Support\Facades\GraphQL; | ||
use Rebing\GraphQL\Support\Query; | ||
use Rebing\GraphQL\Support\SelectFields; | ||
use Rebing\GraphQL\Tests\Support\Models\Post; | ||
|
||
class PostQueryWithNonInjectableTypehintsQuery extends Query | ||
{ | ||
protected $attributes = [ | ||
'name' => 'postQueryWithNonInjectableTypehints', | ||
]; | ||
|
||
public function type(): Type | ||
{ | ||
return GraphQL::type('Post'); | ||
} | ||
|
||
public function args(): array | ||
{ | ||
return [ | ||
'id' => [ | ||
'type' => Type::nonNull(Type::id()), | ||
], | ||
]; | ||
} | ||
|
||
public function resolve($root, $args, $ctx, SelectFields $fields, int $coolNumber) | ||
{ | ||
return Post::select($fields->getSelect()) | ||
->findOrFail($args['id']); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
tests/Support/Queries/PostQueryWithSelectFieldsClassInjectionQuery.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,43 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rebing\GraphQL\Tests\Support\Queries; | ||
|
||
use Closure; | ||
use GraphQL\Type\Definition\ResolveInfo; | ||
use GraphQL\Type\Definition\Type; | ||
use Rebing\GraphQL\Support\Facades\GraphQL; | ||
use Rebing\GraphQL\Support\Query; | ||
use Rebing\GraphQL\Support\SelectFields; | ||
use Rebing\GraphQL\Tests\Support\Models\Post; | ||
use Rebing\GraphQL\Tests\Support\Objects\ClassToInject; | ||
|
||
class PostQueryWithSelectFieldsClassInjectionQuery extends Query | ||
{ | ||
protected $attributes = [ | ||
'name' => 'postWithSelectFieldClassInjection', | ||
]; | ||
|
||
public function type(): Type | ||
{ | ||
return GraphQL::type('Post'); | ||
} | ||
|
||
public function args(): array | ||
{ | ||
return [ | ||
'id' => [ | ||
'type' => Type::nonNull(Type::id()), | ||
], | ||
]; | ||
} | ||
|
||
public function resolve($root, $args, $ctx, SelectFields $fields, ResolveInfo $info, Closure $selectFields, ClassToInject $class) | ||
{ | ||
$selectClass = $selectFields(5); | ||
|
||
return Post::select($fields->getSelect()) | ||
->findOrFail($args['id']); | ||
} | ||
} |
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.
Why not just calling the app()->call() directly in here?
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.
🤷♀️
You can always try making a PR!
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.
@mfn I just notice this because I had implement this feature for auto injecting anything I pass in by myself, so on this PR I notice my solution wouldn't be needed anymore as I could just use this, however I solved it with just a few lines by calling app()->call() and this implementation is trying to do alot.... Which makes me wonder if I missed something.. Or my suggestion would be enough.. Would it work?
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 can't say, didn't author it /cc @crissi
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.
seems like it would bound to specific variable names instead of now where only the 3 first are required arguments and you can use what ever variable name there after as long as the Class name is correct.