DEV Community

ujwal dhakal
ujwal dhakal

Posted on

Fast Prototyping with Lighthouse Laravel

Laravel is a full-fledged framework which is suitable for any kind of application from small, medium to large. And what so special about Laravel is the development process, they claim about rapid web development with it and there is no doubt.

What if I told, you can create an app a lot faster than before by using Lighthouse on Laravel. Lighthouse is a Graphql wrapper for Laravel.

I have used this on a side project DAANI API. DAANI is a crowdsourcing app build on Svelte & Laravel, Lighthouse.

Building on Graphql was easy than the normal REST approach. Here are some points why I felt that this could speed up the development process -:

  • Let's say if you want to create a record, just define a schema and action in the same line as this and it will create a model no need to create separate routes, controllers, requests for this.

    type Mutation {
      createPost(title: String!): Post @create
    }
    

and if you want to read the data this could be simple as

type Query {
  posts: [Post!]! @paginate
}
Enter fullscreen mode Exit fullscreen mode

Note -: Mutation are for write part where (you would do update,create,delete)as Query are for read

Most of the CRUD actions are handled with default Directives provided by Lighthouse.

  • Most of the time we spend time documenting the Apis. With Lighthouse they provide default Playground for testing your API along with the documentation of yours schemas.

  • If you feel like you need a custom way around for your requirements. Extending is easy all you need to do is create a Resolver i.e (mutation or query) it acts as a controller like we used to do.

Conclusion

If you haven't worked with Graphql yet this could be a fun approach to know the Graphql mechanism. And if you have already tried it let me know your thoughts!

Happy Coding!

Daani Source Code

Top comments (0)