File tree Expand file tree Collapse file tree 1 file changed +39
-0
lines changed
Expand file tree Collapse file tree 1 file changed +39
-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+
14+ public function process (QueryFieldDescriptor $ queryFieldDescriptor , FieldHandlerInterface $ fieldHandler ): ?FieldDefinition
15+ {
16+
17+ $ resolver = $ queryFieldDescriptor ->getResolver ();
18+
19+ $ queryFieldDescriptor ->setResolver (function (...$ args ) use ($ resolver , $ queryFieldDescriptor ) {
20+ try {
21+ return $ resolver (...$ args );
22+ } catch (NoBeanFoundException $ e ) {
23+ throw new GraphQLException (
24+ $ e ->getMessage (),
25+ 404 ,
26+ $ e ,
27+ 'Exception ' ,
28+ [
29+ 'table ' => $ e ->getTableName (),
30+ 'keys ' => $ e ->getPrimaryKeys (),
31+ 'className ' => $ e ->getClassName ()
32+ ]
33+ );
34+ }
35+ });
36+
37+ return $ fieldHandler ->handle ($ queryFieldDescriptor );
38+ }
39+ }
You can’t perform that action at this time.
0 commit comments