Skip to content

Commit 8655422

Browse files
authored
Readme update : GraphQL variables
1 parent a8ab4fd commit 8655422

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,36 @@ Query;
255255

256256
$data = $shopify->GraphQL->post($graphQL);
257257
```
258+
##### Variables
259+
If you want to use [GraphQL variables](https://shopify.dev/concepts/graphql/variables), you need to put the variables in an array and give it as the 4th argument of the `post()` method. The 2nd and 3rd arguments don't have any use in GraphQL, but are there to keep similarity with other requests, you can just keep those as `null`. Here is an example:
260+
261+
```php
262+
$graphQL = <<<Query
263+
mutation ($input: CustomerInput!) {
264+
customerCreate(input: $input)
265+
{
266+
customer {
267+
id
268+
displayName
269+
}
270+
userErrors {
271+
field
272+
message
273+
}
274+
}
275+
}
276+
Query;
277+
278+
$variables = [
279+
"input" => [
280+
"firstName" => "Greg",
281+
"lastName" => "Variables",
282+
"email" => "gregvariables@teleworm.us"
283+
]
284+
]
285+
$shopify->GraphQL->post($graphQL, null, null, $variables);
286+
```
287+
258288

259289
##### GraphQL Builder
260290
This SDK only accepts a GraphQL string as input. You can build your GraphQL from [Shopify GraphQL Builder](https://help.shopify.com/en/api/graphql-admin-api/graphiql-builder)

0 commit comments

Comments
 (0)