fix(graphql): build filter args from parameters#8347
Merged
Conversation
FieldsBuilder generated GraphQL field arguments from two divergent
paths: legacy Operation::getFilters() (#[ApiFilter]) and canonical
Operation::getParameters() (#[QueryParameter]). The parameter path
flattened dotted keys (colors.prop) into root arguments and never
exposed ComparisonFilter operator forms, so migrating filters to
QueryParameter silently dropped nested-collection and operator
arguments over GraphQL.
Unify both into a single arg-tree pipeline so QueryParameter reaches
parity with the legacy path:
- nested collection args (colors(prop:)) from the related resource's
own parameters via the existing depth recursion
- operator forms (gt/gte/lt/lte/ne) from JsonSchemaFilterInterface
- scalar leaf types from the parameter native type (int yields Int)
Sort filters implement the backend-agnostic Metadata
SortFilterInterface so the builder can list-shape sequence-sensitive
order arguments (order: [{...}]) without depending on a persistence
layer; GraphQL input-object fields are unordered and cannot preserve
multi-key ordering.
7bc45fc to
43b55ca
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What
Unifies GraphQL field-argument generation in
FieldsBuilderso filters declared via#[QueryParameter]reach full parity with the legacy#[ApiFilter]path.Problem
FieldsBuilderbuilt GraphQL arguments from two divergent code paths:Operation::getFilters()(#[ApiFilter]) — supported nested-collection args (colors(prop:)) and operator forms;Operation::getParameters()(#[QueryParameter]) — flattened dotted keys (colors.prop) into root args and never exposedComparisonFilteroperator forms.So migrating fixtures from
#[ApiFilter]toQueryParameter(the 4.4/bc-filter work) silently dropped nested-collection and operator arguments over GraphQL. The legacyFilterTestsuite only stayed green becauseDummyCarstill uses#[ApiFilter].Change
One intermediate arg-tree (
#name/#list/#nonNullmarkers) feeds one converter, replacinggetFilterArgs/getParameterArgs/parameterToObjectType/getParameterType/mergeFilterArgs/convertFilterArgsToTypes. Both filter and parameter sources feed the same tree.QueryParameter parity:
colors(prop:)) from the related resource's own parameters via the existing depth recursion (also fixes a latent bug where parameter args were sourced from the root operation instead of the resource operation);gt/gte/lt/lte/ne) derived fromJsonSchemaFilterInterface::getSchema()instead of the empty deprecatedgetDescription();intproperty yields GraphQLInt).Sort filters are list-shaped (
order: [{...}]) because GraphQL input-object fields are unordered and cannot preserve multi-key ordering, whereas every other bracketed filter (search/comparison/date/exists) stays a single input object. This is recognized through a new backend-agnosticApiPlatform\Metadata\SortFilterInterface, implemented by the Doctrine ORM/ODMSortFilterand the LaravelOrderFilter— soFieldsBuilderdepends only on Metadata, not on any persistence layer.Runtime is unchanged —
ReadProvider/ParameterProvider/FilterExtension/ParameterExtensionalready apply both paths.Tests
New
ParameterFilterParityTest+GraphQlFilteredResource(Color)fixtures (ORM + ODM) declare DummyCar-equivalent filters viaQueryParameterand assert nested search,ComparisonFilteroperators (gt: 10→Int), root exact andorderlist shape — failing before, green after. LegacyDummyCar/FilterTestleft untouched as the BC anchor.Green (ORM): GraphQl
FilterTest13/13,ParameterFilterParityTest4/4,Issue7966Test, fulltests/Functional/GraphQl159/159,tests/Functional/Parameters406/406 (16 ODM skips). ODM mirror not run locally (no doctrine/mongodb-odm-bundle).