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") {
idurlfileNamemimeTypeextensionsizeresized(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") {
idurlfileNamemimeTypeextensionsize
}
}
Also bundle provides ImageField to use in your API like this:
{
me {
idfirstNamelastNameimage { // imagefieldfrombundleurlresized(width: 100, height: 100, mode: INSET) {
url
}
}
}
}or you can add arguments directly to the image field for your convenience.
{
me {
idfirstNamelastNamesmall: image(width: 100, height: 100, mode: INSET) { // resizeddirectlyurl
} medium: image(width: 500, height: 300, mode: OUTBOUND) { // differentmodeurl
} fullSize: image {
url
}
}
}composer require youshido/graphql-files-bundle
$bundles[] = newYoushido\GraphQLFilesBundle\GraphQLFilesBundle()graphql_file.image_resizer:
resource: "@GraphQLFilesBundle/Resources/config/routing.yml"This is full configuration and by default are not needed:
graph_ql_files:
image_driver: gd #imagine driver, can be gd, imagick or gmagickstorage: local #or s3platform: orm #or odmlocal: #config for local storageweb_root: "%kernel.root_dir%/../web"path_prefix: "uploads"s3: #config for s3 storage client: ~ #s3 client servicebucket: ~directory: ''models:
image_validation_model: Youshido\GraphQLFilesBundle\Model\Validation\ImageValidationModelfile_validation_model: Youshido\GraphQLFilesBundle\Model\Validation\FileValidationModelorm:
image: Youshido\GraphQLFilesBundle\Entity\Imagefile: Youshido\GraphQLFilesBundle\Entity\Fileodm:
image: Youshido\GraphQLFilesBundle\Document\Imagefile: Youshido\GraphQLFilesBundle\Document\File<?phpuseYoushido\GraphQLFilesBundle\GraphQL\Field\UploadBase64ImageField;
useYoushido\GraphQLFilesBundle\GraphQL\Field\UploadImageField;
useYoushido\GraphQLFilesBundle\GraphQL\Field\UploadFileField;
class MutationType extends AbstractObjectType
{
publicfunctionbuild($config)
{
$config->addFields([
// imagesnewUploadBase64ImageField(),
newUploadImageField(),
// filesnewUploadFileField(),
// other mutations
]);
}
}useYoushido\GraphQLFilesBundle\GraphQL\Field\ImageField;
class YourType extends AbstractObjectType
{
publicfunctionbuild($config)
{
$config->addFields([
// your type fieldsnewImageField()
]);
}
}