ember-cli-mirage icon indicating copy to clipboard operation
ember-cli-mirage copied to clipboard

Relationships are not serialized by default?

Open pichfl opened this issue 4 years ago β€’ 7 comments

Is there a reason alwaysIncludeLinkageData isn't true by default? There is no way to reach the relationship from ember if not even the ids are serialized.

import { JSONAPISerializer } from 'ember-cli-mirage';

export default JSONAPISerializer.extend({
  alwaysIncludeLinkageData: true
});

pichfl avatar May 11 '20 15:05 pichfl

I've just hit this same issue πŸ™ˆ I lost a few hours trying to figure out why my definition of the relationships in the "backend" of mirage was incorrect

It is my understanding that this behaviour makes the default JSON:API serialiser invalid πŸ€” the content that the backend returns for a given entity shouldn't change based on the includes query param, only the contents of the JSON:API includes array

Would it be ok for me to submit a PR to flip this default?

mansona avatar Nov 09 '20 21:11 mansona

Yep, sounds good! I guess this would be a minor bump on miragejs and a major for ember-cli-mirage.

samselikoff avatar Nov 09 '20 22:11 samselikoff

so... there is a potential way to do it in the mean time if you were against a major bump πŸ€” you could just fix the default blueprint to make it a part of the serialiser it generates?

you could also create a deprecation in the case that the user-land serialiser doesn't have the parameter defined, but that really depends on how much you care about wanting to not do a major bump πŸ˜‚ thoughts? (I'm happy to do the extra work to fix the blueprint and make a deprecation if you think it's worth it?)

mansona avatar Nov 09 '20 22:11 mansona

I don’t really care about a major bump! Cared for way too long lol

samselikoff avatar Nov 09 '20 22:11 samselikoff

@samselikoff @mansona When I turned this on in the app serializer, it broke my tests. I'lll investigate further, but regardless the results (my setup is pretty basic), it's likely that some other apps would end up the same.

zeppelin avatar Nov 25 '20 14:11 zeppelin

I'm actually not sure re: the spirit of the spec. I think Resource Identifier Objects are really intended to be used to cross-reference resources that are being included in a compound document. Might be worth checking in with @dgeb before we change this behavior.

samselikoff avatar Nov 30 '20 15:11 samselikoff

I think Resource Identifier Objects are really intended to be used to cross-reference resources that are being included in a compound document.

While identifier objects may be included to indicate member(s) of a relationship, @samselikoff is right that their primary purpose is to provide linkage in a compound document.

Consider a has-many relationship that includes thousands of members: including a full set of those members can sometimes be unrealistic, while including a partial set can be confusing since you'll need to reference relationship links to understand that it's a partial set.

I think a sensible default is to always include links for relationships and, if related members are needed, include linkage data as well when requested via include.

dgeb avatar Dec 01 '20 12:12 dgeb