brausepulver/laravel-eloquent-to-graphql
Composer 安装命令:
composer require brausepulver/laravel-eloquent-to-graphql
包简介
Automatically turn Eloquent models into GraphQL
README 文档
README
This package generates a static GraphQL schema from your Eloquent models.
It is suggested to be used with lighthouse.
Setup
- Install the package:
composer require --dev brausepulver/laravel-eloquent-to-graphql
- Type-hint your models' relationships:
use Illuminate\Database\Eloquent\Relations\HasMany; class User extends Model { public function cuteCats(): HasMany { ... } }
- (Optional) Publish the configuration file:
php artisan vendor:publish --tag="eloquent_to_graphql.config"
Usage
php artisan e2gql
This will generate a schema for all your models in a single file at graphql/generated.graphql.
There are several options for customizing the way the schema is generated. Please have a look at them with
php artisan e2gql --help.
Configuration
Automatic Updates
To automatically update the schema every time one of your Eloquent models changes, you can register the command in your IDE of choice with the --force option, which disables all prompts.
If you are using VSCode, this can be achieved using the Run on Save extension. After installing the extension, you can add the following to .vscode/settings.json:
"emeraldwalk.runonsave": { "commands": [ { "match": "app/Models/.*\\.php", "isAsync": true, "cmd": "php artisan e2gql --force" } ] }
With standard project structure, this will update your schema every time an Eloquent model changes.
Custom Type Mappings
If your tables have columns with types unknown to DBAL, the command will let you know. In this case, you have two options:
- Let the command know which type that is known by DBAL you would like to map the unkown type to. You can do this by adding both to
custom_type_mappingsinconfig/eloquent_to_graphql.php:
'custom_type_mappings' => [ 'from-type' => 'to-type' ]
- Ignore the columns entirely using the
--exclude-columnsoption. You can then later add them by hand.
TODO
- Option to automatically update the schema after migrations are run
- Way to keep changes made by the user when regenerating a schema
- More customizable type resolution
brausepulver/laravel-eloquent-to-graphql 适用场景与选型建议
brausepulver/laravel-eloquent-to-graphql 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 344 次下载、GitHub Stars 达 3, 最近一次更新时间为 2022 年 03 月 31 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 brausepulver/laravel-eloquent-to-graphql 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 brausepulver/laravel-eloquent-to-graphql 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 344
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 7
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-03-31