@@ -47,7 +47,7 @@ https://github.com/mghoneimy/php-graphql-oqm)
47
47
48
48
## Simple Query
49
49
50
- ```
50
+ ``` php
51
51
$gql = (new Query('companies'))
52
52
->setSelectionSet(
53
53
[
@@ -61,7 +61,7 @@ This simple query will retrieve all companies displaying their names and serial
61
61
numbers.
62
62
63
63
## Nested Queries
64
- ```
64
+ ``` php
65
65
$gql = (new Query('companies'))
66
66
->setSelectionSet(
67
67
[
@@ -87,7 +87,7 @@ displaying their dates.
87
87
88
88
## Query With Arguments
89
89
90
- ```
90
+ ``` php
91
91
$gql = (new Query('companies'))
92
92
->setArguments(['name' => 'Tech Co.', 'first' => 3])
93
93
->setSelectionSet(
@@ -104,7 +104,7 @@ and serial numbers.
104
104
105
105
## Query With Array Argument
106
106
107
- ```
107
+ ``` php
108
108
$gql = (new Query('companies'))
109
109
->setArguments(['serialNumbers' => [159, 260, 371]])
110
110
->setSelectionSet(
@@ -121,7 +121,7 @@ displaying the name and serial number.
121
121
122
122
## Query With Input Object Argument
123
123
124
- ```
124
+ ``` php
125
125
$gql = (new Query('companies'))
126
126
->setArguments(['filter' => new RawObject('{name_starts_with: "Face"}')])
127
127
->setSelectionSet(
@@ -145,7 +145,7 @@ query class.
145
145
146
146
## Query With Variables
147
147
148
- ```
148
+ ``` php
149
149
$gql = (new Query('companies'))
150
150
->setVariables(
151
151
[
@@ -185,7 +185,7 @@ inline fragments to access data on the underlying concrete type.
185
185
186
186
This example show how to generate inline fragments using this package:
187
187
188
- ```
188
+ ``` php
189
189
$gql = new Query('companies');
190
190
$gql->setSelectionSet(
191
191
[
@@ -211,7 +211,7 @@ Query building is divided into steps.
211
211
That's how the "Query With Input Object Argument" example can be created using
212
212
the QueryBuilder:
213
213
214
- ```
214
+ ``` php
215
215
$builder = (new QueryBuilder('companies'))
216
216
->setVariable('namePrefix', 'String', true)
217
217
->setArgument('filter', new RawObject('{name_starts_with: $namePrefix}'))
@@ -231,7 +231,7 @@ to the GraphQL server.
231
231
232
232
Example:
233
233
234
- ```
234
+ ``` php
235
235
$client = new Client(
236
236
'http://api.graphql.com',
237
237
['Authorization' => 'Basic xyz']
@@ -243,7 +243,7 @@ The Client constructor also receives an optional "httpOptions" array, which **ov
243
243
244
244
Example:
245
245
246
- ```
246
+ ``` php
247
247
$client = new Client(
248
248
'http://api.graphql.com',
249
249
[],
@@ -272,13 +272,13 @@ $client = new Client(
272
272
Running query with the GraphQL client and getting the results in object
273
273
structure:
274
274
275
- ```
275
+ ``` php
276
276
$results = $client->runQuery($gql);
277
277
$results->getData()->Company[0]->branches;
278
278
```
279
279
Or getting results in array structure:
280
280
281
- ```
281
+ ``` php
282
282
$results = $client->runQuery($gql, true);
283
283
$results->getData()['Company'][1]['branches']['address']
284
284
```
@@ -289,7 +289,7 @@ Running queries containing variables requires passing an associative array which
289
289
maps variable names (keys) to variable values (values) to the ` runQuery ` method.
290
290
Here's an example:
291
291
292
- ```
292
+ ``` php
293
293
$gql = (new Query('companies'))
294
294
->setVariables(
295
295
[
@@ -315,7 +315,7 @@ returned objects, receive arguments, and can have sub-fields.
315
315
316
316
Here's a sample example on how to construct and run mutations:
317
317
318
- ```
318
+ ``` php
319
319
$mutation = (new Mutation('createCompany'))
320
320
->setArguments(['companyObject' => new RawObject('{name: "Trial Company", employees: 200}')])
321
321
->setSelectionSet(
@@ -336,7 +336,7 @@ Mutations can utilize the variables in the same way Queries can. Here's an
336
336
example on how to use the variables to pass input objects to the GraphQL server
337
337
dynamically:
338
338
339
- ```
339
+ ``` php
340
340
$mutation = (new Mutation('createCompany'))
341
341
->setVariables([new Variable('company', 'CompanyInputObject', true)])
342
342
->setArguments(['companyObject' => '$company']);
@@ -349,7 +349,7 @@ $client->runQuery(
349
349
350
350
These are the resulting mutation and the variables passed with it:
351
351
352
- ```
352
+ ``` php
353
353
mutation($company: CompanyInputObject!) {
354
354
createCompany(companyObject: $company)
355
355
}
@@ -368,7 +368,7 @@ API link: https://graphql-pokemon.now.sh/
368
368
369
369
This query retrieves any pokemon's evolutions and their attacks:
370
370
371
- ```
371
+ ``` php
372
372
query($name: String!) {
373
373
pokemon(name: $name) {
374
374
id
@@ -398,7 +398,7 @@ query($name: String!) {
398
398
That's how this query can be written using the query class and run using the
399
399
client:
400
400
401
- ```
401
+ ``` php
402
402
$client = new Client(
403
403
'https://graphql-pokemon.now.sh/'
404
404
);
@@ -447,7 +447,7 @@ print_r($results->getData()['pokemon']);
447
447
Or alternatively, That's how this query can be generated using the QueryBuilder
448
448
class:
449
449
450
- ```
450
+ ``` php
451
451
$client = new Client(
452
452
'https://graphql-pokemon.now.sh/'
453
453
);
@@ -489,7 +489,7 @@ Although not the primary goal of this package, but it supports running raw
489
489
string queries, just like any other client using the ` runRawQuery ` method in the
490
490
` Client ` class. Here's an example on how to use it:
491
491
492
- ```
492
+ ``` php
493
493
$gql = <<<QUERY
494
494
query {
495
495
pokemon(name: " Pikachu" ) {
0 commit comments