ecodev/graphql-upload
Composer 安装命令:
composer require ecodev/graphql-upload
包简介
A middleware to support file uploads in GraphQL
README 文档
README
A PSR-15 middleware to support file uploads in GraphQL. It implements the multipart request specification for webonyx/graphql-php.
Quick start
Install the library via composer:
composer require ecodev/graphql-upload
Configure as middleware
In Laminas Mezzio, it would typically be in config/routes.php something like:
use Application\Action\GraphQLAction; use Mezzio\Helper\BodyParams\BodyParamsMiddleware; use GraphQL\Upload\UploadMiddleware; $app->post('/graphql', [ BodyParamsMiddleware::class, UploadMiddleware::class, // This is the magic GraphQLAction::class, ], 'graphql');
Other frameworks
This lib is an implementation of PSR-15, so it can be used with any framework supporting PSR-15. For specific configuration instructions, refer to your framework documentation.
If your framework does not support PSR-15 middleware, you will probably need some kind of bridge. Again, refer to your framework for specific instructions.
Usage in schema
Then you can start using in your mutations like so:
<?php use GraphQL\Type\Definition\ObjectType; use GraphQL\Type\Definition\Type; use GraphQL\Type\Schema; use GraphQL\Upload\UploadType; use Psr\Http\Message\UploadedFileInterface; // Build your Schema $schema = new Schema([ 'query' => new ObjectType([ 'name' => 'Query', 'fields' => [], ]), 'mutation' => new ObjectType([ 'name' => 'Mutation', 'fields' => [ 'testUpload' => [ 'type' => Type::string(), 'args' => [ 'text' => Type::string(), 'file' => new UploadType(), ], 'resolve' => function ($root, array $args): string { /** @var UploadedFileInterface $file */ $file = $args['file']; // Do something with the file $file->moveTo('some/folder/in/my/project'); return 'Uploaded file was ' . $file->getClientFilename() . ' (' . $file->getClientMediaType() . ') with description: ' . $args['text']; }, ], ], ]), ]);
Limitations
- It only works with PSR-7 requests. If you were not using PSR-7 yet, laminas-diactoros is one of many implementation that could be used to create PSR-7 requests.
ecodev/graphql-upload 适用场景与选型建议
ecodev/graphql-upload 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.26M 次下载、GitHub Stars 达 90, 最近一次更新时间为 2018 年 01 月 05 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「api」 「upload」 「middleware」 「multipart」 「graphql」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 ecodev/graphql-upload 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ecodev/graphql-upload 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 ecodev/graphql-upload 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Shoot aims to make providing data to your templates more manageable
The file manager intended for using Laravel with CKEditor / TinyMCE / Colorbox
A PSR-7 compatible library for making CRUD API endpoints
Laravel Media Popup to upload/view the files
Slim Framework 3 CSRF protection middleware utilities
Cloudflare Middleware For Guzzle
统计信息
- 总下载量: 2.26M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 90
- 点击次数: 17
- 依赖项目数: 13
- 推荐数: 2
其他信息
- 授权协议: MIT
- 更新时间: 2018-01-05