Skip to content

Patching relationships should be possible via relationship URLs. #88

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

Closed
colinhiggs opened this issue Sep 9, 2019 · 5 comments
Closed
Labels
enhancement New feature or request pinned Prevent stalebot from marking as stale

Comments

@colinhiggs
Copy link

The jsonapi spec allows for altering relationship information either by PATCHing a resource and including the relationship information (https://jsonapi.org/format/#crud-updating-resource-relationships) or by sending PATCH, POST and DELETE requests to relationship URLs (https://jsonapi.org/format/#crud-updating-relationships).

jsonapi-vuex currently only supports the former and there are good reasons one might want to choose the latter. For instance, when updating a resource with many related resources (such as an article with many comments) we might have fetched only a subset of those related resources (because the results are paged, for example). If we PATCH said article and include the comments relationship in the patch, we will send an incomplete list of comments and unintentionally cause the server to delete many other comments from the relationship.

To support the latter, I think a diff style function which generates a list of patching actions (some of which are actually POST or DELETE in HTTP terms) might be useful. Something like:

todo = generate_patch_todo(new_data, old_data)
// todo = 
// [
//    ['PATCH', '/articles/1', {article_attributes}],
//    ['POST', '/articles/1/rels/comments', [{comments, 5}]],
//    ['DELETE', '/articles/1/rels/comments', [{comments, 2}, {comments,3}]]
//]
for (let todo_item of todo) {
    dispatch(todo_item)
}
@stale
Copy link

stale bot commented Nov 8, 2019

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 Nov 8, 2019
@mrichar1 mrichar1 removed the stale label Nov 8, 2019
@stale
Copy link

stale bot commented Jan 7, 2020

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
Copy link

stale bot commented Mar 7, 2020

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.

@geoidesic
Copy link

The examples shown only deal with non-relational patching.

  1. Could you include an example of how to PATCH related data?
  2. Are there helper methods for setting up patches or does one manually have to write the JSON object?

@mrichar1 mrichar1 mentioned this issue Jul 7, 2020
@stale stale bot added the stale label Jul 13, 2020
@mrichar1 mrichar1 removed the stale label Jul 14, 2020
@stale stale bot added the stale label Sep 12, 2020
@stale stale bot closed this as completed Sep 19, 2020
@mrichar1 mrichar1 reopened this Oct 6, 2020
@stale stale bot removed the stale label Oct 6, 2020
@stale stale bot added the stale label Dec 8, 2020
@mrichar1 mrichar1 removed the stale label Dec 10, 2020
@stale stale bot added the stale label Feb 22, 2021
@mrichar1 mrichar1 added pinned Prevent stalebot from marking as stale and removed stale labels Feb 23, 2021
Repository owner deleted a comment from stale bot Aug 16, 2021
Repository owner deleted a comment from stale bot Aug 16, 2021
Repository owner deleted a comment from stale bot Aug 16, 2021
Repository owner deleted a comment from stale bot Aug 16, 2021
Repository owner deleted a comment from stale bot Aug 16, 2021
@mrichar1
Copy link
Owner

There are now 3 methods to handle updates via relationship URLs:

  • postRelated - add relationships.
  • deleteRelated - remove relationships.
  • patchRelated - replace relationships.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request pinned Prevent stalebot from marking as stale
Projects
None yet
Development

No branches or pull requests

3 participants