Skip to content

joaogarin/graphql_custom_mutations

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 

Repository files navigation

Drupal custom graphql mutation example

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

Installation

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
      }
    }
  }
}

Credits :

This module was implemented based on https://github.com/justinlevi/graphql_custom_mutation, thanks Justin winter

About

Drupal graphql custom mutation example

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages