定制 gency/laravel-graphql-filter 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

gency/laravel-graphql-filter

Composer 安装命令:

composer require gency/laravel-graphql-filter

包简介

Define GraphQL schema for connection filtering using Laravel filterable models

README 文档

README

Define GraphQL schema for connection filtering using Laravel filterable models.

Installation

composer require gency/laravel-graphql-filter

Usage

Use Filterable trait on Model

namespace App;
use Gency\Filterable\Filterable;

class User extends Model
{
  use \Gency\Filterable\FilterableTrait;
  
  protected $filterable = [
    'name' => Filterable::String
  ];
}

Create GraphQL User type

namespace App\GraphQL\Type;

use App\User;
use GraphQL\Type\Definition\Type;
use Folklore\GraphQL\Support\Type as GraphQLType;

class User extends GraphQLType
{
  protected $attributes = [
    'name' => 'User'
  ];
  public function fields() {
    return [
      'id' => [
        'type' => Type::id(),
      ],
      'name' => [
        'type' => Type::string()
      ]
    ]
  }
}

Create GraphQL UserFilter type. The UserFilter fields defintion will be automatically populated with fields in User::$filterable.

namespace App\GraphQL\Type;

use App\User;
use Gency\GraphQLFilter\Type\FilterType;

class UserFilter extends FilterType
{
  protected $model = User::class;
}

Create GraphQL query type to list User records using the User model's filterable settings.

namespace App\GraphQL\Type;

use App\User;
use GraphQL;
use GraphQL\Type\Definition\Type;
use Folklore\GraphQL\Support\Query;

class UsersQuery extends Query
{
  protected $attributes = [
    'name' => 'users'
  ];
  public function type() {
    return Type::listOf(GraphQL::type('User'));
  }
  public function args() {
    return [
      'filter' => [
        'type' => GraphQL::type('UserFilter')
      ]
    ];
  }
  public function resolve($root, $args, $context) {
    return User::filter($args['filter'])->orderBy('name')->limit(10)->get();
  }
}

A GraphQL query can now use the Filterable::String rules to perform searches.

query ListJohns {
  users (filter: { name_MATCH: 'john' }) {
    name
  }
}

统计信息

  • 总下载量: 437
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 4
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-06-21

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固