下記ライブラリを利用
https://github.com/nuwave/lighthouse
playgroundで動作確認
https://localhost/graphql-playground
公式マニュアル:
https://lighthouse-php.com
query {
TQuery(first:10, page:1) {
data{
title
genre
writer
}
paginatorInfo{
total
}
}
}
src/graphql/schema.graphql
type Query {
TQuery: [Test!]! @paginate(builder: "App\\GraphQL\\Queries\\TestQuery")
}
type Test {
title: String
writer: String
genre: Int
}
namespace App\GraphQL\Queries;
use Illuminate\Support\Facades\DB;
class TestQuery
{
public function __invoke($_, array $args)
{
return DB::table('test1')
->join('test2',[['test1.id', '=', 'test2.test1_id']])
->orderBy('test2.created_at', 'asc');
}
}
app/GraphQL/Queries/xxx.php
namespace App\GraphQL\Queries;
class xxx
{
public function __invoke($_, array $args)
{
return $this;
}
public function test()
{
return 1111;
}
}
graphql/schema.graphql
type Query {
xxx: xxx
}
type xxx {
test: Int @method
}