PHPackages                             andyharis/yii2apigql - 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. andyharis/yii2apigql

ActiveYii2-extension

andyharis/yii2apigql
====================

Yii2 API gql

0.2.5(7y ago)0371MITPHP

Since Jul 31Pushed 7y ago1 watchersCompare

[ Source](https://github.com/andyharis/yii2-apigql)[ Packagist](https://packagist.org/packages/andyharis/yii2apigql)[ RSS](/packages/andyharis-yii2apigql/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependenciesVersions (18)Used By (0)

andyharis/yii2-apigql
=====================

[](#andyharisyii2-apigql)

yii2-apigql provides methods to work with database on CRUD operations

Usage
-----

[](#usage)

[API docs](docs.md)

For example we have 3 table/models: Users, Messages, Post.

- `Users` -&gt; hasMany `Post`
- `Post` -&gt; hasMany `Messages`

We want to access clients with all messages including post:

```
{
  "username": "",
  "avatarUrl": "",
  "post": {
    "postName":"",
    "messages": {
      "textMessage": "",
      "dateAdded": ""
    }
  }
}
```

Make request and get all data with the same format you provided.

GET `/clients?select={"username": "","avatarUrl": "","post": {"postName": "","messages": {"textMessage": "","dateAdded": ""}}}`

```
// response
{
    "username": "Andyhar",
    "avatarUrl": "http://example.com/andyhar.png",
    "post": [
      {
        "postName": "Post about API",
        "dateAdded": "1500276204",
        "messages": [
          {
            "textMessage": "Hey what a nice post!",
            "dateAdded": "1500276704",
          },
          {
            "textMessage": "Make more posts like this!",
            "dateAdded": "1500279841",
          }
        ]
      },
    ]
  }
```

- Access main model and nested relations data with one query.
- Sort by nested relations:
    - `/clients?select={...}&sort=post.postName` - sort by `post.postName ASC`
    - `/clients?select={...}&sort=!post.messages.dateAdded` - sort by `post.messaged.dateAdded DESC`
- Filter data with nested conditions:
    - `/clients?select={"username":"=Andyhar"}` - where `username equals Andyhar`
    - `/clients?select={"post":{"messages":{"textMessage":"~Rocks"}}}` - where `post.messages.textMessage like Rocks`
    - `/clients?select={"post":{"likes":">35"}}` - where `post.likes > 35`

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

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/). Either run

```
composer require andyharis/yii2apigql

```

Getting started
---------------

[](#getting-started)

After installation you should enable this module extension in your config file:

1. Open your `frontend/config/main.php`
2. Add module `gql` to `bootstrap` section

```
// main.php
return [
  'id' => 'app-frontend',
  'basePath' => dirname(__DIR__),
  'bootstrap' => ['log', 'gql'],
   // your code
];
```

Then you need to initialize component itself. Just add new component `gql` to list of your components:

```
// main.php
'components' => [
   'gql' => [
     'class' => "andyharis\yii2apigql\Bootstrap",
     'relations' => require 'models.php'
    ],
    // your code
]
```

Creating file models.php
------------------------

[](#creating-file-modelsphp)

As you can see we `require 'models.php'` to let component know which models to use.

So you probably want create a separate file to store you models for this case.

```
// models.php
use andyharis\yii2apigql\components\api\Relations;
// Initializing component relations class which will handle dependencies
$object = new Relations();
// Add all models you need to work with
$object
  ->addModel(String $name, String $className)
  ...
  ...
  ->addModel('clients', \frontend\models\Clients::className())
  ->addModel('job', \frontend\models\Job::className());
// we need to return this object with relations
return $object;
```

Where:

- `clients` - indicates name for your model
- `\frontend\models\Clients::className()` - indicates what model should use to fetch and update data

Almost there
------------

[](#almost-there)

Another important thing is to extend all your models with `Yii2ApigqlRecord` component.

```
// frontend/models/Clients.php
namespace frontend\models;

use andyharis\yii2apigql\components\Yii2ApigqlRecord;
// This is important, because Yii2ApigqlRecord has some methods which use your models to make magic.
// Of course you can extend it with your class but don't forget to extend Yii2ApigqlRecord
class Clients extends Yii2ApigqlRecord
```

That's it. Now you can work with `yii2apigql`.

For more info please visit Wiki for API documentation.

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 96.4% 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 ~20 days

Recently: every ~71 days

Total

17

Last Release

2877d ago

Major Versions

0.1.1 → 1.0.0.x-dev2017-08-01

### Community

---

Top Contributors

[![andyharis](https://avatars.githubusercontent.com/u/16936196?v=4)](https://github.com/andyharis "andyharis (27 commits)")[![AnnOrl](https://avatars.githubusercontent.com/u/30530193?v=4)](https://github.com/AnnOrl "AnnOrl (1 commits)")

### Embed Badge

![Health badge](/badges/andyharis-yii2apigql/health.svg)

```
[![Health](https://phpackages.com/badges/andyharis-yii2apigql/health.svg)](https://phpackages.com/packages/andyharis-yii2apigql)
```

PHPackages © 2026

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