graphiti-api / graphiti

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

Is it possible to structure the raw response like the Vandal JSON preview? #395

Closed raghubetina closed 2 years ago

raghubetina commented 2 years ago

Hi all,

I was hoping to teach non-programmers how to consume a Graphiti API with a no-code tool. Since they won't be writing any custom code in the client, it would be very helpful if the API response had the details of associated objects within the main resource itself — the way that Vandal previews it when you click "View as JSON":

Screen Shot 2021-11-16 at 10 49 14 AM

Unfortunately (for our purposes), the actual JSON:API response has the associated data located far away (in includes), with only links and IDs directly within data.relationships.

Screen Shot 2021-11-16 at 10 49 40 AM

I'm trying to figure out how to customize the response to look the way it does within Vandal's "View as JSON" preview; i.e., with each associated object's details within data.relationships, rather than separately in includes. I assume that Vandal is doing it client-side?

So far I think I may have to modify renderer.rb. If not, I was hoping someone could point me in the right direction.

Thank you!

richmolj commented 2 years ago

You should get this out of the box if you add .json to the url

raghubetina commented 2 years ago

@richmolj That's good to know! It works for a resource by itself, but I can't seem to get it working when relationships are included (because it's interpreting the .json as another relationship to include, I think).

For example, in the sample application, visiting /api/v1/departments/1?include=teams.json produces an Graphiti::Errors::InvalidInclude, 'The requested included relationship "json" is not supported.'

I tried adding some arbitrary parameters after include but haven't gotten a working solution yet. Would appreciate any advice!

richmolj commented 2 years ago

.json comes before the ?

raghubetina commented 2 years ago

🤦🏾‍♂️ thank you!