https://github.com/t3n/graphql-upload
Sidecar package for t3n/graphql that provides upload resolver
https://github.com/t3n/graphql-upload
flowframework flowpackage graphql neoscms php
Last synced: 5 months ago
JSON representation
Sidecar package for t3n/graphql that provides upload resolver
- Host: GitHub
- URL: https://github.com/t3n/graphql-upload
- Owner: t3n
- License: mit
- Created: 2020-06-16T21:21:17.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2022-04-05T12:19:16.000Z (almost 4 years ago)
- Last Synced: 2025-07-25T14:45:58.981Z (6 months ago)
- Topics: flowframework, flowpackage, graphql, neoscms, php
- Language: PHP
- Homepage:
- Size: 13.7 KB
- Stars: 2
- Watchers: 2
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
- License: LICENSE
Awesome Lists containing this project
README
# t3n.GraphQL.Upload
Sidecar package for [t3n/graphql](https://github.com/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:
```yaml
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:
```graphql
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:
```php
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