|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
namespace TheCodingMachine\GraphQLite\Types\AnyScalar; |
|
5
|
|
|
|
|
6
|
|
|
|
|
7
|
|
|
use GraphQL\Type\Definition\InputType; |
|
8
|
|
|
use GraphQL\Type\Definition\NamedType; |
|
9
|
|
|
use GraphQL\Type\Definition\OutputType; |
|
10
|
|
|
use phpDocumentor\Reflection\DocBlock; |
|
11
|
|
|
use phpDocumentor\Reflection\Type; |
|
12
|
|
|
use phpDocumentor\Reflection\Types\Scalar; |
|
13
|
|
|
use ReflectionMethod; |
|
14
|
|
|
use TheCodingMachine\GraphQLite\Mappers\Root\RootTypeMapperInterface; |
|
15
|
|
|
|
|
16
|
|
|
class AnyScalarTypeMapper implements RootTypeMapperInterface |
|
17
|
|
|
{ |
|
18
|
|
|
|
|
19
|
|
|
public function toGraphQLOutputType(Type $type, ?OutputType $subType, ReflectionMethod $refMethod, DocBlock $docBlockObj): ?OutputType |
|
20
|
|
|
{ |
|
21
|
|
|
if ($type instanceof Scalar) { |
|
22
|
|
|
// AnyScalarType is a class implementing the Webonyx ScalarType type. |
|
23
|
|
|
return AnyScalarType::getInstance(); |
|
24
|
|
|
} |
|
25
|
|
|
return null; |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
public function toGraphQLInputType(Type $type, ?InputType $subType, string $argumentName, ReflectionMethod $refMethod, DocBlock $docBlockObj): ?InputType |
|
29
|
|
|
{ |
|
30
|
|
|
if ($type instanceof Scalar) { |
|
31
|
|
|
// AnyScalarType is a class implementing the Webonyx ScalarType type. |
|
32
|
|
|
return AnyScalarType::getInstance(); |
|
33
|
|
|
} |
|
34
|
|
|
return null; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Returns a GraphQL type by name. |
|
39
|
|
|
* If this root type mapper can return this type in "toGraphQLOutputType" or "toGraphQLInputType", it should |
|
40
|
|
|
* also map these types by name in the "mapNameToType" method. |
|
41
|
|
|
* |
|
42
|
|
|
* @param string $typeName The name of the GraphQL type |
|
43
|
|
|
* @return NamedType|null |
|
44
|
|
|
*/ |
|
45
|
|
|
public function mapNameToType(string $typeName): ?NamedType |
|
46
|
|
|
{ |
|
47
|
|
|
if ($typeName === AnyScalarType::NAME) { |
|
48
|
|
|
return AnyScalarType::getInstance(); |
|
49
|
|
|
} |
|
50
|
|
|
return null; |
|
51
|
|
|
} |
|
52
|
|
|
} |
|
53
|
|
|
|