File tree Expand file tree Collapse file tree 6 files changed +32
-27
lines changed
GraphQl/Model/Backpressure Expand file tree Collapse file tree 6 files changed +32
-27
lines changed Original file line number Diff line number Diff line change 10
10
11
11
use Magento \Framework \App \Backpressure \ContextInterface ;
12
12
use Magento \Framework \App \Backpressure \IdentityProviderInterface ;
13
+ use Magento \Framework \App \ObjectManager ;
13
14
use Magento \Framework \App \RequestInterface ;
14
15
use Magento \Framework \GraphQl \Config \Element \Field ;
15
- use Magento \Framework \HTTP \PhpEnvironment \RemoteAddress ;
16
16
17
17
/**
18
- * Creates context for fields.
18
+ * Creates context for fields
19
19
*/
20
20
class BackpressureContextFactory
21
21
{
@@ -50,7 +50,7 @@ public function __construct(
50
50
}
51
51
52
52
/**
53
- * Creates context if possible.
53
+ * Creates context if possible
54
54
*
55
55
* @param Field $field
56
56
* @return ContextInterface|null
@@ -62,12 +62,15 @@ public function create(Field $field): ?ContextInterface
62
62
return null ;
63
63
}
64
64
65
- return new GraphQlContext (
66
- $ this ->request ,
67
- $ this ->identityProvider ->fetchIdentity (),
68
- $ this ->identityProvider ->fetchIdentityType (),
69
- $ typeId ,
70
- $ field ->getResolver ()
65
+ return ObjectManager::getInstance ()->create (
66
+ GraphQlContext::class,
67
+ [
68
+ $ this ->request ,
69
+ $ this ->identityProvider ->fetchIdentity (),
70
+ $ this ->identityProvider ->fetchIdentityType (),
71
+ $ typeId ,
72
+ $ field ->getResolver ()
73
+ ]
71
74
);
72
75
}
73
76
}
Original file line number Diff line number Diff line change 15
15
use Magento \Framework \GraphQl \Query \Resolver \Argument \ValidatorInterface ;
16
16
17
17
/**
18
- * Enforces backpressure for queries/mutations.
18
+ * Enforces backpressure for queries/mutations
19
19
*/
20
20
class BackpressureFieldValidator implements ValidatorInterface
21
21
{
@@ -47,14 +47,16 @@ public function __construct(
47
47
public function validate (Field $ field , $ args ): void
48
48
{
49
49
$ context = $ this ->backpressureContextFactory ->create ($ field );
50
- if ($ context ) {
51
- try {
52
- $ this ->backpressureEnforcer ->enforce ($ context );
53
- } catch (BackpressureExceededException $ exception ) {
54
- throw new GraphQlInputException (
55
- __ ('Something went wrong while processing the request. Try again later ' )
56
- );
57
- }
50
+ if (!$ context ) {
51
+ return ;
52
+ }
53
+
54
+ try {
55
+ $ this ->backpressureEnforcer ->enforce ($ context );
56
+ } catch (BackpressureExceededException $ exception ) {
57
+ throw new GraphQlInputException (
58
+ __ ('Something went wrong while processing the request. Try again later ' )
59
+ );
58
60
}
59
61
}
60
62
}
Original file line number Diff line number Diff line change 11
11
use Magento \Framework \GraphQl \Config \Element \Field ;
12
12
13
13
/**
14
- * Extracts using other extractors.
14
+ * Extracts using other extractors
15
15
*/
16
16
class CompositeRequestTypeExtractor implements RequestTypeExtractorInterface
17
17
{
Original file line number Diff line number Diff line change 11
11
use Magento \Framework \App \Backpressure \ContextInterface ;
12
12
use Magento \Framework \App \RequestInterface ;
13
13
14
+ /**
15
+ * GraphQl request context
16
+ */
14
17
class GraphQlContext implements ContextInterface
15
18
{
16
19
/**
@@ -92,7 +95,7 @@ public function getTypeId(): string
92
95
}
93
96
94
97
/**
95
- * Field's resolver class name.
98
+ * Field's resolver class name
96
99
*
97
100
* @return string
98
101
*/
Original file line number Diff line number Diff line change 11
11
use Magento \Framework \GraphQl \Config \Element \Field ;
12
12
13
13
/**
14
- * Extracts request type for fields.
14
+ * Extracts request type for fields
15
15
*/
16
16
interface RequestTypeExtractorInterface
17
17
{
18
18
/**
19
- * Extracts type ID if possible.
19
+ * Extracts type ID if possible
20
20
*
21
21
* @param Field $field
22
22
* @return string|null
Original file line number Diff line number Diff line change 15
15
use ReflectionException ;
16
16
17
17
/**
18
- * Identifies which quote fields need backpressure management.
18
+ * Identifies which quote fields need backpressure management
19
19
*/
20
20
class BackpressureRequestTypeExtractor implements RequestTypeExtractorInterface
21
21
{
@@ -38,13 +38,10 @@ public function __construct(OrderLimitConfigManager $config)
38
38
public function extract (Field $ field ): ?string
39
39
{
40
40
$ fieldResolver = $ this ->resolver ($ field ->getResolver ());
41
-
42
41
$ placeOrderName = $ this ->resolver (PlaceOrder::class);
43
-
44
42
$ setPaymentAndPlaceOrder = $ this ->resolver (SetPaymentAndPlaceOrder::class);
45
43
46
- if (($ field ->getResolver () === $ setPaymentAndPlaceOrder ||
47
- $ placeOrderName === $ fieldResolver )
44
+ if (($ field ->getResolver () === $ setPaymentAndPlaceOrder || $ placeOrderName === $ fieldResolver )
48
45
&& $ this ->config ->isEnforcementEnabled ()
49
46
) {
50
47
return OrderLimitConfigManager::REQUEST_TYPE_ID ;
You can’t perform that action at this time.
0 commit comments