How to solve the n+1 problem created by fractal

example.com?include=foo,foo.bar,foo.bar.baz,bla 
for 100 records per page == 400 queries!
The Fractal transformer
example.com/user/101/reviews?include=product,product.merchant
example.com/user/101/reviews?include=product,product.merchant
example.com/user/101/reviews?include=product
example.com/user/101/reviews?include=not-whitelisted.nested-relation
Review, Product and Merchant resources
The controller
Spatie query builder + JSON API paginate
The final output
Hooray! The queries

--

--

--

We love APIs

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Unseen Heroes

Unseen Heroes

We love APIs

More from Medium

Laravel Security Vulnerabilities Challenge And How to Address Them Using

Interface And Abstract Class

Express vs Koa — A Quick Comparison

How To Select Active Menu Item Using Jquery