Skip to content
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

fix: allow search filter to use an int for its value #4295

Merged
merged 5 commits into from
May 27, 2021

Conversation

jmontoyaa
Copy link
Contributor

Q A
Branch 2.6
Tickets #1633 #4196 #2190 #2308
License MIT

Same fix as #4290 but with tests and in branch 2.6

1. First test will fail because the relatedDummies.age is an int
bug reported here api-platform#4290

2. Second test will work because the relatedDummies.name is an string.
@@ -136,7 +136,7 @@ protected function getIdFromValue(string $value)
protected function normalizeValues(array $values, string $property): ?array
{
foreach ($values as $key => $value) {
if (!\is_int($key) || !\is_string($value)) {
if (!\is_int($key) || \is_array($value)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What value will not fit the first part of the IF then ? I mean an array will already be validated by the first part of the OR condition isn't it ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First part of the IF it's the $key, second part it's about the $value. If $value is an INT then a notice will appear. I wrote a test about that here:

d33159f

@@ -909,3 +909,65 @@ Feature: GraphQL collection support
Then the response status code should be 200
And the response should be in JSON
And the JSON node "data.fooDummies.collection" should have 1 element

@createSchema
Scenario: Retrieve a collection with a nested collection filtering by age through a GraphQL query
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be better in filters.feature instead?

}
}
"""

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line to remove.


Then the JSON node "data.dummies.totalCount" should be equal to 1
And the JSON node "data.dummies.edges[0].node.relatedDummies.totalCount" should be equal to 1
Then the JSON node "data.dummies.edges[0].node.relatedDummies.edges[0].node.age" should be equal to "31"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Then the JSON node "data.dummies.edges[0].node.relatedDummies.edges[0].node.age" should be equal to "31"
And the JSON node "data.dummies.edges[0].node.relatedDummies.edges[0].node.age" should be equal to "31"

@alanpoulain alanpoulain changed the title Fixes filter when filtering with an int in branch 2.6 fix: allow search filter to use an int for its value May 27, 2021
@alanpoulain
Copy link
Member

Thank you for the Behat tests! I think it would be nice to have unit ones too. I will handle them.

@jmontoyaa
Copy link
Contributor Author

jmontoyaa commented May 27, 2021

Thank you for the Behat tests! I think it would be nice to have unit ones too. I will handle them.

Thanks! I just added a fix with your suggestions.

@jmontoyaa
Copy link
Contributor Author

I just fix for the behat test (subresource.feature) that was failing because the age filter was added.

@alanpoulain alanpoulain merged commit bd11bd0 into api-platform:2.6 May 27, 2021
@alanpoulain
Copy link
Member

Thank you @jmontoyaa.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants