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

Add support for comma-separated filter values #236

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

CostantiniMatteo
Copy link
Contributor

Implements #235

jherdman
jherdman previously approved these changes Sep 4, 2020
@jherdman
Copy link
Contributor

jherdman commented Sep 4, 2020

LGTM. I need to wrap my head around how to release this. I think it's a breaking change despite being what is pretty obviously a bug in the initial implementation. I'd be curious to hear what other maintainers think.

cc @jeregrine @doomspork

@CostantiniMatteo
Copy link
Contributor Author

I've re-read the documentation and I've made a mistake. The part I quoted in the issue is from the recommendations page so it's not supposed to be the default jsonapi behaviour.

Maybe this could be a configurable behaviour?

@jherdman
Copy link
Contributor

jherdman commented Sep 7, 2020

I'm pretty certain this is the kind of behaviour users of this library would expect. My inclination is to merge this as a bug fix and call it out in the changelog.

@CostantiniMatteo
Copy link
Contributor Author

I do agree with you, I would expect this behaviour, however this is not jsonapi standard.

I was discussing this with @lucacorti, which pointed out that this is only a recommendation's example, and one may want to support a different a strategy for filtering, or may want to use a comma in the filter value.

Isn't it better to at least offer a way to prevent this behaviour via configuration?

@jherdman
Copy link
Contributor

jherdman commented Sep 11, 2020 via email

@CostantiniMatteo
Copy link
Contributor Author

CostantiniMatteo commented Oct 12, 2020

Hey @jherdman, sorry I was off the grid.

I've updated the PR to make the parsing configurable.

I don't particularly like the config name, and how I handled the tests (without sacrificing concurrency).
Since they run asynchronously, tests at line 70 and 77 may change the same configuration and one of the two may fail.
The problem may still arise with the current implementation, although much less likely.

Let me know what you think!

@@ -67,12 +67,20 @@ defmodule JSONAPI.QueryParserTest do
assert filter[:name] == "jason"
end

test "parse_filter/2 handles multiple comma-separated filter values" do
test "parse_filter/2 handles multiple comma-separated filter values if configured" do
Application.put_env(:jsonapi, :filter_values_separator, ";")
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be cleaned up in an on_exit hook?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Absolutely! I've restored a previous commit where the whole env is backed up before tests and restored on exit.
This way we are sure we won't forget to clean up other variables.

@jherdman
Copy link
Contributor

Hey @jherdman, sorry I was off the grid.

Never sweat about this. F/OSS is done on a volunteer basis for the vast majority of people. Any and all contributions are much appreciated!

@CostantiniMatteo
Copy link
Contributor Author

Could we take the chance to also merge this one among #245 and make a new release? We ended up not using this feature so I forgot about it, but it would still be useful. What do you think?

@lucacorti
Copy link
Contributor

@CostantiniMatteo I think merging this would be a mistake as this is really constraining what the spec allows in term of filtering: https://jsonapi.org/format/#fetching-filtering

The spec specifies that the filter parameter is used for filtering and its content are entirely up to implementation specific strategy. Processing the filter query param with some predefined logic is really limiting in terms of what can be implemented. Maybe we could explore some delegation to a behaviour like what I implemented earlier for pagination, or leave it entirely to the library user to parse its content?

@CostantiniMatteo
Copy link
Contributor Author

The processing is optional and needs to be configured so it's not limiting and does not break the existing behaviour.

Maybe it can be refactored to accept a module used to parse the filter content, and include a parser with support for comma-separated values, instead of the current hard-coded solution.

@lucacorti
Copy link
Contributor

You can't implement all possible user needs on this, so extensible is arguably better than any built in logic.

@doomspork
Copy link
Member

@jeregrine / @jherdman / @lucacorti / @CostantiniMatteo where do we stand with this PR? It looks like it was approved but there's been some discussion about whether this is the change we want.

@lucacorti
Copy link
Contributor

@doomspork @CostantiniMatteo as I said I think this would be better addressed with an extensible approach instead of configurable baked in logic.

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

4 participants