webonyx/graphql-php
PHP implementation of the GraphQL specification, based on graphql-js. Build schemas, types, and execute queries/mutations in your PHP apps. Widely used, well-tested, and documented with examples and class reference.
webonyx/graphql-php is a reference implementation of GraphQL for PHP, ensuring spec compliance and interoperability with tools like GraphiQL, Apollo, and Relay. This aligns perfectly with Laravel’s ecosystem, where REST APIs are increasingly supplemented (or replaced) by GraphQL for flexible, client-driven data fetching.Route::post('/graphql', [GraphQLController::class, 'handleRequest'])). The package’s schema-first approach complements Laravel’s Eloquent ORM and API resource patterns.// app/GraphQL/Schema.php
use GraphQL\Type\Definition\Type;
use GraphQL\Schema;
$schema = new Schema([
'query' => new ObjectType([
'name' => 'Query',
'fields' => [
'user' => [
'type' => UserType::of(),
'resolve' => fn ($root, $args) => User::find($args['id']),
],
],
]),
]);
auth:api) and Policies to gate GraphQL queries (e.g., @auth directives or resolver logic).QueryComplexity rule), malicious queries (e.g., deeply nested introspection) can DoS the server. Mitigation: Enable depth/complexity limits and PHP max_execution_time.with(), data loaders, or batch loading.Route::prefix('api')) or replace it entirely?@cache) be required?vlucas/phpdataloader) needed to avoid N+1 queries?GraphQLMiddleware to validate/authenticate requests.Route::post('/graphql', [GraphQLController::class]).GraphQL::persistRootTypeDefinitions()).resolve => fn ($root, $args) => User::find($args['id']))./graphql/users) alongside existing REST APIs.UserResource::collect(User::all()))./api/v1/users?with=posts) with GraphQL queries.graphql-php’s Type classes).illuminate/support).composer require webonyx/graphql-php.app/GraphQL/Schema.php).GraphQLController@handle).Route::post('/graphql', [GraphQLController::class]).QueryComplexity/QueryDepth rules.DisableIntrospection::ENABLED.GraphQL::setErrorHandler()).@deprecated) to warn users.extend type Query { newField: String }).GraphQL::executeQuery() with debugFlag: true to inspect resolver errors.microtime(true) in resolvers).webonyx/graphql-php for breaking changes (e.g., spec updates).GraphQL::executeQuery() with validate: true.try-catch and return GraphQL::error().DB::enableQueryLog() to debug SQL in resolvers.graphql-php's introspection or GraphQL Docs).How can I help you explore Laravel packages today?