PHPackages                             phps-cans/harmony-graphql-tool - 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. phps-cans/harmony-graphql-tool

ActiveLibrary[API Development](/categories/api)

phps-cans/harmony-graphql-tool
==============================

This package contains tools to be able to easily implement graphql in your application

v0.1.0(8y ago)923.2k1[1 PRs](https://github.com/phps-cans/harmony-graphql-tool/pulls)MITPHPPHP &gt;=5.5.0

Since Sep 13Pushed 8y ago4 watchersCompare

[ Source](https://github.com/phps-cans/harmony-graphql-tool)[ Packagist](https://packagist.org/packages/phps-cans/harmony-graphql-tool)[ Docs](https://github.com/phps-cans/harmony-graphql-tool)[ RSS](/packages/phps-cans-harmony-graphql-tool/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (3)Versions (2)Used By (0)

harmony-graphql-tool
====================

[](#harmony-graphql-tool)

This package try to make the using of [webonyx's Graphql implementation](https://github.com/webonyx/graphql-php) easyer when using [PSR 11's container](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-11-container.md). To be easyer you must use [ServiceProvider](https://github.com/container-interop/service-provider)

It provides :

- A Type Registry. This is intented to register Type and **not query**. What it does? It ask to the container if the Type asked by object is registered, else it use the Type name asked as a Classname (removing `Type` at the end of the Type asked if it exist). If the Type as a class using his name, it check if it implements `GraphqlTypeInterface`, if it does it use this type.
- `GraphqlQueryInterface`: All query's object should implements this interface to be able to be register into the schema
- `GraphqlTypeInterface`: All type's object should implements this interface to be discovered by the Type Registry
- `DefaultServiceProvider` : A service provider which create a graphql's server / a schema automatically

How to use
----------

[](#how-to-use)

### Using ServiceProvider

[](#using-serviceprovider)

You must register the identifier's name list of instance of your query object (implementing `\PsCs\Harmony\Graphql\Tool\GraphqlQueryInterface`) under the name ` PsCs\Harmony\Graphql\Tool\GraphqlQueryInterface`. By example:

- First define your TypeClass:

```
namespace Foo;

use GraphQL\Type\Definition\ObjectType;
use GraphQL\Type\Definition\Type;

class MyType implements \PsCs\Harmony\Graphql\Tool\GraphqlTypeInterface {
    public $id = "foo";
    public function getId() {
        return $this->id;
    }
    static public function resolveField(MyType $value, $args, $context, ResolveInfo $info)  {
        switch ($info->fieldName) {
            case 'id':
              return $bill->getId();
            default:
              return null;
        }
    }
    static public function getType($typeRegistry): ObjectType {
        return new ObjectType([
            "name" => "MyType",
            "fields" => [
                "id" => Type::nonNull(Type::id())
            ],
            "resolveField" => [self::class, "resolveField"]
        ]);
    }
  }
```

- Secondly, create your Query object:

```
namespace Foo;

use GraphQL\Type\Definition\ObjectType;
use GraphQL\Type\Definition\Type;
use GraphQL\Type\Definition\FieldDefinition;

class MyGraphqlQueryInterfaceImplementation extends MydataFinder implements \PsCs\Harmony\Graphql\Tool\GraphqlQueryInterface {

    public function getQueryField($typeRegistry): FieldDefinition {
        $that = $this;
        return FieldDefinition::create([
            "name" => "billPerYear",
            "type" => $typeRegistry->get((MyType::class)."Type"),
            'args'    => [
                'id' => Type::nonNull(Type::id())
            ],
            "resolve" => function($rootValue, $args) use ($that) {
                return $that->findOneById($args["id"]);
            }
        ]);
    }
  }
```

Alternatively, you can create an object which returns multiple query:

```
namespace Foo;

use GraphQL\Type\Definition\ObjectType;
use GraphQL\Type\Definition\Type;
use GraphQL\Type\Definition\FieldDefinition;

class MyGraphqlQueriesInterfaceImplementation extends MydataFinder implements \PsCs\Harmony\Graphql\Tool\GraphqlQueriesInterface {

    public function getQueryField($typeRegistry): array {
        $that = $this;
        return [FieldDefinition::create([
            "name" => "billPerYear",
            "type" => $typeRegistry->get((MyType::class)."Type"),
            'args'    => [
                'id' => Type::nonNull(Type::id())
            ],
            "resolve" => function($rootValue, $args) use ($that) {
                return $that->findOneById($args["id"]);
            }
        ])];
    }
  }
```

- Then create your serviceProvider

```
namespace Foo\ServiceProvider;

use Interop\Container\ServiceProvider;
use GraphQL\Type\Schema;

use Foo\MyGraphqlQueryInterfaceImplementation;
use Interop\Container\ContainerInterface as Container;

class Graphql implements ServiceProvider {
 public function getServices()
    {
        return [
            (MyGraphqlQueryInterfaceImplementation::class)."Type" => [self::class, 'getMyGraphqlQueryInterfaceImplementation'],
            (\PsCs\Harmony\Graphql\Tool\GraphqlQueryInterface::class) => [self::class, 'getGraphqlQueryQueue'],
        ]; // By convention
    }
    public static function getMyGraphqlQueryInterfaceImplementation(Container $container) {
        return new MyGraphqlQueryInterfaceImplementation();
    }

    public static function getGraphqlQueryQueue(Container $container) {
        return [
            (MyGraphqlQueryInterfaceImplementation::class)."Type"
        ];
    }
}
```

Then register service provider needed:

```
    $container = require_once("container.php");
    $container->register(new \PsCs\Harmony\Graphql\Tool\ServiceProvider\DefaultServiceProvider());
    $container->register(new \Foo\ServiceProvider\Graphql);
    $standardServer = $container->get(\GraphQL\Server\StandardServer::class);
    // ....
```

Without service provider
------------------------

[](#without-service-provider)

This package attempt to make easy the use of the library with service provider. If you do not use the service provider, this package cannot register automatically instances. You still can use the `Registry` class:

```
    $container = require_once("container.php");
    $registry = new \PsCs\Harmony\Graphql\Tool\Registry\Registry($container);
    $registry->get(MyTypeFoo::class);
    //...
```

TODO
----

[](#todo)

Implements type discovery using doctrine's annotation

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity30

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity48

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

3170d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/b1953426bdefad774b92f15505637dcf22e19f567acd596131d86ce40f738f2a?d=identicon)[Ngob](/maintainers/Ngob)

---

Top Contributors

[![Ngob](https://avatars.githubusercontent.com/u/2749238?v=4)](https://github.com/Ngob "Ngob (13 commits)")

---

Tags

graphqlserviceprovider

### Embed Badge

![Health badge](/badges/phps-cans-harmony-graphql-tool/health.svg)

```
[![Health](https://phpackages.com/badges/phps-cans-harmony-graphql-tool/health.svg)](https://phpackages.com/packages/phps-cans-harmony-graphql-tool)
```

###  Alternatives

[nuwave/lighthouse

A framework for serving GraphQL from Laravel

3.5k10.7M93](/packages/nuwave-lighthouse)[overblog/graphql-bundle

This bundle provides tools to build a GraphQL server in your Symfony App.

8027.9M28](/packages/overblog-graphql-bundle)[aimeos/ai-admin-graphql

Aimeos Admin GraphQL API extension

944100.0k4](/packages/aimeos-ai-admin-graphql)[mll-lab/graphql-php-scalars

A collection of custom scalar types for usage with https://github.com/webonyx/graphql-php

1394.2M28](/packages/mll-lab-graphql-php-scalars)[ivome/graphql-relay-php

A PHP port of GraphQL Relay reference implementation

271632.4k5](/packages/ivome-graphql-relay-php)[overblog/graphql-php-generator

GraphQL types generator

29518.9k](/packages/overblog-graphql-php-generator)

PHPackages © 2026

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