Skip to content

Commit

Permalink
New addFields API, allow descriptions wildcard in yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
Uncle Cheese committed Jan 14, 2017
1 parent 10ed7b9 commit e4be8ff
Show file tree
Hide file tree
Showing 5 changed files with 287 additions and 92 deletions.
97 changes: 74 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,80 @@ mutation CreatePost($Input: PostCreateInputType!)
Permission constraints (in this case `canView()` and `canCreate()`) are enforced
by the operation resovlers.
#### Setting field descriptions
Adding field descriptions is a great way to maintain a well-documented API. To do this,
use a map of `FieldName: 'Your description'` instead of an enumerated list of field names.
**Via YAML**:
```yaml
SilverStripe\GraphQL:
schema:
scaffolding:
types:
MyProject\Post:
fields:
ID: The unique identifier of the post
Title: The title of the post
Content: The main body of the post (HTML)
operations:
read: true
create: true
```

**...Or with code**:

```php
namespace MyProject;

class Post extends DataObject implements ScaffoldingProvider {
//...
public function provideGraphQLScaffolding(SchemaScaffolder $scaffolder)
{
$scaffolder
->type(Post::class)
->addFields([
'ID' => 'The unique identidier of the post',
'Title' => 'The title of the post',
'Content' => 'The main body of the post (HTML)'
])
->operation(SchemaScaffolder::READ)
->end()
->operation(SchemaScaffolder::UPDATE)
->end()
->end();

return $scaffolder;
}
}
```

#### Wildcarding and whitelisting fields

If you have a type you want to be fairly well exposed, it can be tedious to add each
field piecemeal. As a shortcut, you can use `addAllFields()` (code) or `fields: *` (yaml).
If you have specific fields you want omitted from that list, you can use
`addAllFieldsExcept()` (code) or `excludeFields` (yaml).

**Via YAML**:
```yaml
SilverStripe\GraphQL:
schema:
scaffolding:
types:
MyProject\Post:
fields: *
excludeFields: [SecretThing]
```
**... Or with code**:
```php
$scaffolder
->type(Post::class)
->addAllFieldsExcept(['SecretThing'])
```


#### Adding arguments

You can add arguments to basic crud operations, but keep in mind you'll need to use your own
Expand Down Expand Up @@ -1054,29 +1128,6 @@ query {
}
```


#### Whitelisting fields in bulk

If you have a type you want to be fairly well exposed, it can be tedious to add each
field piecemeal. As a shortcut, you can use `addAllFieldsExcept()` (code) or `fieldsExcept` (yaml).

**Via YAML**:
```yaml
SilverStripe\GraphQL:
schema:
scaffolding:
types:
MyProject\Post:
fieldsExcept: [SecretThing]
```
**... Or with code**:
```php
$scaffolder
->type(Post::class)
->addAllFieldsExcept(['SecretThing'])
```

#### Adding arbitrary queries and mutations

Not every operation maps to simple CRUD. For this, you can define custom queries and mutations
Expand Down
Loading

0 comments on commit e4be8ff

Please sign in to comment.