Skip to content

Commit 251dc40

Browse files
committed
Updating documentation.
1 parent 80a9902 commit 251dc40

11 files changed

Lines changed: 173 additions & 433 deletions

File tree

doc/SUMMARY.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,3 @@
2323
## Mutations
2424

2525
* [Mutations](mutations/README.md)
26-
27-
## Advanced
28-
29-
* [Split up schema](advanced/split-schema.md)
30-

doc/advanced/split-schema.md

Lines changed: 0 additions & 191 deletions
This file was deleted.

doc/mutations/README.md

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -142,25 +142,20 @@ To add the resolvers we go to our schema implementation and call the created dat
142142

143143
```php
144144
/**
145-
* {@inheritdoc}
146-
*/
147-
protected function getResolverRegistry() {
148-
149-
...
150-
151-
// Create article mutation.
152-
$registry->addFieldResolver('Mutation', 'createArticle',
153-
$builder->produce('create_article', [
154-
'mapping' => [
155-
'data' => $builder->fromArgument('data'),
156-
],
157-
])
158-
);
159-
160-
...
161-
162-
return $registry;
163-
}
145+
* {@inheritdoc}
146+
*/
147+
protected function getResolverRegistry() {
148+
149+
...
150+
// Create article mutation.
151+
$registry->addFieldResolver('Mutation', 'createArticle',
152+
$builder->produce('create_article')
153+
->map('data', $builder->fromArgument('data'))
154+
);
155+
156+
...
157+
return $registry;
158+
}
164159
```
165160

166161
This mutation can now be called like this :

doc/producers/README.md

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,12 @@ We are telling the schema that we have a new field on the "Article" type called
2525
The following code is an example of how a data producer for a creator field on the Article type can be implemented in code.
2626

2727
```php
28-
$registry->addFieldResolver('Article', 'creator',
29-
$builder->produce('property_path', [
30-
'mapping' => [
31-
'type' => $builder->fromValue('entity:node'),
32-
'value' => $builder->fromParent(),
33-
'path' => $builder->fromValue('field_article_creator.value'),
34-
],
35-
])
36-
);
28+
$registry->addFieldResolver('Article', 'creator',
29+
$builder->produce('property_path')
30+
->map('type', $builder->fromValue('entity:node'))
31+
->map('value', $builder->fromParent())
32+
->map('path', $builder->fromValue('field_article_creator.value'))
33+
);
3734
```
3835

3936
Essentially this is what you need to do every time you want to make a field available in the schema. We tell Drupal where and how to get the data and specify where this maps to.

doc/producers/composing.md

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,10 @@ This can be accomplished using some of the built-in helpers inside the `$builder
66

77
```php
88
$registry->addFieldResolver('Query', 'currentUser', $builder->compose(
9-
$builder->produce('current_user'),
10-
$builder->produce('entity_load', [
11-
'mapping' => [
12-
'type' => $builder->fromValue('user'),
13-
'id' => $builder->fromParent(),
14-
],
15-
])
9+
$builder->produce('current_user'),
10+
$builder->produce('entity_load')
11+
->map('type', $builder->fromValue('user'))
12+
->map('id', $builder->fromParent())
1613
));
1714
```
1815

@@ -24,16 +21,13 @@ What if we need to do some massaging but not necessarily using any data producer
2421

2522
```php
2623
$registry->addFieldResolver('Query', 'currentUser', $builder->compose(
27-
$builder->produce('current_user'),
28-
$builder->produce('entity_load', [
29-
'mapping' => [
30-
'type' => $builder->fromValue('user'),
31-
'id' => $builder->fromParent(),
32-
],
33-
]),
34-
$builder->callback(function ($entity) {
35-
// Here we can do anything we want to the data. We get as a parameter anyting that was returned
36-
// in the previous step.
37-
})
24+
$builder->produce('current_user'),
25+
$builder->produce('entity_load')
26+
->map('type', $builder->fromValue('user'))
27+
->map('id', $builder->fromParent()),
28+
$builder->callback(function ($entity) {
29+
// Here we can do anything we want to the data. We get as a parameter anyting that was returned
30+
// in the previous step.
31+
})
3832
));
3933
```

doc/producers/custom.md

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,10 @@ Lets see how we can consume our newly created data producer :
103103

104104
```php
105105
$registry->addFieldResolver('Query', 'currentUser', $builder->compose(
106-
$builder->produce('current_user'),
107-
$builder->produce('entity_load', [
108-
'mapping' => [
109-
'type' => $builder->fromValue('user'),
110-
'id' => $builder->fromParent(),
111-
],
112-
])
106+
$builder->produce('current_user'),
107+
$builder->produce('entity_load')
108+
->map('type', $builder->fromValue('user'))
109+
->map('id', $builder->fromParent())
113110
));
114111
```
115112

doc/queries/README.md

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,10 @@ type Article implements NodeInterface {
1717
We now need to resolve the title field via a data producer which is already provided by the `entity_label` module. This will give us the label of an entity:
1818

1919
```php
20-
$registry->addFieldResolver('Article', 'title',
21-
$builder->produce('entity_label', [
22-
'mapping' => [
23-
'entity' => $builder->fromParent(),
24-
],
25-
])
26-
);
20+
$registry->addFieldResolver('Article', 'title',
21+
$builder->produce('entity_label')
22+
->map('entity' => $builder->fromParent())
23+
);
2724
```
2825

2926
We can now run a query like this:

0 commit comments

Comments
 (0)