Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 789c9c6
Showing
5 changed files
with
210 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
name: Custom graphql mutations | ||
type: module | ||
description: A collection of custom GraphQL Mutations | ||
core: 8.x | ||
package: Custom | ||
dependencies: | ||
- graphql |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
A simple example of a basic page mutation | ||
|
||
|
||
|
||
ADD MUTATION | ||
```$xslt | ||
mutation { | ||
addPage(input:{title:"Hello", body:"World"}){ | ||
entity{ | ||
...on NodePage { | ||
nid | ||
title | ||
body{ | ||
value | ||
} | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
|
||
RESULT | ||
|
||
```$xslt | ||
{ | ||
"data": { | ||
"addPage": { | ||
"entity": { | ||
"nid": 111, | ||
"title": "Hello", | ||
"body": { | ||
"value": "World" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
|
||
|
||
--- | ||
|
||
|
||
UPDATE MUTATION | ||
|
||
```$xslt | ||
mutation { | ||
updatePage(id:110, input:{title:"Justin"}){ | ||
entity{ | ||
...on NodePage { | ||
nid | ||
title | ||
body{ | ||
value | ||
} | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
|
||
|
||
RESULT | ||
```$xslt | ||
{ | ||
"data": { | ||
"updatePage": { | ||
"entity": { | ||
"nid": 111, | ||
"title": "Justin", | ||
"body": null | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
|
||
|
||
--- | ||
|
||
|
||
DELETE MUTATION | ||
```$xslt | ||
mutation { | ||
deletePage(id:111){ | ||
entity{ | ||
...on NodePage { | ||
nid | ||
title | ||
body{ | ||
value | ||
} | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
|
||
|
||
RESULT | ||
|
||
```$xslt | ||
{ | ||
"data": { | ||
"deletePage": { | ||
"entity": { | ||
"nid": 111, | ||
"title": "Justin", | ||
"body": null | ||
} | ||
} | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
namespace Drupal\graphql_custom_mutations\Plugin\GraphQL\InputTypes; | ||
|
||
use Drupal\graphql\Plugin\GraphQL\InputTypes\InputTypePluginBase; | ||
|
||
/** | ||
* Client input type. | ||
* | ||
* @GraphQLInputType( | ||
* id = "client_input", | ||
* name = "ClientInput", | ||
* fields = { | ||
* "title" = "String", | ||
* "email" = "String", | ||
* } | ||
* ) | ||
*/ | ||
class ClientInput extends InputTypePluginBase { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
namespace Drupal\graphql_custom_mutations\Plugin\GraphQL\Mutations; | ||
|
||
|
||
use Drupal\graphql\Annotation\GraphQLMutation; | ||
use Drupal\graphql\GraphQL\Type\InputObjectType; | ||
use Drupal\graphql\Plugin\GraphQL\InputTypes\InputTypePluginBase; | ||
use Drupal\graphql_core\Plugin\GraphQL\Mutations\Entity\CreateEntityBase; | ||
use Youshido\GraphQL\Execution\ResolveInfo; | ||
|
||
|
||
/** | ||
* A Simple Client mutation. | ||
* | ||
* @GraphQLMutation( | ||
* id = "add_client", | ||
* entity_type = "node", | ||
* entity_bundle = "client", | ||
* secure = true, | ||
* name = "addClient", | ||
* type = "EntityCrudOutput", | ||
* arguments = { | ||
* "input" = "ClientInput" | ||
* } | ||
* ) | ||
*/ | ||
class AddClient extends CreateEntityBase { | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function extractEntityInput(array $inputArgs, InputObjectType $inputType, ResolveInfo $info) { | ||
return [ | ||
'title' => $inputArgs['title'], | ||
'email' => $inputArgs['email'] | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
namespace Drupal\graphql_custom_mutations\Plugin\GraphQL\Mutations; | ||
|
||
|
||
use Drupal\graphql\Annotation\GraphQLMutation; | ||
use Drupal\graphql_core\Plugin\GraphQL\Mutations\Entity\DeleteEntityBase; | ||
|
||
|
||
/** | ||
* A Simple Client mutation. | ||
* | ||
* @GraphQLMutation( | ||
* id = "delete_client", | ||
* entity_type = "node", | ||
* entity_bundle = "client", | ||
* secure = true, | ||
* name = "deleteClient", | ||
* type = "EntityCrudOutput", | ||
* arguments = { | ||
* "id" = "Int" | ||
* } | ||
* ) | ||
*/ | ||
class DeleteClient extends DeleteEntityBase { | ||
|
||
} |