Skip to content
This repository has been archived by the owner on Mar 29, 2020. It is now read-only.

Commit

Permalink
add helper to custom field and document
Browse files Browse the repository at this point in the history
  • Loading branch information
chrissm79 committed Apr 25, 2016
1 parent eebe9a7 commit 10cb2c5
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
24 changes: 22 additions & 2 deletions docs/Schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -300,6 +300,26 @@ class AvatarField extends GraphQLField
}
```

**To use the field in your Type(s):**

```php
<?php
// TypeClass ...

/**
* Available fields of Type.
*
* @return array
*/
public function relayFields()
{
return [
'avatar' => 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.
Expand Down
10 changes: 10 additions & 0 deletions src/Support/Definition/GraphQLField.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down

0 comments on commit 10cb2c5

Please sign in to comment.