ynloultratech / graphql-media-service
Serve and manage files using a GraphQL API
Installs: 10 857
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 3
Forks: 0
Open Issues: 0
Type:symfony-bundle
Requires
- php: ^7.1.3
- doctrine/annotations: ^1.5
- doctrine/common: ^2.8
- mindplay/readable: ^1.1
- mtdowling/jmespath.php: ^2.4
- myclabs/deep-copy: ^1.7
- spatie/url-signer: ^1.0
- symfony/form: ^3.4
- symfony/framework-bundle: ^3.4
- ynloultratech/graphql-bundle: ^1.4
Requires (Dev)
- behat/behat: ^3.4
- behat/symfony2-extension: ^2.1
- cocur/slugify: ^3.0
- doctrine/doctrine-bundle: ^1.6
- doctrine/doctrine-fixtures-bundle: ^2.4
- doctrine/orm: ^2.5
- escapestudios/symfony2-coding-standard: 3.x-dev
- fresh/doctrine-enum-bundle: 5.2
- fzaninotto/faker: ^1.7
- lexik/jwt-authentication-bundle: ^2.4
- mockery/mockery: dev-master
- monolog/monolog: ^1.23
- phpunit/phpunit: ^6.2
- symfony/monolog-bundle: ^3.1
- symfony/phpunit-bridge: ^3.1
- symfony/web-server-bundle: ^3.3
This package is auto-updated.
Last update: 2024-11-29 05:28:06 UTC
README
To build your application you probably need images, video's or maybe even a presentation too. The GraphQL Media Service handles all those media assets and centralizes them so you can find your content just the way you like it: fast and efficiently.
- Single endpoint to upload your files trough a API.
- GraphQL Object for files to get details and download url.
- Public and Private files using signed urls
- Direct relations between files and entities
Installation
Install using composer:
composer require graphql-media-service
How its works?
Usage
The following steps assume you have a configured GraphQLAPI using graphql-bundle.
Add the following config in your config.yml
#config.yml media_service: class: AppBundle\Entity\File default_storage: public_files storage: public_files: local: dir_name: "%kernel.root_dir%/../public/uploads" base_url: 'http://example.com/uploads'
For performance reasons public files are served directly thought the http server, then the
base_url
must be a valid public accessible folder where the files are located.
Create a new entity File
namespace AppBundle\Entity; use Doctrine\ORM\Mapping as ORM; use Ynlo\GraphQLBundle\Annotation as GraphQL; use Ynlo\GraphQLMediaService\Model\AbstractFile; /** * @ORM\Entity() * @ORM\Table() * * @GraphQL\ObjectType() */ class File extends AbstractFile { }
At this point you must have a mutation called uploadFile
in your graphql schema,
see graphql-multipart-request-spec
for details of using multipart form data to upload files.
Assign uploaded files to existent object
Upload files to the server is only the first step, you must able to link that files to existent objects. For example link a uploaded photo to the user profile.
Create a field to store the relation on a existent entity:
/** * @ORM\Entity() * @ORM\Table() * * @GraphQL\ObjectType() */ class Profile implements NodeInterface { //.... /** * @var File * * @ORM\OneToOne(targetEntity="AppBundle\Entity\File", orphanRemoval=true) * * @GraphQL\Expose() * * @MediaService\AttachFile() */ protected $photo;
Note the annotation
@MediaService\AttachFile()
is required on properties linked to Files in order to resolve some parameters like theurl
in runtime.
@TODO ...