Created
November 5, 2018 18:53
-
-
Save shrirambalakrishnan/9b9e879e7ba11a2f9c8e5a51d9dcc3bc to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# app/graphql/resolvers/create_movie.rb | |
class Resolvers::CreateMovie < GraphQL::Function | |
# arguments passed as "args" | |
argument :name, !types.String | |
argument :year, types.String | |
argument :genre, types.String | |
# return type from the mutation | |
type Types::MovieType | |
# the mutation method | |
def call(_obj, args, _ctx) | |
movie_params = { name: args[:name], year: args[:year], genre: args[:genre] } | |
movie = Movie.new(movie_params) | |
movie.save! | |
ActionCable.server.broadcast( | |
'movies', | |
name: movie.name, | |
year: movie.year, | |
genre: movie.genre | |
) | |
movie | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment