You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
`getResolver()` receives an array-argument with followed item:
246
+
247
+
-`root` 1st argument given by webonyx library - `GraphQL\Executor\Executor::resolveOrError()`
248
+
-`args` 2nd argument given by webonyx library
249
+
-`context` 3rd argument given by webonyx library
250
+
-`info` 4th argument given by webonyx library
251
+
-`fields` array of fields, that were fetched from query. Limited by depth in `StudioNet\GraphQL\GraphQL::FIELD_SELECTION_DEPTH`
252
+
-`with` array of relations, that could/should be eager loaded. **NOTICE:** Finding this relations happens ONLY, if `getSource()` is defined - this method should return a class name of a associated root-type in query. If `getSource()` is not defined, then `with` will be always empty.
253
+
225
254
### Mutation
226
255
227
256
Mutation are used to update or create data.
@@ -236,6 +265,14 @@ use StudioNet\GraphQL\Definition\Type;
236
265
use App\User;
237
266
238
267
class Profile extends Mutation {
268
+
/**
269
+
* {@inheritDoc}
270
+
*/
271
+
protected function authorize(array $args) {
272
+
// check, that user is not a guest
273
+
return !Auth::guest();
274
+
}
275
+
239
276
/**
240
277
* {@inheritDoc}
241
278
*
@@ -294,6 +331,14 @@ return [
294
331
];
295
332
```
296
333
334
+
### Require authorization
335
+
336
+
Currently you have a possibility to protect your own queries and mutations. You have to implement `authorize()` method in your query/mutation, that return a boolean, that indicates, if requested query/mutation has to be executed. If method return `false`, an `UNAUTHORIZED` GraphQL-Error will be thrown.
337
+
338
+
Usage examples are in query and mutation above.
339
+
340
+
Protection of definition transformers are currently not implemented, but may be will in the future. By now you have to define your query/mutation yourself, and protect it then with logic in `authorize()`.
341
+
297
342
### Self documentation
298
343
299
344
A documentation generator is implemented with the package. By default, you can access it by navigate to `/doc/graphql`. You can change this behavior within the configuration file. The built-in documentation is implemented from [this repository](https://github.com/mhallin/graphql-docs).
@@ -560,6 +605,14 @@ post-save (which can be useful for eloquent relational models) :
560
605
}
561
606
```
562
607
608
+
### N+1 Problem
609
+
610
+
The common question is, if graphql library solves n+1 problem. This occures, when graphql resolves relation. Often entities are fetched without relations, and when graphql query needs to fetch relation, for each fetched entity relation would be fetched from SQL separately. So instead of executing 2 SQL queries, you will get N+1 queries, where N is the count of results of root entity. In that example you would query only one relation. If you query more relations, then it becomes N^2+1 problem.
611
+
612
+
To solve it, Eloquent has already options to eager load relations. Transformers in this library use eager loading, depends on what you query.
613
+
614
+
Currently this smart detection works perfect only on View and List Transformers. Other transformers will be reworked soon.
615
+
563
616
## Contribution
564
617
565
618
If you want participate to the project, thank you ! In order to work properly,
0 commit comments