PHPackages                             99designs/graphql-bundle - 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. 99designs/graphql-bundle

ActiveLibrary[API Development](/categories/api)

99designs/graphql-bundle
========================

Symfony GraphQl Bundle

v1.0.1(2y ago)14.5k↓100%1[1 PRs](https://github.com/99designs/GraphQLBundle/pulls)MITPHPPHP &gt;=5.6

Since Aug 15Pushed 1y agoCompare

[ Source](https://github.com/99designs/GraphQLBundle)[ Packagist](https://packagist.org/packages/99designs/graphql-bundle)[ RSS](/packages/99designs-graphql-bundle/feed)WikiDiscussions master Synced 1mo ago

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

Symfony GraphQl Bundle
======================

[](#symfony-graphql-bundle)

### This is a bundle based on the pure [PHP GraphQL Server](http://github.com/youshido/graphql/) implementation

[](#this-is-a-bundle-based-on-the-pure-php-graphql-server-implementation)

This bundle provides you with:

- Full compatibility with the [RFC Specification for GraphQL](https://facebook.github.io/graphql/)
- Agile object oriented structure to architect your GraphQL Schema
- Intuitive Type system that allows you to build your project much faster and stay consistent
- Built-in validation for the GraphQL Schema you develop
- Well documented classes with a lot of examples
- Automatically created endpoint /graphql to handle requests

**There are simple demo application to demonstrate how we build our API, see [GraphQLDemoApp](https://github.com/Youshido/GraphQLDemoApp).**

Table of Contents
-----------------

[](#table-of-contents)

- [Installation](#installation)
- [Symfony features included](#symfony-features-included)
    - [AbstractContainerAwareField class](#class-abstractcontainerawarefield)
    - [Service method as callable](#service-method-as-callable)
    - [Security](#security)
- [Documentation](#documentation)

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

[](#installation)

We assume you have `composer`, if you're not – install it from the [official website](https://getcomposer.org/doc/00-intro.md#installation-linux-unix-osx).
If you need any help installing Symfony framework – here's the link .

> Shortcut to install Symfony: `composer create-project symfony/framework-standard-edition my_project_name`

Once you have your composer up and running – you're ready to install the GraphQL Bundle.
Go to your project folder and run:

```
composer require youshido/graphql-bundle
```

Then enable bundle in your `app/AppKernel.php`

```
new Youshido\GraphQLBundle\GraphQLBundle(),
```

Add the routing reference to the `app/config/routing.yml`:

```
graphql:
    resource: "@GraphQLBundle/Controller/"
```

or

```
graphql:
    resource: "@GraphQLBundle/Resources/config/route.xml"
```

If you don't have a web server configured you can use a bundled version, simply run `php bin/console server:run`.

Let's check if you've done everything right so far – try to access url `localhost:8000/graphql`.
You should get a JSON response with the following error:

```
{"errors":[{"message":"Schema class does not exist"}]}
```

That's because there was no GraphQL Schema specified for the processor yet. You need to create a GraphQL Schema class and set it inside your `app/config/config.yml` file.

> There is a way where you can use inline approach and do not create a Schema class, in order to do that you have to define your own GraphQL controller and use a `->setSchema` method of the processor to set the Schema.

The fastest way to create a Schema class is to use a generator shipped with this bundle:

```
php bin/console graphql:configure AppBundle
```

Here *AppBundle* is a name of the bundle where the class will be generated in.
You will be requested for a confirmation to create a class.

After you've added parameters to the config file, try to access the following link in the browser – `http://localhost:8000/graphql?query={hello(name:World)}`

> Alternatively, you can execute the same request using CURL client in your console
> `curl http://localhost:8000/graphql --data "query={ hello(name: \"World\") }"`

Successful response from a test Schema will be displayed:

```
{"data":{"hello":"world!"}}
```

That means you have GraphQL Bundle for the Symfony Framework configured and now can architect your GraphQL Schema:

Next step would be to link assets for GraphiQL Explorer by executing:

```
php bin/console assets:install --symlink
```

Now you can access it at `http://localhost:8000/graphql/explorer`

Symfony features
----------------

[](#symfony-features)

### Class AbstractContainerAwareField:

[](#class-abstractcontainerawarefield)

AbstractContainerAwareField class used for auto passing container to field, add ability to use container in resolve function:

```
class RootDirField extends AbstractContainerAwareField
{

    /**
     * @inheritdoc
     */
    public function getType()
    {
        return new StringType();
    }

    /**
     * @inheritdoc
     */
    public function resolve($value, array $args, ResolveInfo $info)
    {
        return $this->container->getParameter('kernel.root_dir');
    }

    /**
     * @inheritdoc
     */
    public function getName()
    {
        return 'rootDir';
    }
```

### Service method as callable:

[](#service-method-as-callable)

Ability to pass service method as resolve callable:

```
$config->addField(new Field([
    'name'    => 'cacheDir',
    'type'    => new StringType(),
    'resolve' => ['@resolve_service', 'getCacheDir']
]))
```

### Events:

[](#events)

You can use the Symfony Event Dispatcher to get control over specific events which happen when resolving graphql queries.

```
namespace ...\...\..;

use Youshido\GraphQL\Event\ResolveEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

class MyGraphQLResolveEventSubscriber implements EventSubscriberInterface
{
    public static function getSubscribedEvents()
    {
        return [
            'graphql.pre_resolve'  => 'onPreResolve',
            'graphql.post_resolve' => 'onPostResolve'
        ];
    }

    public function onPreResolve(ResolveEvent $event)
    {
		//$event->getFields / $event->getAstFields()..
    }

    public function onPostResolve(ResolveEvent $event)
    {
		//$event->getFields / $event->getAstFields()..
    }
}
```

#### Configuration

[](#configuration)

Now configure you subscriber so events will be caught. This can be done in Symfony by either XML, Yaml or PHP.

```

```

### Security:

[](#security)

Bundle provides two ways to guard your application: using black/white operation list or using security voter.

#### Black/white list

[](#blackwhite-list)

Used to guard some root operations. To enable it you need to write following in your config.yml file:

```
graphql:

  #...

  security:
    black_list: ['hello'] # or white_list: ['hello']
```

#### Using security voter:

[](#using-security-voter)

Used to guard any field resolve and support two types of guards: root operation and any other field resolving (including internal fields, scalar type fields, root operations). To guard root operation with your specified logic you need to enable it in configuration and use `SecurityManagerInterface::RESOLVE_ROOT_OPERATION_ATTRIBUTE` attribute. The same things need to do to enable field guard, but in this case use `SecurityManagerInterface::RESOLVE_FIELD_ATTRIBUTE` attribute. [Official documentation](http://symfony.com/doc/current/security/voters.html) about voters.

> Note: Enabling field security lead to a significant reduction in performance

Config example:

```
graphql:
    security:
        guard:
            field: true # for any field security
            operation: true # for root level security
```

Voter example (add in to your `services.yml` file with tag `security.voter`):

```
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
use Youshido\GraphQL\Execution\ResolveInfo;
use Youshido\GraphQLBundle\Security\Manager\SecurityManagerInterface;

class GraphQLVoter extends Voter
{

    /**
     * @inheritdoc
     */
    protected function supports($attribute, $subject)
    {
        return in_array($attribute, [SecurityManagerInterface::RESOLVE_FIELD_ATTRIBUTE, SecurityManagerInterface::RESOLVE_ROOT_OPERATION_ATTRIBUTE]);
    }

    /**
     * @inheritdoc
     */
    protected function voteOnAttribute($attribute, $subject, TokenInterface $token)
    {
        // your own validation logic here

        if (SecurityManagerInterface::RESOLVE_FIELD_ATTRIBUTE == $attribute) {
            /** @var $subject ResolveInfo */
            if ($subject->getField()->getName() == 'hello') {
                return false;
            }

            return true;
        } elseif (SecurityManagerInterface::RESOLVE_ROOT_OPERATION_ATTRIBUTE == $attribute) {
            /** @var $subject Query */
            if ($subject->getName() == '__schema') {
                return true;
            }
        }
    }
}
```

GraphiQL extension:
-------------------

[](#graphiql-extension)

To run [graphiql extension](https://github.com/graphql/graphiql) just try to access to `http://your_domain/graphql/explorer`

Documentation
-------------

[](#documentation)

All detailed documentation is available on the main GraphQL repository – .

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance28

Infrequent updates — may be unmaintained

Popularity22

Limited adoption so far

Community21

Small or concentrated contributor base

Maturity40

Maturing project, gaining track record

 Bus Factor2

2 contributors hold 50%+ of commits

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 ~0 days

Total

2

Last Release

1006d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/61d94165c13417941a32d14d4468f27868c7643e96495090cfd33009055ea48c?d=identicon)[mtibben](/maintainers/mtibben)

![](https://www.gravatar.com/avatar/077206ec25224ef22d3151c8d6803444c5a0dfb5c9977d8e28d1da3c51ae0534?d=identicon)[sinamt](/maintainers/sinamt)

![](https://www.gravatar.com/avatar/9774882060edf784e5983eabb3d1d9bf2b0517773afd641696d1c56e18a78ad1?d=identicon)[navitronic](/maintainers/navitronic)

---

Top Contributors

[![portey](https://avatars.githubusercontent.com/u/1961696?v=4)](https://github.com/portey "portey (94 commits)")[![viniychuk](https://avatars.githubusercontent.com/u/1412341?v=4)](https://github.com/viniychuk "viniychuk (59 commits)")[![sinamt](https://avatars.githubusercontent.com/u/29794?v=4)](https://github.com/sinamt "sinamt (9 commits)")[![pdziok](https://avatars.githubusercontent.com/u/9324392?v=4)](https://github.com/pdziok "pdziok (4 commits)")[![keesschepers](https://avatars.githubusercontent.com/u/915930?v=4)](https://github.com/keesschepers "keesschepers (4 commits)")[![iainmckay](https://avatars.githubusercontent.com/u/1223726?v=4)](https://github.com/iainmckay "iainmckay (4 commits)")[![mrexclamation](https://avatars.githubusercontent.com/u/3123405?v=4)](https://github.com/mrexclamation "mrexclamation (3 commits)")[![symm](https://avatars.githubusercontent.com/u/69390?v=4)](https://github.com/symm "symm (2 commits)")[![florentdestremau](https://avatars.githubusercontent.com/u/2852204?v=4)](https://github.com/florentdestremau "florentdestremau (2 commits)")[![mickaelvieira](https://avatars.githubusercontent.com/u/3251585?v=4)](https://github.com/mickaelvieira "mickaelvieira (1 commits)")[![mloureiro](https://avatars.githubusercontent.com/u/3427665?v=4)](https://github.com/mloureiro "mloureiro (1 commits)")[![m-naw](https://avatars.githubusercontent.com/u/1231338?v=4)](https://github.com/m-naw "m-naw (1 commits)")[![paaacman](https://avatars.githubusercontent.com/u/314534?v=4)](https://github.com/paaacman "paaacman (1 commits)")[![sebastienva](https://avatars.githubusercontent.com/u/4148039?v=4)](https://github.com/sebastienva "sebastienva (1 commits)")[![MGDSoft](https://avatars.githubusercontent.com/u/3816465?v=4)](https://github.com/MGDSoft "MGDSoft (1 commits)")[![dkreuer](https://avatars.githubusercontent.com/u/461576?v=4)](https://github.com/dkreuer "dkreuer (1 commits)")[![eliecharra](https://avatars.githubusercontent.com/u/6154987?v=4)](https://github.com/eliecharra "eliecharra (1 commits)")[![elvismdev](https://avatars.githubusercontent.com/u/3847077?v=4)](https://github.com/elvismdev "elvismdev (1 commits)")[![i-melnichenko](https://avatars.githubusercontent.com/u/5779974?v=4)](https://github.com/i-melnichenko "i-melnichenko (1 commits)")[![JeremyGreaux](https://avatars.githubusercontent.com/u/1903212?v=4)](https://github.com/JeremyGreaux "JeremyGreaux (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/99designs-graphql-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/99designs-graphql-bundle/health.svg)](https://phpackages.com/packages/99designs-graphql-bundle)
```

###  Alternatives

[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M651](/packages/sylius-sylius)[cravler/maxmind-geoip-bundle

Bundle integrating MaxMind GeoIP2 database into symfony application

27615.8k2](/packages/cravler-maxmind-geoip-bundle)[sulu/headless-bundle

Bundle that provides controllers and services for using Sulu as headless content management system

55133.7k2](/packages/sulu-headless-bundle)

PHPackages © 2026

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