This code provides example on mutation on a custom content type "Client" for Drupal using Drupal GraphQL
For this example I assume a content type called “Client” exists in the Drupal installation (just setup a content type with name Client, machine name should be client). Also this content type should have some fields created :
email telephone
Put this inside your modules/custom folder and go to extensions in your drupal site and enable the module. Or run :
drush en graphql_custom_mutations
ADD MUTATION
mutation {
addClient(input:{title:"Client name", email:"hello@world.com"}){
entity{
...on NodeClient {
nid,
title,
email
}
}
}
}
RESULT
{
"data": {
"addClient": {
"entity": {
"nid": 111,
"title": "Client name",
"email": "hello@world.com"
}
}
}
}
DELETE MUTATION
mutation {
deleteClient(id:111){
entity{
...on NodeClient {
nid
}
}
}
}
RESULT
{
"data": {
"deleteClient": {
"entity": {
"nid": 111
}
}
}
}
This module was implemented based on https://github.com/justinlevi/graphql_custom_mutation, thanks Justin winter