Add Data Producer plugins for creating, updating and deleting entities.#1231
Add Data Producer plugins for creating, updating and deleting entities.#1231Cryt1c wants to merge 11 commits intodrupal-graphql:8.x-4.xfrom Cryt1c:8.x-4.x
Conversation
| $field_access_errors = []; | ||
| foreach ($values as $field_name => $value) { | ||
| $create_access = $entity->get($field_name)->access('edit', NULL, TRUE); | ||
| if (!$create_access->isALlowed()) { |
There was a problem hiding this comment.
| if (!$create_access->isALlowed()) { | |
| if (!$create_access->isAllowed()) { |
There was a problem hiding this comment.
| $context->addCacheableDependency($access); | ||
| if (!$access->isAllowed()) { | ||
| return [ | ||
| 'was_successful' => FALSE, |
There was a problem hiding this comment.
would 'result' be a better name for this than 'was_successful'?
There was a problem hiding this comment.
| // things such as the owner of the entity or the ID of the entity. | ||
| $update_fields = array_filter($values, function (string $field_name) use ($entity, $context) { | ||
| if (!$entity->hasField($field_name)) { | ||
| throw new \Exception("Could not update '$field_name' field, since it does not exist on the given entity."); |
There was a problem hiding this comment.
Instead of throwing an exception, should this keep track of errors and return ['errors'=>] like other code paths in this producer?
There was a problem hiding this comment.
|
The author of this PR asked to fork it and I said it was a good idea. I don't have the time to push it forward any further. |
|
From building my own mutations for creation, updating and deletion I'm wondering if these producers should be in the module or whether they're better suited in a contrib module or in the documentation as examples. I would expect most GraphQL APIs to be more complex and more specifically tailored then simply exposing an entire entity for creation/update/deletion. |
|
@Kingdutch after fleshing our API out a bit more I tend to agree with you here. Maybe we just take some of the documentation from Sam on #1212 and commit that instead? |
Continuation of #1212