1
<?php
2

3
namespace Nuwave\Lighthouse\Schema\Types\Scalars;
4

5
use GraphQL\Error\Error;
6
use GraphQL\Error\InvariantViolation;
7
use GraphQL\Type\Definition\ScalarType;
8
use GraphQL\Utils\Utils;
9
use Illuminate\Http\UploadedFile;
10

11
class Upload extends ScalarType
12
{
13
    /**
14
     * This always throws, as the Upload scalar can only be used as an argument.
15
     *
16
     * @throws \GraphQL\Error\InvariantViolation
17
     */
18 1
    public function serialize($value): void
19
    {
20 1
        throw new InvariantViolation(
21 1
            '"Upload" cannot be serialized, it can only be used as an argument.'
22
        );
23
    }
24

25
    /**
26
     * Parse a externally provided variable value into a Carbon instance.
27
     *
28
     * @throws \GraphQL\Error\Error
29
     */
30 1
    public function parseValue($value): UploadedFile
31
    {
32 1
        if (! $value instanceof UploadedFile) {
33 1
            throw new Error(
34 1
                'Could not get uploaded file, be sure to conform to GraphQL multipart request specification: https://github.com/jaydenseric/graphql-multipart-request-spec Instead got: '.Utils::printSafe($value)
35
            );
36
        }
37

38 1
        return $value;
39
    }
40

41
    /**
42
     * This always throws, as the Upload scalar must be used with a multipart form request.
43
     *
44
     * @param  \GraphQL\Language\AST\Node  $valueNode
45
     * @param  array<string, mixed>|null  $variables
46
     *
47
     * @throws \GraphQL\Error\Error
48
     */
49 1
    public function parseLiteral($valueNode, array $variables = null): void
50
    {
51 1
        throw new Error(
52 1
            '"Upload" cannot be hardcoded in a query. Be sure to conform to the GraphQL multipart request specification: https://github.com/jaydenseric/graphql-multipart-request-spec'
53
        );
54
    }
55
}

Read our documentation on viewing source code .

Loading