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
Copy file name to clipboardExpand all lines: CHANGELOG.md
+1
Original file line number
Diff line number
Diff line change
@@ -6,6 +6,7 @@ CHANGELOG
6
6
7
7
### Added
8
8
- Add support for custom authorization message [\#578 / Sh1d0w](https://github.com/rebing/graphql-laravel/pull/578)
9
+
- Add support for macros on the GraphQL service/facade [\#592 / stevelacey](https://github.com/rebing/graphql-laravel/pull/592)
9
10
### Fixed
10
11
- Fix the infinite loop as well as sending the correct matching input data to the rule-callback [\#579 / crissi](https://github.com/rebing/graphql-laravel/pull/579)
-[Default Field Resolver](#default-field-resolver)
132
+
-[Field and input alias](#field-and-input-alias)
133
+
-[JSON columns](#json-columns)
134
+
-[Field deprecation](#field-deprecation)
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)
@@ -186,7 +187,7 @@ use GraphQL\Type\Definition\Type;
186
187
use Rebing\GraphQL\Support\Type as GraphQLType;
187
188
188
189
class UserType extends GraphQLType
189
-
{
190
+
{
190
191
protected $attributes = [
191
192
'name' => 'User',
192
193
'description' => 'A user',
@@ -209,7 +210,7 @@ class UserType extends GraphQLType
209
210
'type' => Type::string(),
210
211
'description' => 'The email of user',
211
212
'resolve' => function($root, $args) {
212
-
// If you want to resolve the field yourself,
213
+
// If you want to resolve the field yourself,
213
214
// it can be done here
214
215
return strtolower($root->email);
215
216
}
@@ -228,7 +229,7 @@ class UserType extends GraphQLType
228
229
protected function resolveEmailField($root, $args)
229
230
{
230
231
return strtolower($root->email);
231
-
}
232
+
}
232
233
}
233
234
```
234
235
@@ -541,7 +542,7 @@ public function validationErrorMessages(array $args = []): array
541
542
'name.string' => 'Your name must be a valid string',
542
543
'email.required' => 'Please enter your email address',
543
544
'email.email' => 'Please enter a valid email address',
544
-
'email.exists' => 'Sorry, this email address is already in use',
545
+
'email.exists' => 'Sorry, this email address is already in use',
545
546
];
546
547
}
547
548
````
@@ -819,7 +820,7 @@ class UserType extends GraphQLType
819
820
}
820
821
```
821
822
822
-
### Query Variables
823
+
### Query variables
823
824
824
825
GraphQL offers you the possibility to use variables in your query so you don't need to "hardcode" value. This is done like that:
825
826
@@ -856,7 +857,7 @@ use GraphQL\Type\Definition\Type;
856
857
use Rebing\GraphQL\Support\Field;
857
858
858
859
class PictureField extends Field
859
-
{
860
+
{
860
861
protected $attributes = [
861
862
'description' => 'A picture',
862
863
];
@@ -943,7 +944,7 @@ use GraphQL\Type\Definition\Type;
943
944
use Rebing\GraphQL\Support\Field;
944
945
945
946
class FormattableDate extends Field
946
-
{
947
+
{
947
948
protected $attributes = [
948
949
'description' => 'A field that can output a date in all sorts of ways.',
949
950
];
@@ -976,15 +977,15 @@ class FormattableDate extends Field
976
977
protected function resolve($root, $args): ?string
977
978
{
978
979
$date = $root->{$this->getProperty()};
979
-
980
+
980
981
if (!$date instanceof Carbon) {
981
982
return null;
982
983
}
983
984
984
985
if ($args['relative']) {
985
986
return $date->diffForHumans();
986
987
}
987
-
988
+
988
989
return $date->format($args['format']);
989
990
}
990
991
@@ -1032,7 +1033,7 @@ class UserType extends GraphQLType
1032
1033
1033
1034
// Because the constructor of `FormattableDate` accepts our the array of parameters,
1034
1035
// we can override them very easily.
1035
-
// Imagine we want our field to be called `createdAt`, but our database column
1036
+
// Imagine we want our field to be called `createdAt`, but our database column
1036
1037
// is called `created_at`:
1037
1038
'createdAt' => new FormattableDate([
1038
1039
'alias' => 'created_at',
@@ -1050,7 +1051,7 @@ Only the required fields will be queried from the database.
1050
1051
1051
1052
The class can be instanciated by typehinting `SelectFields $selectField` in your resolve method.
1052
1053
1053
-
You can also construct the class by typehinting a `Closure`.
1054
+
You can also construct the class by typehinting a `Closure`.
1054
1055
The Closure accepts an optional parameter for the depth of the query to analyse.
1055
1056
1056
1057
Your Query would look like:
@@ -1332,7 +1333,7 @@ within a certain interval of time.
1332
1333
1333
1334
There are tools that help with this and can handle the batching for you, e.g [Apollo](http://www.apollodata.com/)
1334
1335
1335
-
### Scalar Types
1336
+
### Scalar types
1336
1337
1337
1338
GraphQL comes with built-in scalar types for string, int, boolean, etc. It's possible to create custom scalar types to special purpose fields.
1338
1339
@@ -1567,7 +1568,7 @@ Based on the previous code example, the method would look like:
1567
1568
}
1568
1569
```
1569
1570
1570
-
#### Sharing Interface fields
1571
+
#### Sharing interface fields
1571
1572
1572
1573
Since you often have to repeat many of the field definitons of the Interface in the concrete types, it makes sense to share the definitions of the Interface.
1573
1574
You can access and reuse specific interface fields with the method `getField(string fieldName): FieldDefinition`. To get all fields as an array use `getFields(): array`
@@ -1675,7 +1676,7 @@ class TestMutation extends GraphQLType {
1675
1676
}
1676
1677
```
1677
1678
1678
-
### Input Alias
1679
+
### Field and input alias
1679
1680
1680
1681
It is possible to alias query and mutation arguments as well as input object fields.
1681
1682
@@ -1768,7 +1769,7 @@ class UpdateUserMutation extends Mutation
1768
1769
```
1769
1770
1770
1771
1771
-
### JSON Columns
1772
+
### JSON columns
1772
1773
1773
1774
When using JSON columns in your database, the field won't be defined as a "relationship",
1774
1775
but rather a simple column with nested data. To get a nested object that's not a database relationship,
@@ -1801,7 +1802,7 @@ class UserType extends GraphQLType
1801
1802
}
1802
1803
```
1803
1804
1804
-
####Field deprecation
1805
+
### Field deprecation
1805
1806
1806
1807
Sometimes you would want to deprecate a field but still have to maintain backward compatibility
1807
1808
until clients completely stop using that field. You can deprecate a field using
@@ -1820,7 +1821,7 @@ use GraphQL\Type\Definition\Type;
1820
1821
use Rebing\GraphQL\Support\Type as GraphQLType;
1821
1822
1822
1823
class UserType extends GraphQLType
1823
-
{
1824
+
{
1824
1825
protected $attributes = [
1825
1826
'name' => 'User',
1826
1827
'description' => 'A user',
@@ -1856,7 +1857,7 @@ class UserType extends GraphQLType
1856
1857
}
1857
1858
```
1858
1859
1859
-
####Default Field Resolver
1860
+
### Default field resolver
1860
1861
1861
1862
It's possible to override the default field resolver provided by the underlying
1862
1863
webonyx/graphql-php library using the config option `defaultFieldResolver`.
@@ -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
@@ -1940,7 +1975,7 @@ The following is not a bullet-proof list but should serve as a guide. It's not a
1940
1975
- Change namespace references:
1941
1976
- from `Folklore\`
1942
1977
- to `Rebing\`
1943
-
- See [Upgrade guide from v1 to v2 for all the function signature changes](#upgrading-from-v1-to-v2)
1978
+
- See [Upgrade guide from v1 to v2 for all the function signature changes](#upgrading-from-v1-to-v2)
1944
1979
- The trait `ShouldValidate` does not exist anymore; the provided features are baked into `Field`
1945
1980
- The first argument to the resolve method for queries/mutations is now `null` (previously its default was an empty array)
0 commit comments