PHPackages                             d3mo17/colja - 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. d3mo17/colja

ActiveSymfony-bundle[API Development](/categories/api)

d3mo17/colja
============

Provides GraphQL functionality to symfony projects

0.10.0(4y ago)06mitPHPPHP &gt;=7.3

Since Apr 15Pushed 4y ago1 watchersCompare

[ Source](https://github.com/d3mo17/colja)[ Packagist](https://packagist.org/packages/d3mo17/colja)[ RSS](/packages/d3mo17-colja/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (13)Versions (5)Used By (0)

Colja
=====

[](#colja)

A Symfony bundle to provide GraphQL functionality (by the use of [Siler](https://github.com/leocavalcante/siler/)). Per default GraphQL requests (method POST) will be handled on request-uri `/graphql`.

Schema
------

[](#schema)

There has to be defined one basic schema file in GraphQL Schema Definition Language ([SDL](https://graphql.org/learn/schema/)). The path to this file has to be configured in the `d_mo_colja.yaml`-file (see [here](https://github.com/d3mo17/colja-examples/blob/master/config/packages/d_mo_colja.yaml#L2)).

The basic schema file can be extended by multiple more files (see [here](https://github.com/d3mo17/colja-examples/blob/master/config/packages/d_mo_colja.yaml#L11)).

To link a query or mutation (field) from the schema to a resolver callable in php you have to [configure a classname and a method with the specified fieldname](https://github.com/d3mo17/colja-examples/blob/master/config/packages/d_mo_colja.yaml#L4-L6)

Resolvers
---------

[](#resolvers)

A class which contains field resolvers, must extend the Class `DMo\Colja\GraphQL\AbstractResolver`. This is because the `ResolverManager` will be injected into each Resolver, so through this you will be able to get the symfony controller and container.

All Resolvers (callable functions) can be defined to expect four parameters:

- `$root`
- `$args`
- `$context`
- `$info`

The most important parameter is the second one: `$args`. It contains all arguments passed to a field.

Each Resolver can return a scalar value or an associative array. The array values can contain scalars or function references which act as field resolvers by themselves.

All field values which need to be "lazy-loaded" must be defined as resolver, because a resolver will only be called if the corresponding field was requested in a query. You can also realize recursive data structures with this technique (see [example here](https://github.com/d3mo17/colja-examples/blob/master/src/GraphQL/DemoEntityResolver.php#L16-L33)).

GET-Requests
------------

[](#get-requests)

By default this bundle only supports the request method POST. But you can easily add support for the method GET. Just place the following in the `routes.yaml` of your symfony project:

```
d_mo_colja_endpoint_get:
    path:       /graphql
    controller: DMo\Colja\Controller\GraphQLController::endpoint
    methods:    GET

```

Setup Example
-------------

[](#setup-example)

See also [Colja examples](https://github.com/d3mo17/colja-examples/) for more information

```
a-symfony-project/
├─ bin/
├─ config/
│  ├─ graphql/
│  │  ├─ base.schema
│  ├─ packages/
│  │  ├─ .../
│  │  ├─ d_mo_colja.yaml
│  │  ├─ ...
|  ├─ bundles.php
│  ├─ .../
├─ src/
│  ├─ Controller/
│  ├─ .../
│  ├─ GraphQL/
│  │  ├─ DemoResolver.php
│  │  ├─ ...
├─ ...
├─ composer.json

```

### base.schema

[](#baseschema)

```
type Query {
    demo: String,
    demoArgs(name: String!, num: Int): String
}
```

### d\_mo\_colja.yaml

[](#d_mo_coljayaml)

```
d_mo_colja:
  schema: config/graphql/base.schema
  query:
    demo:
      class: App\GraphQL\DemoResolver
      method: demo
    demoArgs:
      class: App\GraphQL\DemoResolver
      method: demoWithArguments
```

### bundles.php

[](#bundlesphp)

```
