Skip to content

Commit

Permalink
Adapting code to new TypeMapperInterface
Browse files Browse the repository at this point in the history
  • Loading branch information
moufmouf committed Aug 1, 2018
1 parent b05c538 commit 0d28266
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 27 deletions.
26 changes: 24 additions & 2 deletions src/AbstractTdbmGraphQLTypeMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@
namespace TheCodingMachine\Tdbm\GraphQL;

use Psr\Container\ContainerInterface;
use TheCodingMachine\GraphQL\Controllers\TypeMapperInterface;
use TheCodingMachine\GraphQL\Controllers\Mappers\TypeMapperInterface;
use Youshido\GraphQL\Type\InputObject\InputObjectType;
use Youshido\GraphQL\Type\InputTypeInterface;
use Youshido\GraphQL\Type\ListType\ListType;
use Youshido\GraphQL\Type\NonNullType;
use Youshido\GraphQL\Type\Object\AbstractObjectType;
use Youshido\GraphQL\Type\TypeInterface;
use Youshido\GraphQL\Type\TypeMap;

abstract class AbstractTdbmGraphQLTypeMapper implements TypeMapperInterface
{
Expand Down Expand Up @@ -124,4 +123,27 @@ private function mapTypeToInputType(TypeInterface $type): InputTypeInterface
$inputType->addFields($inputFields);
return $inputType;
}

/**
* Returns true if this type mapper can map the $className FQCN to a GraphQL type.
*
* @param string $className
* @return bool
*/
public function canMapClassToType(string $className): bool
{
return isset($this->getMap()[$className]);
}


/**
* Returns true if this type mapper can map the $className FQCN to a GraphQL input type.
*
* @param string $className
* @return bool
*/
public function canMapClassToInputType(string $className): bool
{
return isset($this->getMap()[$className]);
}
}
28 changes: 3 additions & 25 deletions tests/TestRegistryFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
use Doctrine\Common\Annotations\Reader;
use Psr\Container\ContainerInterface;
use TheCodingMachine\GraphQL\Controllers\HydratorInterface;
use TheCodingMachine\GraphQL\Controllers\Mappers\StaticTypeMapper;
use TheCodingMachine\GraphQL\Controllers\Registry\EmptyContainer;
use TheCodingMachine\GraphQL\Controllers\Registry\Registry;
use TheCodingMachine\GraphQL\Controllers\Security\AuthenticationServiceInterface;
use TheCodingMachine\GraphQL\Controllers\Security\AuthorizationServiceInterface;
use TheCodingMachine\GraphQL\Controllers\Security\VoidAuthenticationService;
use TheCodingMachine\GraphQL\Controllers\Security\VoidAuthorizationService;
use TheCodingMachine\GraphQL\Controllers\TypeMapperInterface;
use TheCodingMachine\GraphQL\Controllers\Mappers\TypeMapperInterface;
use Youshido\GraphQL\Type\InputTypeInterface;
use Youshido\GraphQL\Type\TypeInterface;

Expand All @@ -30,30 +31,7 @@ public static function build(ContainerInterface $container = null,
$authorizationService = $authorizationService ?: new VoidAuthorizationService();
$authenticationService = $authenticationService ?: new VoidAuthenticationService();
$reader = new AnnotationReader();
$typeMapper = $typeMapper ?: new class implements TypeMapperInterface {

/**
* Maps a PHP fully qualified class name to a GraphQL type.
*
* @param string $className
* @return TypeInterface
*/
public function mapClassToType(string $className): TypeInterface
{
throw new \RuntimeException('Not implemented');
}

/**
* Maps a PHP fully qualified class name to a GraphQL input type.
*
* @param string $className
* @return InputTypeInterface
*/
public function mapClassToInputType(string $className): InputTypeInterface
{
throw new \RuntimeException('Not implemented');
}
};
$typeMapper = $typeMapper ?: new StaticTypeMapper();
$hydrator = $hydrator ?: new class implements HydratorInterface {

/**
Expand Down

0 comments on commit 0d28266

Please sign in to comment.