1. Go to this page and download the library: Download virtualwonders/yii2-graphql 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/ */
class MyModule extends \yii\base\Module
{
use \yii\graphql\GraphQLModuleTrait;
}
'modules'=>[
'moduleName ' => [
'class' => 'path\to\module'
//graphql config
'schema' => [
'query' => [
'user' => 'app\graphql\query\UsersQuery'
],
'mutation' => [
'login'
],
// you do not need to set the types if your query contains interfaces or fragments
// the key must same as your defined class
'types' => [
'Story' => 'yiiunit\extensions\graphql\objects\types\StoryType'
],
],
],
];
class MyController extends Controller
{
function actions() {
return [
'index'=>[
'class'=>'yii\graphql\GraphQLAction'
],
];
}
}
'components'=>[
'componentsName' => [
'class' => 'path\to\components'
//graphql config
'schema' => [
'query' => [
'user' => 'app\graphql\query\UsersQuery'
],
'mutation' => [
'login'
],
// you do not need to set the types if your query contains interfaces or fragments
// the key must same as your defined class
'types'=>[
'Story'=>'yiiunit\extensions\graphql\objects\types\StoryType'
],
],
],
];
public function rules() {
return [
['password','boolean']
];
}