Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
joaogarin committed Jan 7, 2018
0 parents commit 789c9c6
Show file tree
Hide file tree
Showing 5 changed files with 210 additions and 0 deletions.
7 changes: 7 additions & 0 deletions graphql_custom_mutations.info.yml
@@ -0,0 +1,7 @@
name: Custom graphql mutations
type: module
description: A collection of custom GraphQL Mutations
core: 8.x
package: Custom
dependencies:
- graphql
116 changes: 116 additions & 0 deletions readme.md
@@ -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
}
}
}
}
```
21 changes: 21 additions & 0 deletions src/Plugin/GraphQL/InputTypes/ClientInput.php
@@ -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 {

}
39 changes: 39 additions & 0 deletions src/Plugin/GraphQL/Mutations/AddClient.php
@@ -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']
];
}
}
27 changes: 27 additions & 0 deletions src/Plugin/GraphQL/Mutations/DeleteClient.php
@@ -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 {

}

0 comments on commit 789c9c6

Please sign in to comment.