File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed
Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+ namespace TheCodingMachine \Tdbm \GraphQL \Middlewares ;
3+
4+ use GraphQL \Type \Definition \FieldDefinition ;
5+ use TheCodingMachine \GraphQLite \Exceptions \GraphQLException ;
6+ use TheCodingMachine \GraphQLite \Middlewares \FieldHandlerInterface ;
7+ use TheCodingMachine \GraphQLite \Middlewares \FieldMiddlewareInterface ;
8+ use TheCodingMachine \GraphQLite \QueryFieldDescriptor ;
9+ use TheCodingMachine \TDBM \NoBeanFoundException ;
10+
11+ class NoBeanFoundExceptionWrapperMiddleware implements FieldMiddlewareInterface
12+ {
13+ public function process (QueryFieldDescriptor $ queryFieldDescriptor , FieldHandlerInterface $ fieldHandler ): ?FieldDefinition
14+ {
15+ $ resolver = $ queryFieldDescriptor ->getResolver ();
16+
17+ $ queryFieldDescriptor ->setResolver (function (...$ args ) use ($ resolver , $ queryFieldDescriptor ) {
18+ try {
19+ return $ resolver (...$ args );
20+ } catch (NoBeanFoundException $ e ) {
21+ throw new GraphQLException (
22+ $ e ->getMessage (),
23+ 404 ,
24+ $ e ,
25+ 'Exception ' ,
26+ [
27+ 'table ' => $ e ->getTableName (),
28+ 'keys ' => $ e ->getPrimaryKeys (),
29+ 'className ' => $ e ->getClassName ()
30+ ]
31+ );
32+ }
33+ });
34+
35+ return $ fieldHandler ->handle ($ queryFieldDescriptor );
36+ }
37+ }
You can’t perform that action at this time.
0 commit comments