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
1616
1717 /**
1818 * @param string $query
19+ * @param array $variables
1920 *
2021 * @return array
2122 */
22- public function execute ($ query )
23+ public function execute ($ query, array $ variables = null )
2324 {
2425 $ this ->acceptHeaderValue = 'application/vnd.github.v4+json ' ;
2526 $ params = array (
2627 'query ' => $ query
2728 );
29+ if (!empty ($ variables )) {
30+ $ params ['variables ' ] = json_encode ($ variables );
31+ }
2832
2933 return $ this ->post ('/graphql ' , $ params );
3034 }
Original file line number Diff line number Diff line change @@ -21,6 +21,35 @@ public function shouldTestGraphQL()
2121 $ this ->assertEquals ('foo ' , $ result );
2222 }
2323
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+
2453 protected function getApiClass ()
2554 {
2655 return \Github \Api \GraphQL::class;
You can’t perform that action at this time.
0 commit comments