Migrating to GraphQL on Laravel with Lighthouse

Josh Krawczyk
8 min readJan 30, 2019

I will be covering how to covert your Laravel Controllers, Resources, and Form Requests into a single GraphQL endpoint. After the conversion you will find that the amount of boilerplate needed per Model will be drastically reduced. My demo consists of a Ticket System and I am using VueJS to power the frontend.

So what is GraphQL?

To quote the GraphQL website,

GraphQL is a query language for APIs and a runtime for fulfilling those queries with your existing data. GraphQL provides a complete and understandable description of the data in your API, gives clients the power to ask for exactly what they need and nothing more, makes it easier to evolve APIs over time, and enables powerful developer tools.

Basically GraphQL is a layer between your client app and your data. GraphQL is great because you just have to specify the data that can be queried and the client can pick and choose what data to pull. As opposed to a REST API where you define rigid endpoints that return the same amount of data every time. You could hack some parameters into the request to filter data, but it isn’t provided out of the box and may not scale well.

The Setup

I will be using Lighthouse to serve the graphql endpoint. Lighthouse is great because…

--

--

Josh Krawczyk

Systems Engineer by day, Programmer by night. Just doing my best to juggle life, family, career, and passion.