Strengths:
@searchBy and @sortBy directives enable complex, type-safe filtering and sorting directly in GraphQL queries, reducing backend logic complexity and improving query efficiency.user.posts.title) aligns well with Laravel’s Eloquent ORM and nested query patterns.Mixed types, improving developer experience and reducing runtime errors.@stream directive enables pagination/streaming for large datasets, critical for APIs serving real-time or voluminous data.Fit with Laravel Ecosystem:
=, >, <, etc.) and relation handling map cleanly to Eloquent query builder methods.Potential Gaps:
v9.x+), which may necessitate migration if using alternative GraphQL libraries (e.g., GraphQL for PHP).$context->getDirective() to Eloquent queries).@searchBy(condition: "gt:created_at")).N+1 queries).@sortBy("user.address.city") without with()).with() clauses in resolvers or use Laravel’s loadMissing().String! with union types for custom operators).where, orderBy), minimizing resolver logic.@stream) benefits real-time analytics or large dataset APIs.composer require nuwave/lighthouse).type User @searchBy { ... }).type Query {
users: [User] @searchBy(conditions: [
{ field: "age", operator: "gt", value: 25 },
{ field: "posts.title", operator: "contains", value: "Laravel" }
])
}
public function resolve($root, array $args) {
$conditions = $this->context->getDirective('searchBy')?->getArgument('conditions');
$query = User::query();
// Parse conditions into Eloquent clauses
return $query->get();
}
with() clauses for relations to avoid N+1.lighthouse-cache).@searchBy).Log::debug($context->getDirective())).@searchBy).created_at for gtHow can I help you explore Laravel packages today?