@@ -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 )
@@ -1944,6 +1945,40 @@ The following is not a bullet-proof list but should serve as a guide. It's not a
1944
1945
- The trait ` ShouldValidate ` does not exist anymore; the provided features are baked into ` Field `
1945
1946
- The first argument to the resolve method for queries/mutations is now ` null ` (previously its default was an empty array)
1946
1947
1948
+ ### Macros
1949
+
1950
+ If you would like to define some helpers that you can re-use in a variety of your
1951
+ queries, mutations and types, you may use the macro method on the ` GraphQL ` facade.
1952
+
1953
+ For example, from a service provider's boot method:
1954
+
1955
+ ``` php
1956
+ <?php
1957
+
1958
+ namespace App\Providers;
1959
+
1960
+ use GraphQL\Type\Definition\Type;
1961
+ use Illuminate\Support\ServiceProvider;
1962
+ use Rebing\GraphQL\Support\Facades\GraphQL;
1963
+
1964
+ class AppServiceProvider extends ServiceProvider
1965
+ {
1966
+ /**
1967
+ * Bootstrap any application services.
1968
+ *
1969
+ * @return void
1970
+ */
1971
+ public function boot()
1972
+ {
1973
+ GraphQL::macro('listOf', function (string $name) : Type {
1974
+ return Type::listOf(GraphQL::type($name));
1975
+ });
1976
+ }
1977
+ }
1978
+ ```
1979
+
1980
+ The ` macro ` function accepts a name as its first argument, and a ` Closure ` as its second.
1981
+
1947
1982
## Performance considerations
1948
1983
1949
1984
### Lazy loading of types
0 commit comments