PHPackages                             cis-bv/gql-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. cis-bv/gql-builder

ActiveLibrary[API Development](/categories/api)

cis-bv/gql-builder
==================

Simple GraphQl-Query-Builder

v0.1.0(1y ago)01151MITPHPPHP ^8.3

Since Oct 20Pushed 3mo ago1 watchersCompare

[ Source](https://github.com/cis-ks/gql-builder)[ Packagist](https://packagist.org/packages/cis-bv/gql-builder)[ RSS](/packages/cis-bv-gql-builder/feed)WikiDiscussions master Synced today

READMEChangelog (1)DependenciesVersions (3)Used By (1)

PHP GraphQL Query-Builder
=========================

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

Inspired by the Builder-Part of the [PHP GraphQL Client by mghonemiy](https://github.com/mghoneimy/php-graphql-client) this builder provides a simple way to generate Graph-QL-Queries and provide the string.

This library don't include any Client or Response-Decoding functionality and requires the handling of Client-Request and -Responses separately.

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

[](#installation)

```
composer require cis-bv/gql-builder
```

Usage
-----

[](#usage)

The main entry point for usage is the Query-class. You can simply create a Query with either a static or typical instantiate call.

### Create a Query

[](#create-a-query)

To create a simple query (here querying a `device_list` and retrieve `id` and `name` of each device) you have three ways:

```
use Cis\GqlBuilder\Query;

$query = new Query('device_list');
$query->setSelectionSet(['id', 'name']);

// or in one line:
$query = (new Query('device_list'))->setSelectionSet(['id', 'name']);

// or as a static Call:
$query = Query::create(name: 'device_list', selectionSet: ['id', 'name']);

// This is not part of the library
$graphQlClient->sendRequest(['query' => (string)$query]);
```

The example above will create the following query:

```
query{device_list{id name}}

```

If you set the Pretty-Flag:

```
use Cis\GqlBuilder\Query;
$query = Query::create('device_list', selectionSet: ['id', 'name'])->setOutputFlags(Query::QUERY_PRETTY_PRINT);
```

The query will have a pretty output:

```
query {
    device_list {
        id
        name
    }
}

```

Please keep in mind that these examples are the easiest implementation that it is possible and the "global" query will only be set if scalar fields are within the Selection-Set.

The clean and correct way (and also a more complex example) will be the generation of an "empty" root-query and define all Queries within the selection set:

```
use Cis\GqlBuilder\Query;
use Cis\GqlBuilder\Parts\Argument;
use Cis\GqlBuilder\Parts\Variable;
use Cis\GqlBuilder\Enums\VariableTypes;

$query = (new Query())->setSelectionSet([
    (new Query('device_list'))
        ->setSelectionSet([
            'id',
            'name',
            (new Query('interfaces'))->setSelectionSet(['id', 'name']),
        ])
        ->setArguments([
            new Argument('filters', [
                'name' => ['i_starts_with' => '$name'],
                'has_primary_ip' => true
            ], isQueryType: true),
        ]),
])->setVariables([
    new Variable('name', VariableTypes::String, true),
]);
```

The example above also includes Arguments for Filtering (here a more complex FilterQueryType) and using a Variable.

The following query (when set to Pretty Print) will be generated and is a real life example for a Strawberry GraphQL-Endpoint:

```
query ($name: String!) {
    device_list (filters: {name: {i_starts_with: $name},has_primary_ip: true}) {
        id
        name
        interfaces {
            id
            name
        }
    }
}

```

### Static Query-Builder

[](#static-query-builder)

Within a selection Set you generally can create a new Query with the following code:

```
use Cis\GqlBuilder\Query;

...
    (new Query('interfaces'))->setSelectionSet(['id', 'name'])
...
```

But you can also use a static build:

```
use Cis\GqlBuilder\Query;

...
    Query::query('interfaces', ['id', 'name'])
...
```

This is a short version and will return a new Query Instance.

Earlier we also have seen the ` Query::create(...$parameters)` statement. Another Advantage of this call is that Variables can be easily created as Arrays without the `new Variable(...$parameters)` statement.

For easier understanding the named parameter style of PHP8 is used:

```
use Cis\GqlBuilder\Query;
use Cis\GqlBuilder\Enums\VariableTypes;

$query = Query::create(
    name: 'device_list',
    selectionSet: [
        'id',
        'name',
        'status',
        Query::query(
            name: 'interfaces',
            selectionSet: ['id', 'name'],
            arguments: [
                ['filters', ['name' => ['exact' => '$name']], true]
            ]
        )
    ],
    variables: [
        ['name', VariableTypes::String, true]
    ]
);
```

###  Health Score

33

—

LowBetter than 72% of packages

Maintenance60

Regular maintenance activity

Popularity10

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity45

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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

Unknown

Total

1

Last Release

621d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/59171582?v=4)[cis-ks](/maintainers/cis-ks)[@cis-ks](https://github.com/cis-ks)

---

Top Contributors

[![cis-ks](https://avatars.githubusercontent.com/u/59171582?v=4)](https://github.com/cis-ks "cis-ks (3 commits)")

### Embed Badge

![Health badge](/badges/cis-bv-gql-builder/health.svg)

```
[![Health](https://phpackages.com/badges/cis-bv-gql-builder/health.svg)](https://phpackages.com/packages/cis-bv-gql-builder)
```

###  Alternatives

[exsyst/swagger

A php library to manipulate Swagger specifications

35916.4M7](/packages/exsyst-swagger)[hubspot/api-client

Hubspot API client

24016.2M20](/packages/hubspot-api-client)[pocketmine/bedrock-protocol

An implementation of the Minecraft: Bedrock Edition protocol in PHP

172445.0k15](/packages/pocketmine-bedrock-protocol)[botman/driver-telegram

Telegram driver for BotMan

93459.5k6](/packages/botman-driver-telegram)

PHPackages © 2026

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