reyesoft / ngx-jsonapi

JSON API client library for Angular 5+ 👌 :: Production Ready 🚀
https://ngx-jsonapi.reyesoft.com/
MIT License
101 stars 52 forks source link

Eager loaded relations aren't correctly populated #68

Closed frans-beech-it closed 6 years ago

frans-beech-it commented 6 years ago

Maybe we are just missing something. But we run into the issue that relations loaded thought the ?include= parameter aren't correctly populated when the service beloning to that service isn't registered manually.

If the service belonging to the related object isn't loaded the relation has an id but the content variable has the value none.

You can also see this behavior in the demo:

We added the following workaround to app.module.ts of our project:

export class AppModule {
    // temp workaround to be sure nested relations are correctly loaded/filled
    constructor(protected usersService: UsersService) {
        usersService.register();
    }
}
pablorsk commented 6 years ago

Hi @frans-beech-it, I added again @Autoregister decorator. With decorator, service.register(); is not required, but still necesary inject service.

https://github.com/reyesoft/ngx-jsonapi/pull/71/commits/9c4a96331f7634128562468062cab9542b710bda#diff-5e617bbbd31eeb3487a2f9cb91d9d449

Any ideas for a way to injection of dependency is not necessary? :thinking:

sunel commented 6 years ago

And Additional the data loaded is behaving differently when cache is enabled

Without cache or first time when loaded

2

With Cache after first time

1

pablorsk commented 6 years ago

I think original issue by @frans-beech-it was solved in #71

@sunel, Your example I don't understand very well.... If you open a new issue with the same example data but add and example uri and method? Maybe I understand your example and it's really the same issue.

sunel commented 6 years ago

@pablorsk created #78

ouranos commented 6 years ago

Working for me with the workaround @frans-beech-it suggested :clap: . Waiting for a release including #71 to test Autoregister().

Does it work with multi level association? eg: include: ['author', 'photos', 'photos.comments']

In my case the first relationship (photos) has an extra relationship (comments) but it's empty:

{
  "content": "none",
  "data": {}
}

I'll keep playing as it might come from my code.

Let me know if I should open a new issues or if you have some tips :)

ouranos commented 6 years ago

@pablorsk any ideas regarding the above? I tried to reproduce the case with the demo but it looks like the playground doesn't support requesting resources related to other resources, eg:

GET /v2/stores/1?include=books.chapters
adolf86 commented 6 years ago

Hi @ouranos. I'm finding the same problem with nested relationships. Have you managed to resolved that issue?

pablorsk commented 6 years ago

@adolf86, JsonApi playground backend dont support include or sorted refereces with ..

Try with version 1.1.2 if your problem is with library.

ouranos commented 6 years ago

@pablorsk updated to v1.1.4 @AutoRegister now works properly but it doesn't seem to fix the problem for nested relationships ("photo.comments" in my example)

jonasgrundtvig commented 6 years ago

@ouranos Did you find a solution or fix for the problem with nested relationships?

ouranos commented 6 years ago

@jonasgrundtvig No, we do manual HTTP calls and parsing for the few endpoints that need it.