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 name converter in GraphQL #2765

Merged
merged 1 commit into from Sep 21, 2019

Conversation

antograssiot
Copy link
Contributor

Q A
Bug fix? ?
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets
License MIT
Doc PR

That will also make filtering possible with #2751

I could add unit tests if you feel it is needed and the idea/implementation is OK

@alanpoulain
Copy link
Member

Nice! For the unit tests I'm refactoring the schema builder, it will be a lot more easier to add them then. I hope to do the PR this weekend.

Copy link
Member

@soyuka soyuka left a comment

Choose a reason for hiding this comment

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

lgtm

@dunglas
Copy link
Member

dunglas commented May 15, 2019

Can you rebase @antograssiot? It would be nice to have it in the next patch release.

@antograssiot
Copy link
Contributor Author

Yeah I'll finish this but it won't land in the patch release @dunglas, the support of name converters in filters have landed in master (#2751) and that's also the target here.
I just need to add a unit test and I'll push

@antograssiot
Copy link
Contributor Author

rebased and added on top of the recent refactoring.
ping @dunglas @alanpoulain

@antograssiot
Copy link
Contributor Author

This PHPStan error appear often recently on master, I'm really not sure why but it is definitely not related to this PR I think 🤔

@@ -15,6 +15,7 @@
<argument type="service" id="serializer" />
<argument type="service" id="api_platform.metadata.resource.metadata_factory" />
<argument type="service" id="api_platform.security.resource_access_checker" on-invalid="ignore" />
<argument type="service" id="api_platform.name_converter" on-invalid="ignore" />
Copy link
Member

Choose a reason for hiding this comment

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

I think we could add it before and remove the on-invalid. There is no BC policy for GraphQL and we have already done a lot of BC breaks in master anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually there's not always a name_converter in every app, that's why it is nullable @alanpoulain, not really for BC reason bit I might be wrong...

Copy link
Member

Choose a reason for hiding this comment

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

OK. Could you just change its position then (before a parameter for instance)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well optional parameters are always supposed to be the last ones, and parameter are not optional unless I'm wrong @alanpoulain ?

Copy link
Member

Choose a reason for hiding this comment

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

Because you are adding on-invalid="ignore", it will be replaced by null if the service doesn't exist.
IMO we have to use an optional parameter at the last and with a default value only for BC policy: we don't want a decorator to break for instance.

@@ -26,6 +27,7 @@
<argument type="service" id="api_platform.security.resource_access_checker" on-invalid="null" />
<argument type="service" id="request_stack" />
<argument>%api_platform.collection.pagination.enabled%</argument>
<argument type="service" id="api_platform.name_converter" on-invalid="ignore" />
Copy link
Member

Choose a reason for hiding this comment

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

Same for all the services.

@dunglas dunglas added this to the 2.5.0 milestone Jul 2, 2019
@antograssiot antograssiot force-pushed the graphql-name-converter branch 2 times, most recently from 305a65a to 5c5db23 Compare July 3, 2019 21:36
@antograssiot
Copy link
Contributor Author

I guess this one is ready.

I've added support for nested filtering even when using name converters like done in #2897

To do so I had to create a new configuration value because the way we support nested properties (using the underscore (_) syntax instead of the dot (.) syntax ) is problematic when the property name contains underscore(s). To avoid breaking BC and to allow users that need this feature, I've introduced the possibility to choose the separator that should be used using a new configuration option.

I don't think that it is worth deprecating using the actual value (_) which i the default configuration value as I think that users using such name converters and graphql are not a lot (at least for now), that's really an edge case I guess. Of course if you agree, I'll open a doc PR to explain all of this.
ping @api-platform/core-team

@dunglas
Copy link
Member

dunglas commented Jul 4, 2019

I suggest to I lu support the dot. Underscore is weird, and was not intended imho. Let’s not complexify the code, BC breaks are allowed for GraphQL.

@antograssiot
Copy link
Contributor Author

I suggest to support the dot.

@dunglas, as far as I remember the dot is not allowed in GraphQl queries, that's why underscores where used in the first place, this PR didn't changed that. ping @alanpoulain
If it is now allowed, then it will be easy to support it, we just need to drop the usage of parse_str() in the FieldsBuilder

@alanpoulain
Copy link
Member

@antograssiot antograssiot force-pushed the graphql-name-converter branch 2 times, most recently from c9a84d7 to 4fa26ba Compare July 4, 2019 12:52
@alanpoulain alanpoulain changed the base branch from master to 2.5 September 21, 2019 12:16
@alanpoulain alanpoulain merged commit b0939ad into api-platform:2.5 Sep 21, 2019
@alanpoulain
Copy link
Member

Thanks a lot @antograssiot! It would be great if you could do the doc PR too 🙂

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

Successfully merging this pull request may close these issues.

None yet

5 participants