Giter Site home page Giter Site logo

Misunderstanding or ? about jsonapi-vuex HOT 7 CLOSED

santerref avatar santerref commented on June 1, 2024
Misunderstanding or ?

from jsonapi-vuex.

Comments (7)

mrichar1 avatar mrichar1 commented on June 1, 2024

I'm not sure what is causing this behaviour for you. The behaviour of the JSON spec is that it uses relationships if they are in the object, but if there is no relationship section at all then it won't remove them on the server.

In your above example, there is no _jv: { relationships: { ...}} key so this patch should have no effect on the server.

Equally if the object you are using in the patch is one from the store, then it should include the relationship section it had when it was fetched, so there should be no change.

It might help to set the cleanPatch: true config option when setting up the module - this will drop any keys in the patch that are also in the store. It is designed to stop out-of-date records in the store accidentally being 'added back' when a patch happens - but should also guarantee to remove all references to relationships etc.

Let us know if that helps?

from jsonapi-vuex.

santerref avatar santerref commented on June 1, 2024

Hi @mrichar1 !

Thanks for your quick reply.

I think my question was wrong.

When I send my PATCH request, I do not use the object (record) in the state, but only a raw JSON object: {_jv: {type: 'blogs', id: '1'}}.

I think this is my issue.

But it might be a great option (or not) to add !? Something that could find an existing record before sending the PATCH request to make sure relationships are kept !

Example: mergeExistingOnPatch: true.

The cleanPatch will help me because I only want to send what have been changed.

Francis.

from jsonapi-vuex.

mrichar1 avatar mrichar1 commented on June 1, 2024

Hi,

Creating a new object 'from scratch' shouldn't matter. If the object doesn't contain a relationships section (in _jv) then the patch won't modify any relationships. I've just tested this using the testapp provided with the library and it behaves as expected.

The store is empty, and the object I'm passing to the patch action is:

{
   _jv: {
     type: 'widget',
     id: '1',
   },
   color: 'red',
 }

(Different type/attribute, but the same effect).

Can you let me know what JSONAPI server you are running/connecting to? There is a possibility that the implementation doesn't follow the JSONAPI spec correctly.

from jsonapi-vuex.

santerref avatar santerref commented on June 1, 2024

Hi,

I am using the Laravel JSON API package: https://laravel-json-api.readthedocs.io/en/latest/

I will make more tests and see what response I get and if the relationships section is in _jv.

However, I do not say that the relationships are modified or removed from the server (database), I said that the relationships are removed from the Vuex store when the response of the PATCH request is parsed from your package.

All comments and tags are removed from the Vuex store.

from jsonapi-vuex.

mrichar1 avatar mrichar1 commented on June 1, 2024

Ahh - apologies - I thought you meant that the patch was removing relationships on the server-side. I now see what you mean!

With patch the server can return no data (204) or a representation of the resulting patched object (200).https://jsonapi.org/format/#crud-updating-responses-200

If it returns 204, then the code already does a 'merge' of the patch object onto the store, so relationships should be unaffected.

If it returns 200, then the data should contain the relationships section with the appropriate relationship identifier objects. Something like:

data: {
  type: 'blogs',
  id: '1'
  attributes: {
    published: false
  },
  relationships: {
    tags: {
      data; { type: 'tags', id: '10' }
    },
    comments: {
      data: { type: 'comments', id: '20' }
    }
}

Since the related items are already in the store (from the original get with include) these will just create a reference 'pointing' to these objects.

Can you set the config option preserveJson: true and then paste the contents of _jv/json for the get and patch operations?

from jsonapi-vuex.

hakuna0829 avatar hakuna0829 commented on June 1, 2024

Hello, @mrichar1

I am new guy for this package and I'd like to use this one for my project.
So I have one issue and want your help.

I've got the json api like this.
baseUrl : https://dev-54ta5gq-2mtjdsd3z4gog.de-2.platformsh.site/jsonapi
method: Get,
its response looks like following
`
{
"jsonapi": {
"version": "1.0",
"meta": {
"links": {
"self": {
"href": "http://jsonapi.org/format/1.0/"
}
}
}
},
"data": [],
"links": {
"action--action": {
"href": "https://dev-54ta5gq-2mtjdsd3z4gog.de-2.platformsh.site/jsonapi/action/action"
},
"api_key--api_key": {
"href": "https://dev-54ta5gq-2mtjdsd3z4gog.de-2.platformsh.site/jsonapi/api_key/api_key"
},
"base_field_override--base_field_override": {
"href": "https://dev-54ta5gq-2mtjdsd3z4gog.de-2.platformsh.site/jsonapi/base_field_override/base_field_override"
}
}
}

`

I want to get the data from the href url related to the specific links key.
But I don't know how to do this.
Can you give me advice?
Thanks.

from jsonapi-vuex.

stale avatar stale commented on June 1, 2024

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.

from jsonapi-vuex.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.