Skip to content
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

[FR] Runtime Serializer Resolver for Relator (support for heterogenous relationship types) #41

Open
jaridmargolin opened this issue Apr 6, 2022 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@jaridmargolin
Copy link
Contributor

Is your feature request related to a problem? *

Currently, the Relator constructor assumes that there will be a single serializer class used for each relator. However, as we are building out a "SearchResultsSerializer", we would like to return a "result" relationship which may be one of several types. The fetch function of the relator will be smart enough to return the correct data based on the data passed to it, but there is no way to dynamically select the correct Serializer.

{
  relationships: {
    result: { "data": { "type": "people", "id": "9" } }
  }
}

or

{
  relationships: {
    result: { "data": { "type": "item", "id": "5" } }
  }
}

Ref: https://discuss.jsonapi.org/t/how-to-implement-a-search-api/35/3

Describe the solution you'd like*

It would be great if we could pass in a Serializer (current functionality) or a function that takes the data as the first parameter and returns a Serializer class to use.

Describe alternatives you've considered*

Another option could be to specify each possible type as a relator but it seems unnecessary to have to pass null relationships for every supported type:

{
  relationships: {
    people: null,
    item: { "data": { "type": "item", "id": "5" } }
  }
}

Additional context

I'll need to take a closer look at the code to ensure it wouldn't be a nightmare to implement, but happy to do the leg work on this if you agree with the API decisions and are willing to review/merge the work.

@jaridmargolin jaridmargolin added the enhancement New feature or request label Apr 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants