Laravel

How to implement GraphQL APIs with Laravel?

December 3, 2025

download ready
Thank You
Your submission has been received.
We will be in touch and contact you soon!

Implement GraphQL in Laravel using the Lighthouse package for schema-first development install via Composer, define types/queries in graphql/schema.graphql, and access via /graphql endpoint with built-in playground.​

Install nuwave/lighthouse for automatic resolvers from Eloquent models, publish schema/config, and define queries/mutations in a single schema file. Add directives for auth/validation, then test with GraphQL Playground at /graphiql. Scales well for complex APIs with minimal boilerplate.​

Code

composer require nuwave/lighthouse
php artisan vendor:publish --provider="Nuwave\Lighthouse\LighthouseServiceProvider"
php artisan lighthouse:publish-schema

# graphql/schema.graphql
type Query {
  posts: [Post!]! @all
  post(id: ID! @eq): Post @find
}

type Post {
  id: ID!
  title: String!
  content: String!
}

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


// routes/web.php
Route::get('/graphiql', '\Nuwave\Lighthouse\GraphiQLController@index');

# Test query:
# { posts { id title } }
Hire Now!

Need Help with Laravel Development ?

Work with our skilled laravel developers to accelerate your project and boost its performance.
**Hire now**Hire Now**Hire Now**Hire now**Hire now