PHPackages                             youshido/graphql-files-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [File &amp; Storage](/categories/file-storage)
4. /
5. youshido/graphql-files-bundle

ActiveSymfony-bundle[File &amp; Storage](/categories/file-storage)

youshido/graphql-files-bundle
=============================

Library to implement images and file upload to GraphQL API

v0.0.1(8y ago)44.6k[1 issues](https://github.com/Youshido/GraphQLFilesBundle/issues)MITPHPPHP &gt;=7.0.0

Since Aug 7Pushed 8y agoCompare

[ Source](https://github.com/Youshido/GraphQLFilesBundle)[ Packagist](https://packagist.org/packages/youshido/graphql-files-bundle)[ RSS](/packages/youshido-graphql-files-bundle/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (2)Used By (0)

GraphQL Files Bundle
====================

[](#graphql-files-bundle)

Symfony bundle for easy implementation images and files to your GraphQL API (bundle with GraphQL implementation and its documentation is [here](https://github.com/Youshido/GraphQLBundle)). Bundle provides `UploadImageMutation`:

```
mutation {
  uploadImage(field: "file") {
    id
    url
    fileName
    mimeType
    extension
    size
    resized(width: 100, height: 100, mode: INSET) {
      url
    }
  }
}
```

Mutation assumes that request content-type is `multipart/form-data` and include image data in field that is passed as argument `field`. Upload file mutation:

```
mutation {
  uploadFile(field: "file") {
    id
    url
    fileName
    mimeType
    extension
    size
  }
}
```

Also bundle provides `ImageField` to use in your API like this:

```
{
  me {
    id
    firstName
    lastName
    image { // image field from bundle
      url
      resized(width: 100, height: 100, mode: INSET) {
        url
      }
    }
  }
}
```

or you can add arguments directly to the image field for your convenience.

```
{
  me {
    id
    firstName
    lastName
    small: image(width: 100, height: 100, mode: INSET) { // resized directly
      url
    }
    medium: image(width: 500, height: 300, mode: OUTBOUND) { // different mode
      url
    }
    fullSize: image {
      url
    }
  }
}
```

How to use
----------

[](#how-to-use)

- [Installation](#1-installation)
- [Configuration](#2-configuration)
- [GraphQL schema set-up](#3-set-up-graphql-schema)
    - [Mutation type](#31-add-uploadimagemutation-to-your-mutationtype)
    - [Custom type](#32-add-image-field-to-your-type)

### 1. Installation:

[](#1-installation)

> composer require youshido/graphql-files-bundle

### 2. Configuration:

[](#2-configuration)

#### 2.1 Enable bundle in your `AppKernel.php`:

[](#21-enable-bundle-in-your-appkernelphp)

```
$bundles[] = new Youshido\GraphQLFilesBundle\GraphQLFilesBundle()
```

#### 2.2. Add new routing in `routing.yml`:

[](#22-add-new-routing-in-routingyml)

```
graphql_file.image_resizer:
    resource: "@GraphQLFilesBundle/Resources/config/routing.yml"
```

#### 2.3. Configurate bundle in `config.yml`

[](#23-configurate-bundle-in-configyml)

This is full configuration and by default are not needed:

```
graph_ql_files:
    image_driver: gd     #imagine driver, can be gd, imagick or gmagick
    storage: local       #or s3
    platform: orm        #or odm
    local:                                     #config for local storage
        web_root: "%kernel.root_dir%/../web"
        path_prefix: "uploads"
    s3:                                        #config for s3 storage
        client: ~                              #s3 client service
        bucket: ~
        directory: ''
    models:
        image_validation_model: Youshido\GraphQLFilesBundle\Model\Validation\ImageValidationModel
        file_validation_model: Youshido\GraphQLFilesBundle\Model\Validation\FileValidationModel
        orm:
            image: Youshido\GraphQLFilesBundle\Entity\Image
            file: Youshido\GraphQLFilesBundle\Entity\File
        odm:
            image: Youshido\GraphQLFilesBundle\Document\Image
            file: Youshido\GraphQLFilesBundle\Document\File
```

### 3. Set-up GraphQL schema:

[](#3-set-up-graphql-schema)

#### 3.1 Add `UploadImageMutation` to your `MutationType`:

[](#31-add-uploadimagemutation-to-your-mutationtype)

```
