@@ -37,11 +37,15 @@ class RequestContext implements Context
37
37
/** @var RequestFactoryInterface */
38
38
private $ requestFactory ;
39
39
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 = '' )
41
44
{
42
45
$ this ->builder = $ builder ;
43
46
$ this ->streamFactory = $ streamFactory ;
44
47
$ this ->requestFactory = $ requestFactory ;
48
+ $ this ->graphqlEndpoint = $ graphqlEndpoint ;
45
49
46
50
$ this ->client = Psr18ClientDiscovery::find ();
47
51
}
@@ -118,6 +122,24 @@ final public function set_the_body(string $body): void
118
122
$ this ->request = $ request ->withBody ($ stream );
119
123
}
120
124
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
+
121
143
/** @When I add/set the value :value to the header :header */
122
144
final public function add_header (string $ header , string $ value ): void
123
145
{
0 commit comments