There’s only one mutation left to be added: allowing users to vote for links. This follows a familiar path:
This would create our vote model, which is used to represent an user vote.
class Vote < ActiveRecord::Base belongs_to :user, validate: true belongs_to :link, validate: true end
Votes would be created by a mutation and represented by a GraphQL type.
Done! Now you can vote on links:
You can already create votes, but there’s currently no way to fetch them yet! A typical use case would be to get votes for each link using the existing
For that to work, you just have to change the
LinkType to have references to its votes.
Now every link has access to its votes. But GraphQL still doesn’t know about those votes.
Now you can see all votes for links:
Following these same steps, you could also add a new field to make it easier to find all the votes made by the same user.
Now you can see all votes for users:
Learn best practices for validation of input arguments and implementing error handling in GraphQL with Ruby.