File tree Expand file tree Collapse file tree 2 files changed +34
-1
lines changed Expand file tree Collapse file tree 2 files changed +34
-1
lines changed Original file line number Diff line number Diff line change @@ -16,15 +16,19 @@ class GraphQL extends AbstractApi
16
16
17
17
/**
18
18
* @param string $query
19
+ * @param array $variables
19
20
*
20
21
* @return array
21
22
*/
22
- public function execute ($ query )
23
+ public function execute ($ query, array $ variables = null )
23
24
{
24
25
$ this ->acceptHeaderValue = 'application/vnd.github.v4+json ' ;
25
26
$ params = array (
26
27
'query ' => $ query
27
28
);
29
+ if (!empty ($ variables )) {
30
+ $ params ['variables ' ] = json_encode ($ variables );
31
+ }
28
32
29
33
return $ this ->post ('/graphql ' , $ params );
30
34
}
Original file line number Diff line number Diff line change @@ -21,6 +21,35 @@ public function shouldTestGraphQL()
21
21
$ this ->assertEquals ('foo ' , $ result );
22
22
}
23
23
24
+ /**
25
+ * @test
26
+ */
27
+ public function shouldSupportGraphQLVariables ()
28
+ {
29
+ $ api = $ this ->getApiMock ();
30
+
31
+ $ api ->method ('post ' )
32
+ ->with ('/graphql ' , $ this ->arrayHasKey ('variables ' ));
33
+
34
+ $ api ->execute ('bar ' , ['variable ' => 'foo ' ]);
35
+ }
36
+
37
+ /**
38
+ * @test
39
+ */
40
+ public function shouldJSONEncodeGraphQLVariables ()
41
+ {
42
+ $ api = $ this ->getApiMock ();
43
+
44
+ $ api ->method ('post ' )
45
+ ->with ('/graphql ' , $ this ->equalTo ([
46
+ 'query ' =>'bar ' ,
47
+ 'variables ' => '{"variable":"foo"} '
48
+ ]));
49
+
50
+ $ api ->execute ('bar ' , ['variable ' => 'foo ' ]);
51
+ }
52
+
24
53
protected function getApiClass ()
25
54
{
26
55
return \Github \Api \GraphQL::class;
You can’t perform that action at this time.
0 commit comments