File tree Expand file tree Collapse file tree 2 files changed +62
-0
lines changed Expand file tree Collapse file tree 2 files changed +62
-0
lines changed Original file line number Diff line number Diff line change @@ -79,6 +79,40 @@ $service = new Shopify\Service\ProductService($client);
7979$service->delete($productId);
8080```
8181
82+ ### GraphQL
83+
84+ #### Query
85+ ``` php
86+ $service = new Shopify\Service\GraphQLService($client);
87+ $service->graph(
88+ '{
89+ products(query: "created_at:<2019 " , first: 5) {
90+ edges {
91+ node {
92+ title
93+ description
94+ }
95+ }
96+ }
97+ }'
98+ );
99+ ```
100+
101+ #### Mutation
102+ ```php
103+ $service = new Shopify\Service\GraphQLService($client);
104+ $service->graph(
105+ 'mutation productCreate($input: ProductInput!){
106+ productCreate(input: $input) {
107+ product {
108+ id
109+ }
110+ }
111+ }',
112+ ['input' => ['title' => 'Sweet new product','productType' => 'Snowboard','vendor' => 'JadedPixel']]
113+ );
114+ ```
115+
82116## Authentication
83117
84118Authentication to Shopify's API is done through access tokens, which are obtained through OAuth. To get a
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Shopify \Service ;
4+
5+ class GraphQLService extends AbstractService
6+ {
7+
8+ public function graph (string $ query , array $ variables = [])
9+ {
10+ // Build the request
11+ $ request = ['query ' => $ query ];
12+ if (count ($ variables ) > 0 ) {
13+ $ request ['variables ' ] = $ variables ;
14+ }
15+
16+ // Create the request, pass the access token and optional parameters
17+ $ endpoint = '/admin/api/graphql.json ' ;
18+ $ response = $ this ->request (
19+ $ endpoint ,
20+ 'POST ' ,
21+ $ request
22+ );
23+
24+ return (object ) [
25+ 'response ' => $ response
26+ ];
27+ }
28+ }
You can’t perform that action at this time.
0 commit comments