Skip to content

Commit 5a47b1b

Browse files
committed
Macro README
1 parent 39be3c6 commit 5a47b1b

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

README.md

+35
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ To work this around:
133133
- [JSON columns](#json-columns)
134134
- [Field deprecation](#field-deprecation)
135135
- [Default field resolver](#default-field-resolver)
136+
- [Macros](#macros)
136137
- [Guides](#guides)
137138
- [Upgrading from v1 to v2](#upgrading-from-v1-to-v2)
138139
- [Migrating from Folklore](#migrating-from-folklore)
@@ -1869,6 +1870,40 @@ You can define any valid callable (static class method, closure, etc.) for it:
18691870

18701871
The parameters received are your regular "resolve" function signature.
18711872

1873+
### Macros
1874+
1875+
If you would like to define some helpers that you can re-use in a variety of your
1876+
queries, mutations and types, you may use the macro method on the `GraphQL` facade.
1877+
1878+
For example, from a service provider's boot method:
1879+
1880+
```php
1881+
<?php
1882+
1883+
namespace App\Providers;
1884+
1885+
use GraphQL\Type\Definition\Type;
1886+
use Illuminate\Support\ServiceProvider;
1887+
use Rebing\GraphQL\Support\Facades\GraphQL;
1888+
1889+
class AppServiceProvider extends ServiceProvider
1890+
{
1891+
/**
1892+
* Bootstrap any application services.
1893+
*
1894+
* @return void
1895+
*/
1896+
public function boot()
1897+
{
1898+
GraphQL::macro('listOf', function (string $name) : Type {
1899+
return Type::listOf(GraphQL::type($name));
1900+
});
1901+
}
1902+
}
1903+
```
1904+
1905+
The `macro` function accepts a name as its first argument, and a `Closure` as its second.
1906+
18721907
## Guides
18731908

18741909
### Upgrading from v1 to v2

0 commit comments

Comments
 (0)