Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Bugfix: Respect input DTO without adding additional id field#5095

Merged
alanpoulain merged 2 commits into
api-platform:mainfrom
jotwea:bugfix/respect-input-no-id
Jan 23, 2023
Merged

Bugfix: Respect input DTO without adding additional id field#5095
alanpoulain merged 2 commits into
api-platform:mainfrom
jotwea:bugfix/respect-input-no-id

Conversation

@jotwea
Copy link
Copy Markdown
Contributor

@jotwea jotwea commented Oct 26, 2022

Q A
Branch? main
Tickets #5097 #2736
License MIT
Doc PR -

For all GraphQL mutations except create the id field is added automatically. Also for scenarios where an input DTO is used the id got added. This PR respects the given input DTO and will not add an additional id field. If you need the id your DTO may contain it.

The related Ticker #2736 is not completely solved with this PR but it enables the workaround to have multipe create mutations by using a specifiy input DTO.

Branch:

  • main, because not sure if it is a real bugfix or more a tiny new feature.

Note: Failing PHP-cs-fixer is not related to the changes in this PR

@alanpoulain
Copy link
Copy Markdown
Member

It's totally main, since it can even be considered as a breaking change.

Why not using an allow list like suggested in the issue?

@jotwea
Copy link
Copy Markdown
Contributor Author

jotwea commented Oct 26, 2022

Thanks @alanpoulain for your quick feedback.

Maybe it was a mistake from my side to promote this issue as a workaround for #2736.
The main issue is #5097, which I created just now to explain the in my opinion wrong behaviour when using DTOs. So when I use DTOs for input I expect that this DTO will be exactly used as an input for the GraphQL Mutation and no id should be automatically added. If the mutation needs one it can be specified as a property within the DTO. So this PR is mainly fixing issue #5097.

But as mentioned it can additionally be considered as a workaround for #2736. But you are right, it does not mainly fix this issue and the propsal using an allow list will be still open. Sorry for misunderstanding.

@jotwea jotwea changed the title Bugfix/respect input no Bugfix: Respect input DTO without adding additional id field Oct 26, 2022
@stale
Copy link
Copy Markdown

stale Bot commented Dec 25, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale Bot added the stale label Dec 25, 2022
@jotwea jotwea force-pushed the bugfix/respect-input-no-id branch from 6f7b30c to 2960b99 Compare December 26, 2022 14:27
@stale stale Bot removed the stale label Dec 26, 2022
@jotwea jotwea force-pushed the bugfix/respect-input-no-id branch 2 times, most recently from b1d40d8 to 8f86e31 Compare January 19, 2023 10:44
@alanpoulain alanpoulain force-pushed the bugfix/respect-input-no-id branch from 8f86e31 to 1801dfa Compare January 23, 2023 10:48
@alanpoulain alanpoulain merged commit c353e5a into api-platform:main Jan 23, 2023
@alanpoulain
Copy link
Copy Markdown
Member

Thank you @jotwea.

@alanpoulain
Copy link
Copy Markdown
Member

After some thought, maybe I will revert this PR. The condition is not right: we don't want to remove the ID for update and delete mutations.
You seem to use a custom mutation in your issue, but you don't use a custom resolver. I don't see how it can work.
Making the ID optional for custom mutations is probably a better way to solve your issue.

@alanpoulain
Copy link
Copy Markdown
Member

WDYT of this PR to replace yours?

#5359

@jotwea
Copy link
Copy Markdown
Contributor Author

jotwea commented Jan 23, 2023

I guess #5359 also solves the original problem mentioned in #5097 very well.

Your approach differs from mine that it is based on the existence of a resolver, mine is based on the existence of an input DTO. And you are right, I use a custom resolver as well in my project, so your solutions will work for me as well. The important thing is just that there will be a way to avoid an automatic id field.

@alanpoulain
Copy link
Copy Markdown
Member

Thanks for the answer.
It will be available in version 3.2.

jotwea added a commit to jotwea/api-platform-core that referenced this pull request Jan 25, 2023
syl20b pushed a commit to syl20b/api-platform-core that referenced this pull request Feb 8, 2023
soyuka pushed a commit to fraynaud1330/api-platform-core that referenced this pull request Feb 28, 2023
soyuka pushed a commit to mrossard/core that referenced this pull request Apr 14, 2023
Deuchnord pushed a commit to Deuchnord/api-platform-core that referenced this pull request Apr 25, 2023
@jotwea jotwea deleted the bugfix/respect-input-no-id branch October 13, 2023 12:52
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.

2 participants