Skip to content

Commit 62adee7

Browse files
author
Mahel SIf
committed
Add new step for graphql query
1 parent 56dc556 commit 62adee7

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

src/Http/RequestContext.php

+23-1
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,15 @@ class RequestContext implements Context
3737
/** @var RequestFactoryInterface */
3838
private $requestFactory;
3939

40-
public function __construct(PluginClientBuilder $builder, StreamFactoryInterface $streamFactory, RequestFactoryInterface $requestFactory)
40+
/** @var string */
41+
private $graphqlEndpoint;
42+
43+
public function __construct(PluginClientBuilder $builder, StreamFactoryInterface $streamFactory, RequestFactoryInterface $requestFactory, string $graphqlEndpoint = '')
4144
{
4245
$this->builder = $builder;
4346
$this->streamFactory = $streamFactory;
4447
$this->requestFactory = $requestFactory;
48+
$this->graphqlEndpoint = $graphqlEndpoint;
4549

4650
$this->client = Psr18ClientDiscovery::find();
4751
}
@@ -118,6 +122,24 @@ final public function set_the_body(string $body): void
118122
$this->request = $request->withBody($stream);
119123
}
120124

125+
/** @When I create the following graphql request: */
126+
final public function set_the_graphql_body(string $body): void
127+
{
128+
if (empty($this->graphqlEndpoint)) {
129+
throw new RuntimeException('No graphql endpoint specified');
130+
}
131+
132+
$this->query = [];
133+
$this->request = $this->requestFactory->createRequest('POST', $this->graphqlEndpoint);
134+
135+
// let's set a default content-type
136+
$this->set_the_content_type($this->getDefaultContentType());
137+
138+
$stream = $this->streamFactory->createStream(json_encode(['query' => $body]));
139+
140+
$this->request = $this->request->withBody($stream);
141+
}
142+
121143
/** @When I add/set the value :value to the header :header */
122144
final public function add_header(string $header, string $value): void
123145
{

0 commit comments

Comments
 (0)