-
-
Notifications
You must be signed in to change notification settings - Fork 906
GraphQL: add support for filters #1633
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
Conversation
features/graphql/filters.feature
Outdated
|
||
@createSchema | ||
@dropSchema | ||
Scenario: Retrieve a collection filtered using the date filter |
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.
The Scenario does not correspond to what is done.
Nice! |
$filterType = \in_array($value['type'], Type::$builtinTypes, true) ? new Type($value['type'], $nullable) : new Type('object', $nullable, $value['type']); | ||
$graphqlFilterType = $this->convertType($filterType); | ||
|
||
if ('[]' === $newKey = substr($key, -2)) { |
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.
Shouldn't it be in a dedicated method (in FilterInterface?)? Or maybe a boolean returned by getDescription
(like $value['is_property_list']
?
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.
Indeed, but has it was done this way for historical reason (and we definitely need this code for existing custom filters), I propose to add the new key in a new PR.
1c37cd2
to
1a362f2
Compare
cd728b9
to
049e7b6
Compare
*/ | ||
abstract protected function filterProperty(string $property, $value, QueryBuilder $queryBuilder, QueryNameGeneratorInterface $queryNameGenerator, string $resourceClass, string $operationName = null); | ||
abstract protected function filterProperty(string $property, $value, QueryBuilder $queryBuilder, QueryNameGeneratorInterface $queryNameGenerator, string $resourceClass, string $operationName = null/*, array $context = []*/); |
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.
@dunglas The commented out $context
in apply
and filterProperty
is a bit confusing. I see that AbstractContextAwareFilter
extends from this class and overrides apply
introducing array $context = []
, and then calls $this->filterProperty(..., $context);
.
How about filterProperty, should it also be overridden in AbstractContextAwareFilter
with adding array $context = []
?
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.
oh good catch I think it should indeed
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.
As @meyerbaptiste reminds us, we need PHP 7.2 for this: https://3v4l.org/ktgkR
Fixes test that fails in 2.6: d33159f Related/Reported in api-platform#1633 api-platform#4196 api-platform#2190 api-platform#2308 api-platform#4290
This is the last missing part for full GraphQL support (and to release the first beta of 2.2): filters support.
This PR allows to use any API Platform filter (builtin or not) both with REST and GraphQL. It comes with a refactoring of the filter subsystem to be decoupled from the HTTP layer. This also means that it's now now easy to add support for other transport layers (e.g. RabbitMQ), and different HTTP abstractions than Symfony's HttpFoundation (e.g. PSR-7).
Example:
Then you can run this GraphQL query:
It also works for any level of nested collections.
TODO: