Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Graphql Laravel

Graphql Laravel Laravel Package

rebing/graphql-laravel

Code-first GraphQL integration for Laravel based on webonyx/graphql-php. Define schemas, types, queries and mutations in PHP. Supports multiple schemas, per-schema middleware, resolver middleware, and n+1 prevention via dataloaders or SelectFields eager loading.

View on GitHub
Deep Wiki
Context7

rebing/graphql-laravel brings a code-first GraphQL server to Laravel, powered by webonyx/graphql-php. Define your entire schema in PHP classes—types, queries, and mutations—and expose them as request endpoints without maintaining .graphql schema files.

Ideal for Laravel apps that want strong schema control, extensibility, and performance tuning via built-in data-loading strategies.

  • Build queries and mutations as HTTP endpoints
  • Support multiple schemas with per-schema types, middleware, and execution middleware
  • Add custom resolver middleware per field/query/mutation
  • Avoid N+1 with Dataloaders or SelectFields (optimized select() + eager with())
  • Apply per-type privacy rules for authorization and data visibility
Frequently asked questions about Graphql Laravel
How do I define a GraphQL schema in Laravel using this package without writing `.graphql` files?
Define your schema entirely in PHP classes. Create `Type`, `Query`, and `Mutation` classes extending the package’s base classes (e.g., `Type`, `ObjectType`). For example, a `UserType` would extend `ObjectType` and define fields like `id()` and `name()`. The package auto-discovers these classes and builds the schema at runtime.
Can I use this package with Laravel 13? Does it support PHP 8.2+?
Yes, **rebing/graphql-laravel** explicitly supports Laravel 12.x and 13.x with PHP 8.2+. The package leverages Laravel’s service container and Artisan commands, ensuring compatibility with the latest Laravel features. Check the [GitHub releases](https://github.com/rebing/graphql-laravel/releases) for version-specific notes.
How do I prevent N+1 queries when fetching Eloquent relationships in GraphQL?
Use **SelectFields** for optimized `select()` and `with()` clauses based on GraphQL field selections, or **Dataloaders** for batching database queries. Both strategies are built into the package. For example, `SelectFields` automatically generates efficient Eloquent queries, while Dataloaders defer resolution until all fields are requested, reducing redundant queries.
Is it possible to have multiple GraphQL schemas in a single Laravel app? For example, one for admin and one for public users?
Yes, the package supports **multiple schemas** with independent queries, mutations, types, and middleware. Configure each schema in its own service provider or use the `graphql:schemaConfig` Artisan command to generate schema-specific configurations. This is ideal for multi-tenancy, feature flags, or microservices.
How do I add authentication or authorization to specific GraphQL queries or mutations?
Use **resolver middleware** or **execution middleware** for per-field or global authorization. For example, add `authorize()` methods to your `Query` or `Mutation` classes, or use middleware like `AddAuthUserContextValueMiddleware` to inject the authenticated user into the GraphQL context. You can also apply Laravel middleware to GraphQL routes.
Does this package support persisted queries for performance optimization?
Yes, you can enable **persisted queries** via the `AutomaticPersistedQueriesMiddleware`. This reduces payload size and parsing overhead by caching and reusing query hashes. Configure it in your schema’s execution middleware pipeline to validate and resolve persisted queries automatically.
How do I test GraphQL endpoints in Laravel using this package?
The package includes built-in test helpers like `TestCase` and `TestCaseDatabase` for unit and integration tests. Use Laravel’s HTTP testing tools to send GraphQL requests (e.g., `Http::post('/graphql', ['query' => '...'])`). Fixtures like `User` and `Post` models are provided for quick setup, and you can mock dependencies with Laravel’s testing utilities.
Can I integrate third-party GraphQL tools like Apollo Client or Relay with this package?
Absolutely. This package generates a standard GraphQL endpoint (`/graphql`) that works with any GraphQL client, including Apollo Client, Relay, or GraphQL Playground. Ensure your client sends requests to the correct endpoint (e.g., `POST /graphql` with a `query` field) and handles responses in the GraphQL format.
What are the alternatives to this package for Laravel GraphQL, and how does it compare?
Alternatives include **Lighthouse** (supports subscriptions and SDL-first schemas) and **GraphQL for Laravel** (simpler but less feature-rich). **rebing/graphql-laravel** stands out for its **code-first approach**, **multiple schema support**, and **performance optimizations** like SelectFields and Dataloaders. It’s ideal for developers who prefer PHP classes over `.graphql` files and need fine-grained control over middleware and data loading.
How do I debug performance issues in my GraphQL queries, especially with complex nested relationships?
Use **OpenTelemetry** integration to trace GraphQL operations per field or schema. Enable it via configuration and inspect traces in tools like Jaeger or Laravel’s built-in debugging. For Eloquent queries, enable Laravel’s query logging (`DB::enableQueryLog()`) and analyze the generated SQL. The package also provides tools like `SelectFields` to optimize queries automatically.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport