PHP code example of andyharis / yii2apigql

1. Go to this page and download the library: Download andyharis/yii2apigql library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

andyharis / yii2apigql example snippets


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

// main.php
'components' => [
   'gql' => [
     'class' => "andyharis\yii2apigql\Bootstrap",
     'relations' => 

// 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;

// 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