Skip to content

Instantly share code, notes, and snippets.

@shrirambalakrishnan
Created November 5, 2018 18:53
Show Gist options
  • Save shrirambalakrishnan/9b9e879e7ba11a2f9c8e5a51d9dcc3bc to your computer and use it in GitHub Desktop.
Save shrirambalakrishnan/9b9e879e7ba11a2f9c8e5a51d9dcc3bc to your computer and use it in GitHub Desktop.
# 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