-
-
Save hash32bot/bbd8f6a5de3c5bbed163882c0242811b to your computer and use it in GitHub Desktop.
Speaker Mutations - resolve - [Post] GraphQL with Sinatra (Ruby) - Part 2- Mutations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'graphql' | |
require_relative 'base_mutation' | |
class Mutations::CreateSpeaker < Mutations::BaseMutation | |
description 'Creates a speaker' | |
# input arguments | |
def resolve(name:, bio:, twitter_handle:, talk_title:) | |
speaker = Speaker.new( | |
name: name, | |
bio: bio, | |
twitter_handle: twitter_handle, | |
talk_title: talk_title | |
) | |
if speaker.save | |
{ | |
success: true, | |
errors: [] | |
} | |
else | |
{ | |
success: false, | |
errors: speaker.errors.full_messages | |
} | |
end | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment