@@ -133,6 +133,7 @@ To work this around:
133
133
- [ JSON columns] ( #json-columns )
134
134
- [ Field deprecation] ( #field-deprecation )
135
135
- [ Default field resolver] ( #default-field-resolver )
136
+ - [ Macros] ( #macros )
136
137
- [ Guides] ( #guides )
137
138
- [ Upgrading from v1 to v2] ( #upgrading-from-v1-to-v2 )
138
139
- [ Migrating from Folklore] ( #migrating-from-folklore )
@@ -1869,6 +1870,40 @@ You can define any valid callable (static class method, closure, etc.) for it:
1869
1870
1870
1871
The parameters received are your regular "resolve" function signature.
1871
1872
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
+
1872
1907
## Guides
1873
1908
1874
1909
### Upgrading from v1 to v2
0 commit comments