PHPackages                             secundo/laravel-graphql-query-builder - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. secundo/laravel-graphql-query-builder

ActiveLibrary[API Development](/categories/api)

secundo/laravel-graphql-query-builder
=====================================

A powerful and elegant GraphQL query builder for PHP, designed specifically for Laravel applications

v1.1.0(2mo ago)26.7k—9.4%MITPHPPHP ^8.3CI passing

Since Sep 17Pushed 2mo agoCompare

[ Source](https://github.com/SecundoAS/laravel-graphql-query-builder)[ Packagist](https://packagist.org/packages/secundo/laravel-graphql-query-builder)[ Docs](https://github.com/SecundoAS/laravel-graphql-query-builder)[ RSS](/packages/secundo-laravel-graphql-query-builder/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (14)Versions (4)Used By (0)

Laravel GraphQL Query Builder
=============================

[](#laravel-graphql-query-builder)

[![Latest Version on Packagist](https://camo.githubusercontent.com/a8e13df56ab6b4c9ae943d1d370dc4932edf103bbc4f0a73622295b23b31f4ab/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f736563756e646f2f6c61726176656c2d6772617068716c2d71756572792d6275696c6465722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/secundo/laravel-graphql-query-builder)[![GitHub Tests Action Status](https://camo.githubusercontent.com/c1513880a1872683d22e2733d54ad222c64a4f22d0ae3fb2cd8d8e1889124c8f/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f536563756e646f41532f6c61726176656c2d6772617068716c2d71756572792d6275696c6465722f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/SecundoAS/laravel-graphql-query-builder/actions?query=workflow%3Arun-tests+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/2bcf73340dcfaf4c8fa3b039a5ab982a9252067db33f40a276a2f81a9778bbd2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f736563756e646f2f6c61726176656c2d6772617068716c2d71756572792d6275696c6465722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/secundo/laravel-graphql-query-builder)

A powerful and elegant GraphQL query builder for PHP, designed specifically for Laravel applications. Build GraphQL queries and mutations with a fluent, type-safe interface.

Features
--------

[](#features)

- **Fluent API**: Build GraphQL queries using an intuitive, chainable interface
- **Type Safety**: Full PHP 8+ type hints for better IDE support and fewer runtime errors
- **Laravel Integration**: Built with Laravel conventions and auto-discovery
- **Variable Support**: Automatic variable handling with type safety
- **Fragment Support**: Create reusable query fragments
- **Inline Fragments**: Type-based conditional field selection

Requirements
------------

[](#requirements)

- PHP 8.3 or higher
- Laravel 11.0 or higher

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require secundo/laravel-graphql-query-builder
```

The service provider will be automatically registered using Laravel's package discovery.

Quick Start
-----------

[](#quick-start)

### Basic Query

[](#basic-query)

```
use Secundo\GraphQL\Builder;

$builder = new Builder();

$query = $builder->query()
    ->field('products', [], ['id', 'title', 'handle'])
    ->toGraphQL();

// Output:
// query {
//   products {
//     id
//     title
//     handle
//   }
// }
```

### Query with Arguments

[](#query-with-arguments)

```
$query = $builder->query()
    ->field('product', ['id' => 'gid://shopify/Product/123'], ['id', 'title', 'handle'])
    ->toGraphQL();

// Output:
// query {
//   product(id: "gid://shopify/Product/123") {
//     id
//     title
//     handle
//   }
// }
```

### Nested Fields

[](#nested-fields)

```
$query = $builder->query()
    ->field('products', ['first' => 10], function ($field) {
        $field->field('edges', [], function ($field) {
            $field->field('node', [], ['id', 'title']);
            $field->field('cursor');
        });
        $field->field('pageInfo', [], ['hasNextPage', 'endCursor']);
    })
    ->toGraphQL();
```

### Using Variables

[](#using-variables)

```
$query = $builder->query('GetProduct')
    ->variable('id', 'ID!', 'gid://shopify/Product/123')
    ->field('product', ['id' => '$id'], ['id', 'title', 'description'])
    ->toGraphQL();

// Get variable values for the request
$variables = $builder->getVariableValues();

// Output:
// query GetProduct($id: ID!) {
//   product(id: $id) {
//     id
//     title
//     description
//   }
// }
// Variables: {"id": "gid://shopify/Product/123"}
```

### Mutations

[](#mutations)

```
$mutation = $builder->mutation('UpdateProduct')
    ->variable('id', 'ID!')
    ->variable('input', 'ProductInput!')
    ->field('productUpdate', ['id' => '$id', 'product' => '$input'], function ($field) {
        $field->field('product', [], ['id', 'title']);
        $field->field('userErrors', [], ['field', 'message']);
    })
    ->toGraphQL();
```

### Fragments

[](#fragments)

```
$query = $builder->query()
    ->fragment('ProductFields', 'Product', ['id', 'title', 'handle', 'createdAt'])
    ->field('products', [], function ($field) {
        $field->field('edges', [], function ($field) {
            $field->field('node', [], ['...ProductFields']);
        });
    })
    ->toGraphQL();
```

### Inline Fragments

[](#inline-fragments)

```
$query = $builder->query()
    ->field('node', ['id' => '$id'], function ($field) {
        $field->field('id');
        $field->inlineFragment('Product', function ($fragment) {
            $fragment->field('title');
            $fragment->field('handle');
        });
        $field->inlineFragment('Collection', function ($fragment) {
            $fragment->field('title');
            $fragment->field('description');
        });
    })
    ->toGraphQL();

// Output:
// query {
//   node(id: $id) {
//     id
//     ... on Product {
//       title
//       handle
//     }
//     ... on Collection {
//       title
//       description
//     }
//   }
// }
```

Advanced Usage
--------------

[](#advanced-usage)

### Multiple Variables with Default Values

[](#multiple-variables-with-default-values)

```
$query = $builder->query('SearchProducts')
    ->variables([
        'first' => ['type' => 'Int', 'value' => 10],
        'query' => ['type' => 'String', 'value' => 'title:shirt'],
        'sortKey' => ['type' => 'ProductSortKeys', 'value' => 'CREATED_AT']
    ])
    ->field('products', [
        'first' => '$first',
        'query' => '$query',
        'sortKey' => '$sortKey'
    ], ['id', 'title']);
```

### Field Aliases

[](#field-aliases)

```
use Secundo\GraphQL\Types\Field;

$field = new Field('product');
$field->alias('myProduct')
    ->arguments(['id' => 'gid://shopify/Product/123'])
    ->fields(['id', 'title']);
```

### Directives

[](#directives)

```
$field = new Field('expensiveField');
$field->directive('include', ['if' => '$includeExpensive'])
    ->fields(['data']);

$field = new Field('debugInfo');
$field->directive('skip', ['if' => '$production'])
    ->fields(['logs']);
```

Laravel Integration
-------------------

[](#laravel-integration)

### Using the Facade

[](#using-the-facade)

```
use Secundo\GraphQL\Facades\GraphQL;

$query = GraphQL::query()
    ->field('shop', [], ['name', 'email'])
    ->toGraphQL();
```

### Dependency Injection

[](#dependency-injection)

```
use Secundo\GraphQL\GraphQL;

class ProductController extends Controller
{
    public function __construct(
        private GraphQL $graphql
    ) {}

    public function index()
    {
        $query = $this->graphql->query()
            ->field('products', ['first' => 10], ['id', 'title'])
            ->toGraphQL();

        // Execute query...
    }
}
```

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

If you discover a security vulnerability, please send an email to . All security vulnerabilities will be promptly addressed.

Credits
-------

[](#credits)

- [Secundo Team](https://github.com/SecundoAS)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

47

—

FairBetter than 94% of packages

Maintenance88

Actively maintained with recent releases

Popularity27

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 77.3% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~182 days

Total

2

Last Release

61d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/7867c8e6cb949ab73460f6189d49e8423431864c495a389e650e82509e44d954?d=identicon)[einar-hansen](/maintainers/einar-hansen)

---

Top Contributors

[![einar-hansen](https://avatars.githubusercontent.com/u/49709354?v=4)](https://github.com/einar-hansen "einar-hansen (17 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (5 commits)")

---

Tags

apiclientlaravelgraphqlquery buildershopifyGraphql Client

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Rector

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/secundo-laravel-graphql-query-builder/health.svg)

```
[![Health](https://phpackages.com/badges/secundo-laravel-graphql-query-builder/health.svg)](https://phpackages.com/packages/secundo-laravel-graphql-query-builder)
```

###  Alternatives

[andreaselia/laravel-api-to-postman

Generate a Postman collection automatically from your Laravel API

1.0k586.2k3](/packages/andreaselia-laravel-api-to-postman)[resend/resend-laravel

Resend for Laravel

1191.4M6](/packages/resend-resend-laravel)[mll-lab/laravel-graphiql

Easily integrate GraphiQL into your Laravel project

683.2M9](/packages/mll-lab-laravel-graphiql)[api-platform/laravel

API Platform support for Laravel

59126.4k6](/packages/api-platform-laravel)[dragon-code/laravel-json-response

Automatically always return a response in JSON format

1118.6k1](/packages/dragon-code-laravel-json-response)[alexaandrov/laravel-graphql-client

GraphQL client for laravel/lumen

125.6k](/packages/alexaandrov-laravel-graphql-client)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
