graphiti-api / graphiti

Stylish Graph APIs
https://www.graphiti.dev/
MIT License
974 stars 139 forks source link

Fix Sparse fieldsets to work with relationships #389

Closed mrhardikjoshi closed 7 months ago

mrhardikjoshi commented 3 years ago

Fixes #301

The sparse fieldsets is not filtering relationships. Currently if we specify any attribute and/or relationship in fields param, it works correctly on attributes but the not on relationships. It returns all the relationships, ignoring fields param. According to jsonapi format both attribute and relationship should be supported. This PR fixes that.

In case of fields param having only attribute(s) in them, this change will restrict all relationships as well because of the following line from jsonapi format doc (fields represent both attributes and relationships)

If a client requests a restricted set of fields for a given resource type, an endpoint MUST NOT include additional fields in resource objects of that type in its response.

I have not changed include section because of the following specification from the jsonapi format doc.

The only exception to the full linkage requirement is when relationship fields that would otherwise contain linkage data are excluded via sparse fieldsets

So in case of having a relationship mentioned in include and sparse fieldsets having some atttribute, this will still return the relationship but the linkage won't be there.

smai-f commented 2 years ago

Just being the messenger from the Graphiti Slack so future perusers are aware...

image

https://graphiti-api.slack.com/archives/CJLJFRQFK/p1633956166007200?thread_ts=1632930343.006800&cid=CJLJFRQFK

jkeen commented 7 months ago

I'm getting up to speed here and cleaning up some things and am going to have to trust the wisdom of @richmolj and close this PR until I'm more convinced that this is a real issue.