Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
510 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the API Platform project. | ||
* | ||
* (c) Kévin Dunglas <dunglas@gmail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity; | ||
|
||
use ApiPlatform\Core\Annotation\ApiProperty; | ||
use ApiPlatform\Core\Annotation\ApiResource; | ||
use GraphQL\Type\Definition\Type; | ||
|
||
/** | ||
* Class MediaObject. | ||
* | ||
* @ApiResource(iri="http://schema.org/MediaObject", | ||
* graphql={ | ||
* "upload"={ | ||
* "mutation"="app.graphql.mutation_resolver.upload_media_object", | ||
* "args"={ | ||
* "file"={"type"="Upload!", "description"="File"} | ||
* } | ||
* }, | ||
* "uploadMultiple"={ | ||
* "mutation"="app.graphql.mutation_resolver.upload_multiple_media_object", | ||
* "args"={ | ||
* "files"={"type"="[Upload!]!", "description"="Files"} | ||
* } | ||
* } | ||
* } | ||
* ) | ||
* | ||
* @author Mahmood Bazdar <mahmood@bazdar.me> | ||
*/ | ||
class MediaObject | ||
{ | ||
/** | ||
* @ApiProperty(identifier=true) | ||
*/ | ||
public $id; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
public $contentUrl; | ||
} |
43 changes: 43 additions & 0 deletions
43
tests/Fixtures/TestBundle/GraphQl/Resolver/UploadMediaObjectResolver.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the API Platform project. | ||
* | ||
* (c) Kévin Dunglas <dunglas@gmail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ApiPlatform\Core\Tests\Fixtures\TestBundle\GraphQl\Resolver; | ||
|
||
use ApiPlatform\Core\GraphQl\Resolver\MutationResolverInterface; | ||
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\MediaObject; | ||
|
||
/** | ||
* Resolver for custom file upload mutation. | ||
* | ||
* @author Mahmood Bazdar <mahmood@bazdar.me> | ||
*/ | ||
class UploadMediaObjectResolver implements MutationResolverInterface | ||
{ | ||
/** | ||
* @param MediaObject|null $item | ||
*/ | ||
public function __invoke($item, array $context): MediaObject | ||
{ | ||
/** | ||
* @var \Symfony\Component\HttpFoundation\File\UploadedFile | ||
*/ | ||
$uploadedFile = $context['args']['input']['file']; | ||
// doing some process for uploading the file | ||
|
||
$uploadedMediaObject = new MediaObject(); | ||
$uploadedMediaObject->id = 1; | ||
$uploadedMediaObject->contentUrl = $uploadedFile->getFileName(); | ||
|
||
return $uploadedMediaObject; | ||
} | ||
} |
Oops, something went wrong.