承接 youshido/graphql-files-bundle 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

youshido/graphql-files-bundle

Composer 安装命令:

composer require youshido/graphql-files-bundle

包简介

Library to implement images and file upload to GraphQL API

README 文档

README

Symfony bundle for easy implementation images and files to your GraphQL API (bundle with GraphQL implementation and its documentation is here). 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

1. Installation:

composer require youshido/graphql-files-bundle

2. Configuration:

2.1 Enable bundle in your AppKernel.php:

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

2.2. Add new routing in routing.yml:

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

2.3. Configurate bundle in config.yml

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.1 Add UploadImageMutation to your MutationType:

<?php

use Youshido\GraphQLFilesBundle\GraphQL\Field\UploadBase64ImageField;
use Youshido\GraphQLFilesBundle\GraphQL\Field\UploadImageField;
use Youshido\GraphQLFilesBundle\GraphQL\Field\UploadFileField;

class MutationType extends AbstractObjectType
{

    public function build($config)
    {

        $config->addFields([
            // images
            new UploadBase64ImageField(),
            new UploadImageField(),
            
            // files
            new UploadFileField(),

            // other mutations
        ]);

    }
}

3.2 Add image field to your type:

use Youshido\GraphQLFilesBundle\GraphQL\Field\ImageField;

class YourType extends AbstractObjectType
{

    public function build($config)
    {
        $config->addFields([
            // your type fields
        
            new ImageField()
        ]);
    }
}

统计信息

  • 总下载量: 4.56k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 4
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 4
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-08-07

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固