国内/app-library

v0.13.0 2024-03-20 05:04 UTC

README

认证

GraphQL

在您的 App 命名空间中,创建以下目录结构

- GraphQL
    - Input
    - Mutation
        - Operation
        - Output
    - Object
    - Query
        - Operation
        - Output

然后添加以下文件 App\GraphQL\Mutation\MutationType

<?php
declare(strict_types=1);

namespace App\GraphQL\Mutation;

use App\GraphQL\Mutation\Operation\UpdateSomethingMutation;
use GraphQL\Type\Definition\ObjectType;

final class MutationType extends ObjectType
{
    public function __construct()
    {
        parent::__construct(
            [
                'name'   => 'Mutation',
                'fields' => [
                    'updateSomething' => new UpdateSomethingMutation(),
                ],
            ]
        );
    }
}

App\GraphQL\Mutation\QueryType

<?php
declare(strict_types=1);

namespace App\GraphQL\Query;

use App\GraphQL\Query\Operation\PingQuery;
use GraphQL\Type\Definition\ObjectType;

final class QueryType extends ObjectType
{
    public function __construct()
    {
        parent::__construct(
            [
                'name'   => 'Query',
                'fields' => [
                    'ping'                    => new PingQuery(),
                ],
            ],
        );
    }
}

App\GraphQL\Type\GraphQLType

<?php
declare(strict_types=1);

namespace App\GraphQL\Type;

use App\GraphQL\Type;

final class GraphQLType extends Type
{

}

添加

    public static function userInfo()
    {
        return self::$userInfo ?: (self::$userInfo = new UserInfoObject());
    }

分页

GraphQL

存在一个 Paginate 输入(paginate 是动词)和一个 Pagination 输出(pagination 是名词)。

输入和输出设置为与 React Virtualized Infinite Loader 一起工作