beyondcode/laravel-query-detector

[Question] How to use this in an API application

johannesschobel opened this issue · 9 comments

Dear @mpociot ,

this is a question regarding how to use this package within an API-style application (e.g., that has no (graphical) UI, but rather outputs data as JSON).

From what i understand, I would guess, one would need to provide its own Output class, right?
Would it be possible to provide a JsonOutput class for this purpose?

If so, would you accept a PR to add this feature?
All the best, cheers

You could use the Log output and just look into the log files to see the detected N+1 queries.

yeah, but if you run the application you would need to take a look at the Log file.. This would slow down "development" speed, i think.. For the regular "Web UI" you have a JavaScript Alert Box which immediately tells you, "what went wrong"..

Would be cool to have this for JSON as well..
I am thinking of something like "add a custom JSON to the JSON response".. What do you think about this?

What if the package would provide events when a query is inefficient, so we could listen for that event and do what we want with that information? Like, I could connect it to Sentry/BugSnag/etc, or connect PHPUnit to automatically fail if one of the queries is not using eager loading.

What do you guys think?

I think this would be a very cool Output feature :) I like the idea

Yeah, Event could be another output format.
Does anyone want to PR this feature?

I'll try to come up with something tomorrow :)

Okay Great. Thinking about it - I would probably just fire the events all the time. Don’t think there’s a need to have this as an output method. If you want to listen for these events you can do it.

Maybe, it would be great to implement Output class integrated with Clockwork?

I created a Json output for APIs: #25