Passed
Push — master ( 0b14f1...83e53d )
by Adrien
12:36
created

PatchGraphQlQueriesMiddleware   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 13
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 1
eloc 4
c 1
b 0
f 0
dl 0
loc 13
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A process() 0 8 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Application\Middleware;
6
7
use Laminas\Diactoros\CallbackStream;
8
use Psr\Http\Message\ResponseInterface;
9
use Psr\Http\Message\ServerRequestInterface;
10
use Psr\Http\Server\MiddlewareInterface;
11
use Psr\Http\Server\RequestHandlerInterface;
12
13
/**
14
 * TODO revert this entire commit in February 2026.
15
 */
16
class PatchGraphQlQueriesMiddleware implements MiddlewareInterface
17
{
18
    /**
19
     * Transform GraphQL queries from old clients to still be compatible with the server new schema.
20
     */
21
    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
22
    {
23
        $contents = $request->getBody()->getContents();
24
25
        // Login mutation does not accept a Login anymore, but a String
26
        $contents = str_replace('"isActive":{"equal":{"value":true}}', '"status": {"equal": {"value": "Active"}}', $contents);
27
28
        return $handler->handle($request->withBody(new CallbackStream(fn () => $contents)));
29
    }
30
}
31