PHP code example of bowens-h / laravel-graphql-extend
1. Go to this page and download the library: Download bowens-h/laravel-graphql-extend 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/ */
bowens-h / laravel-graphql-extend example snippets
BowensH\LaravelGraphQLExtend\ServiceProvider::class,
php artisan make:graphql:column TestColumn --table=test --force
public function columns()
{
return [
'test' => [
'name' => [
'type' => Type::string(),
'description' => '类型',
]
],
'description' => '测试',
];
}
public function columns()
{
return [
'test' => [
[//数组类型
'name' => [
'type' => Type::string(),
'description' => '类型',
]
]
],
'description' => '测试',
];
}
php artisan make:graphql:type TestType --table=test --force
Column::make(TestColumn::class, true);
Column::make(TestColumn::class)
->append([
'test' => [
'type' => Type:int(),
'description' => '描述'
]
]);
//支持字符串与数组
Column::make(TestColumn::class, true)->only(['id'])
Column::make(TestColumn::class, true)->only('id')
//支持字符串与数组
Column::make(TestColumn::class, true)->except(['id'])
Column::make(TestColumn::class, true)->except('id')
//支持字符串与数组
Column::make(TestColumn::class, true)->nonNull(['title'])
Column::make(TestColumn::class, true)->nonNull('title')
namespace App\GraphQL\Type\Clothes;
use App\GraphQL\Columns\TestColumn;
use BowensH\LaravelGraphQLExtend\Column;
use Folklore\GraphQL\Support\Type as BaseType;
class TestType extends BaseType
{
protected $inputObject = true;
protected $attributes = [
'name' => 'TestType',
'description' => '测试'
];
public function fields()
{
return Column::make(TestColumn::class, true) // 根据 ClothesColumn 生成 Column 实例
->nonNull(['title']) // 可选,配置 title 字段为 nonNull
->except(['id']) // 可选,排除 id 字段
->result(); // 返回最终结果
}
}
bash
$ php artisan vendor:publish --provider="BowensH\LaravelGraphQLExtend\ServiceProvider"
config/graphql_extend.php
bash
$ php artisan vendor:publish --provider="BowensH\LaravelGraphQLExtend\ServiceProvider"
config/graphql_extend.php