Drupal graphql custom mutation example
Switch branches/tags
Nothing to show
Clone or download
Latest commit 9de436f Jan 7, 2018
Permalink
Failed to load latest commit information.
src/Plugin/GraphQL initial commit Jan 7, 2018
graphql_custom_mutations.info.yml initial commit Jan 7, 2018
readme.md docs(readme): Credits Jan 7, 2018

readme.md

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