-
-
Notifications
You must be signed in to change notification settings - Fork 960
[GraphQL] Add custom queries #2445
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
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
ac27389
Add configuration for custom GraphQL queries on ApiResource
lukasluecke f0ca31e
Merge branch 'master' into custom-graphql
lukasluecke 6e96476
Merge branch 'master' into custom-graphql
lukasluecke a1a51eb
Add query suffix to graphql resolver key
lukasluecke 86e3a8f
Fix code-style
lukasluecke db8a3c1
Fix tests
lukasluecke 32cb7dc
Resolve review comments
lukasluecke 79b27d7
Merge branch 'master' into custom-graphql
lukasluecke bec21ca
Fix cs and tests
lukasluecke 2e99f2f
Add behat test for custom query
lukasluecke 3e422f2
Merge branch 'master' into custom-graphql
lukasluecke 09de26e
Fixes
alanpoulain 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
43 changes: 43 additions & 0 deletions
43
src/Bridge/Symfony/Bundle/DependencyInjection/Compiler/GraphQlQueryResolverPass.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 | ||
|
|
||
| /* | ||
| * This file is part of the API Platform project. | ||
| * | ||
| * (c) Kévin Dunglas <dunglas@gmail.com> | ||
| * | ||
| * For the full copyright and license information, please view the LICENSE | ||
| * file that was distributed with this source code. | ||
| */ | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace ApiPlatform\Core\Bridge\Symfony\Bundle\DependencyInjection\Compiler; | ||
|
|
||
| use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; | ||
| use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
| use Symfony\Component\DependencyInjection\Reference; | ||
|
|
||
| /** | ||
| * Injects GraphQL resolvers. | ||
| * | ||
| * @internal | ||
| * | ||
| * @author Lukas Lücke <lukas@luecke.me> | ||
| */ | ||
| final class GraphQlQueryResolverPass implements CompilerPassInterface | ||
| { | ||
| /** | ||
| * {@inheritdoc} | ||
| */ | ||
| public function process(ContainerBuilder $container) | ||
| { | ||
| $resolvers = []; | ||
| foreach ($container->findTaggedServiceIds('api_platform.graphql.query_resolver', true) as $serviceId => $tags) { | ||
| foreach ($tags as $tag) { | ||
| $resolvers[$tag['id'] ?? $serviceId] = new Reference($serviceId); | ||
| } | ||
| } | ||
|
|
||
| $container->getDefinition('api_platform.graphql.query_resolver_locator')->addArgument($resolvers); | ||
| } | ||
| } |
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,32 @@ | ||
| <?php | ||
|
|
||
| /* | ||
| * This file is part of the API Platform project. | ||
| * | ||
| * (c) Kévin Dunglas <dunglas@gmail.com> | ||
| * | ||
| * For the full copyright and license information, please view the LICENSE | ||
| * file that was distributed with this source code. | ||
| */ | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace ApiPlatform\Core\GraphQl\Resolver; | ||
|
|
||
| use GraphQL\Type\Definition\ResolveInfo; | ||
|
|
||
| /** | ||
| * A function retrieving an item to resolve a GraphQL query. | ||
| * Should return the normalized item or collection. | ||
| * | ||
| * @experimental | ||
| * | ||
| * @author Lukas Lücke <lukas@luecke.me> | ||
| */ | ||
| interface QueryResolverInterface | ||
| { | ||
| /** | ||
| * @return mixed|null The normalized query result (item or collection) | ||
| */ | ||
| public function __invoke($source, $args, $context, ResolveInfo $info); | ||
| } | ||
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,38 @@ | ||
| <?php | ||
|
|
||
| /* | ||
| * This file is part of the API Platform project. | ||
| * | ||
| * (c) Kévin Dunglas <dunglas@gmail.com> | ||
| * | ||
| * For the full copyright and license information, please view the LICENSE | ||
| * file that was distributed with this source code. | ||
| */ | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace ApiPlatform\Core\Tests\Fixtures\TestBundle\Document; | ||
|
|
||
| use ApiPlatform\Core\Annotation\ApiResource; | ||
|
|
||
| /** | ||
| * Dummy with custom GraphQL query resolvers. | ||
| * | ||
| * @author Lukas Lücke <lukas@luecke.me> | ||
| * | ||
| * @ApiResource(graphql={ | ||
| * "testItem"={ | ||
| * "item_query"="app.graphql.query_resolver.dummy_custom_item" | ||
| * }, | ||
| * "testCollection"={ | ||
| * "collection_query"="app.graphql.query_resolver.dummy_custom_collection" | ||
| * } | ||
| * }) | ||
| */ | ||
| class DummyCustomQuery | ||
| { | ||
| /** | ||
| * @var string | ||
| */ | ||
| public $message; | ||
| } |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.