A Laravel GraphQL reference implementation forked from webonyx/graphql-php
johnlui/graphql-laravel is a Laravel package for a laravel graphql reference implementation forked from webonyx/graphql-php.
It currently has 3 GitHub stars and 18 downloads on Packagist (latest version v1.5.1).
Install it with composer require johnlui/graphql-laravel.
Discover more Laravel packages by johnlui
or browse all Laravel packages to compare alternatives.
Last updated
webonyx/graphql-php 的 Laravel 适配,魔改原库,将其彻底融入 Laravel 生命周期。
cc()composer require johnlui/graphql-laravel
php artisan vendor:publish
app\GraphApp为工作文件夹Routes.php为路由文件QueryFields目录存放响应代码Types目录存放自定义类型config/graphql.php为配置文件
query ($id: Int) {
foo(id: $id) {
id
foo
bar
}
}
此处为 JSON 格式描述,开发时应使用 key-value 形式描述 variables,不应该使用 JSON 字符串。
{
"id": 200
}
php artisan serve
http://127.0.0.1:8000/graphql
修改默认路径请编辑config/graphql.php中的apiUri。
curl --location --request POST 'http://127.0.0.1:8000/graphql' \
--header 'Content-Type: application/json' \
--data-raw '{"query":"query($id: Int) {\n foo(id: $id) {\n id\n foo\n bar\n }\n}","variables":{"id":200}}'
{
"status": 0,
"message": "OK",
"values": {
"foo": {
"id": 200,
"foo": "foo",
"bar": "bar"
},
"queries": []
}
}
The johnlui/GraphQL-Laravel is open-sourced software licensed under the MIT license