|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
namespace TheCodingMachine\GraphQL\Controllers\Mappers; |
|
5
|
|
|
|
|
6
|
|
|
|
|
7
|
|
|
use ReflectionMethod; |
|
8
|
|
|
|
|
9
|
|
|
class CannotMapTypeException extends \Exception implements CannotMapTypeExceptionInterface |
|
10
|
|
|
{ |
|
11
|
|
|
public static function createForType(string $className): self |
|
12
|
|
|
{ |
|
13
|
|
|
return new self('cannot map class "'.$className.'" to a known GraphQL type. Check your TypeMapper configuration.'); |
|
14
|
|
|
} |
|
15
|
|
|
|
|
16
|
|
|
public static function createForInputType(string $className): self |
|
17
|
|
|
{ |
|
18
|
|
|
return new self('cannot map class "'.$className.'" to a known GraphQL input type. Check your TypeMapper configuration.'); |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
public static function createForName(string $name): self |
|
22
|
|
|
{ |
|
23
|
|
|
return new self('cannot find GraphQL type "'.$name.'". Check your TypeMapper configuration.'); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
public static function wrapWithParamInfo(CannotMapTypeExceptionInterface $previous, \ReflectionParameter $parameter): self |
|
27
|
|
|
{ |
|
28
|
|
|
$message = sprintf('For parameter $%s, in %s::%s, %s', |
|
29
|
|
|
$parameter->getName(), |
|
30
|
|
|
$parameter->getDeclaringClass()->getName(), |
|
31
|
|
|
$parameter->getDeclaringFunction()->getName(), |
|
32
|
|
|
$previous->getMessage()); |
|
33
|
|
|
|
|
34
|
|
|
return new self($message, 0, $previous); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
public static function wrapWithReturnInfo(CannotMapTypeExceptionInterface $previous, ReflectionMethod $method): self |
|
38
|
|
|
{ |
|
39
|
|
|
$message = sprintf('For return type of %s::%s, %s', |
|
40
|
|
|
$method->getDeclaringClass()->getName(), |
|
41
|
|
|
$method->getName(), |
|
42
|
|
|
$previous->getMessage()); |
|
43
|
|
|
|
|
44
|
|
|
return new self($message, 0, $previous); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public static function mustBeOutputType($subTypeName): self |
|
48
|
|
|
{ |
|
49
|
|
|
return new self('type "'.$subTypeName.'" must be an output type.'); |
|
50
|
|
|
} |
|
51
|
|
|
} |
|
52
|
|
|
|