1. Go to this page and download the library: Download pomelchenko/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\graphql\GraphQLModule
{
}
'modules'=>[
'moduleName ' => [
'class' => 'path\to\module'
//graphql config
'schema' => [
'query' => [
'user' => \app\graphql\query\UsersQuery::class
],
'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
],
],
],
];
class MyController extends Controller
{
function actions()
{
return [
'index' => [
'class' => \yii\graphql\GraphQLAction::class,
],
];
}
}
'components' => [
'componentsName' => [
'class' => 'path\to\components'
//graphql config
'schema' => [
'query' => [
'user' => \app\graphql\query\UsersQuery::class
],
'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,
],
],
],
];
public function rules()
{
return [
['password', 'boolean'],
];
}
use yii\graphql\base\GraphQLMutation;
use GraphQL\Type\Definition\Type;
class UpdatePasswordMutation extends GraphQLMutation
{
public function type()
{
return Type::boolean();
}
public function args()
{
return [
'password' => ['type' => Type::nonNull(Type::string())],
];
}
public function rules()
{
return [
['password', 'string', 'min' => 12],
];
}
public function resolve($root, $args)
{
// Arguments are already validated here.
// ...
return true;
}
}