t3n/graphql-upload
最新稳定版本:2.1.0
Composer 安装命令:
composer require t3n/graphql-upload
包简介
Extension for t3n/graphql that implements upload-handling
README 文档
README
Warning
This plugin is no longer being maintained and there is no superseding package at this time
t3n.GraphQL.Upload
Sidecar package for t3n/graphql that brings an Upload scalar and enables you to handle file uploads in your schema.
Simply install the package via composer:
composer require t3n/graphql-upload
Configuration
This package ships all needed parts. However, you must add the typeDefs and the Resolver to your schema like this:
t3n: GraphQL: endpoints: 'your-endpoint': #use your endpoint variable here schemas: upload: typeDefs: 'resource://t3n.GraphQL.Upload/Private/GraphQL/schema.upload.graphql' resolvers: Upload: 't3n\GraphQL\Upload\Resolver\Type\UploadResolver'
This is everything you need to do. Once configured you can use the Upload scalar in your app.
Usage
To use the Upload scalar you might want to add it as an arg to a mutation like this:
type Mutation { uploadFile(file: Upload): String }
This package will handle the upload itself and pass an Neos\Http\Factories\FlowUploadedFile to your MutationResolver. Within your resolver method your could for instance import your resource:
class MutationResolver implements ResolverInterface { /** * @Flow\Inject * * @var ResourceManager */ protected $resourceManager; public function uploadFile($_, $variables): string { /** @var FlowUploadedFile $file */ $file = $variables['file']; $resource = $this->resourceManager->importResource($file->getStream()->detach()); $resource->setFilename($file->getClientFilename()); $resource->setMediaType($file->getClientMediaType()); return $file->getClientFilename(); } }
Some notes
To actually use file upload your frontend client must use multipart/form-data in your forms. This Package is tested with a react app that uses https://github.com/jaydenseric/apollo-upload-client
统计信息
- 总下载量: 86.56k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2020-06-17