-
-
Notifications
You must be signed in to change notification settings - Fork 569
Closed
Description
I'm trying to wrap my head around for 2 days now and I can't come up with a good solution that follows good practices.
I have the following Query Class.
namespace Ladypopular\api\graphql\App;
use GraphQL\Type\Definition\NonNull;
use GraphQL\Type\Definition\ObjectType;
use Ladypopular\api\graphql\App\Resolver\Event\MapResolver;
class Query extends ObjectType
{
public function __construct()
{
$config = [
'name' => 'Query',
'fields' => [
'map' => [
'type' => Types::map(),
'description' => 'All information needed for the event',
'args' => [
'id' => new NonNull(Types::id()),
],
'fields' => [
'userErrors' => [
'type' => Types::listOf(Types::int()),
'description' => 'User domain logic errors'
]
],
'resolve' => static fn ($rootValue, array $args, \App $context): \Closure
=> (MapResolver::getInstance($context))->getEventById($args['id']),
'interface' => [Types::userErrors(),]
]
],
];
parent::__construct($config);
}
}
I'm using the Standart Server and trying to stop the execution of the request in the first resolve if there is a doma
in logic error. I don't want to continue down the child resolvers and load data. The main problem is that the information in the child resolvers is dependent of the main resolver (Like you can see here when I'm calling getEventById. If I have no found event with this ID I want to stop the request here and return response.
I have a response already created, but I can't stop the execution of the other resolvers. So the following questions popup in my head.
- Is my approach wrong?
- Should I throw exceptions and let the StandartServer handle them, by using custom Error Handler and Formatter? I really don't like this way. I want my domain logic errors to be separated by the application errors.
- How do you handle such logic?
Metadata
Metadata
Assignees
Labels
No labels