RestQL Data Resolution Package for Laravel
Published on by Paul Redmond
RestQL is a data resolution package for your Laravel models by Gregori Piñeres:
RestQL is a Laravel eloquent-based data resolution package. This package tries to adopt GraphQL principles solving only the data that the client requests. RestQL uses your Laravel models as an entry point to add queries to then based on the eloquent methods.
This package has data resolution clauses, which are a way to improve queries based on parameters provided by the client. It’s RESTful but uses principles from GraphQL.
From the project’s readme, here’s an example of the RestQL route:
use Restql\Restql;use Illuminate\Http\Request; // The RestQL endpoint.Route::get('restql', function (Request $request) { return Restql::resolve($request);});
And with that route, how you might use this package on the frontend to retrieve author names:
axios.get('http://laravel.app/api/restql', { params: { authors: { select: 'name' } }}).then(({ data: authors }) => { // Do something... console.log(authors)});
Finally, you’d get the following JSON back:
{ "authors": [ { "id": 1, "name": "Kasey Yost" }, { "id": 2, "name": "Ike Barton" }, { "id": 3, "name": "Emie Daniel" }, {...} ]}
Learn More
You can learn more about this package, get full installation instructions, and view the source code on GitHub at gregorip02/restql.