Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[Question] Is there any example on how to create webform mutation? #10

Open
sixtyniner-official opened this issue Mar 18, 2019 · 0 comments

Comments

@sixtyniner-official
Copy link

Hi all,

I'm trying to send email using mutation and webform module. For now I've created EmailInput.php as InputType and SendEmail.php as Mutations, basically just copy code of CreateArticle.php and ArticleInput.php

I'm able to create new Webform Submission, but not sure how to send and save values, so submissions are empty.

SendEmail.php

<?php

namespace Drupal\graphql_examples\Plugin\GraphQL\Mutations;

use Drupal\graphql\Annotation\GraphQLMutation;
use Drupal\graphql\GraphQL\Execution\ResolveContext;
use Drupal\graphql_core\Plugin\GraphQL\Mutations\Entity\CreateEntityBase;
use GraphQL\Type\Definition\ResolveInfo;

/**
 * Simple mutation for creating a new article node.
 *
 * @GraphQLMutation(
 *   id = "send_email",
 *   entity_type = "webform_submission",
 *   entity_bundle = "sidebar_contact",
 *   secure = true,
 *   name = "sendEmail",
 *   type = "EntityCrudOutput!",
 *   arguments = {
 *     "input" = "EmailInput"
 *   }
 * )
 */
class SendEmail extends CreateEntityBase {

  /**
   * {@inheritdoc}
   */
  protected function extractEntityInput(
    $value,
    array $args,
    ResolveContext $context,
    ResolveInfo $info
  ) {
    return [
      'email' => $args['input']['email']
    ];
  }
}

EmailInput.php

<?php

namespace Drupal\graphql_examples\Plugin\GraphQL\InputTypes;

use Drupal\graphql\Plugin\GraphQL\InputTypes\InputTypePluginBase;

/**
 * The input type for article mutations.
 *
 * @GraphQLInputType(
 *   id = "email_input",
 *   name = "EmailInput",
 *   fields = {
 *     "email" = "String",
 *   }
 * )
 */
class EmailInput extends InputTypePluginBase {

}

form

Any help is appreciated.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant