From 10cb2c5e5f85252377930ff4652ac3908cff58b7 Mon Sep 17 00:00:00 2001 From: Christopher Moore Date: Mon, 25 Apr 2016 11:53:50 -0700 Subject: [PATCH] add helper to custom field and document --- docs/Schema.md | 24 ++++++++++++++++++++++-- src/Support/Definition/GraphQLField.php | 10 ++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/docs/Schema.md b/docs/Schema.md index e239e11..fbb9a15 100644 --- a/docs/Schema.md +++ b/docs/Schema.md @@ -230,7 +230,7 @@ class UpdatePassword extends RelayMutation Create a custom field: ```bash -php artisan relay:make:field AvatarField +php artisan relay:make:field Avatar ``` ```php @@ -243,7 +243,7 @@ use GraphQL\Type\Definition\Type; use Nuwave\Relay\Support\Definition\GraphQLField; use Nuwave\Relay\Traits\GlobalIdTrait; -class AvatarField extends GraphQLField +class Avatar extends GraphQLField { /** * Field attributes. @@ -300,6 +300,26 @@ class AvatarField extends GraphQLField } ``` +**To use the field in your Type(s):** + +```php + Avatar::field() + ] +} + +``` + ### Schema File The ```schema.php``` file you create is similar to Laravel's ```routes.php``` file. It used to declare your Types, Mutations and Queries to be used by GraphQL. Similar to routes, you can group your schema by namespace as well as add middleware to your Queries and Mutations. diff --git a/src/Support/Definition/GraphQLField.php b/src/Support/Definition/GraphQLField.php index 7e69bd8..f04be3a 100644 --- a/src/Support/Definition/GraphQLField.php +++ b/src/Support/Definition/GraphQLField.php @@ -152,6 +152,16 @@ public function toArray() return $this->getAttributes(); } + /** + * Transform into field array. + * + * @return array + */ + public static function field() + { + return (new static)->toArray(); + } + /** * Dynamically retrieve the value of an attribute. *