Straightforward implementation of a Hackernews clone using Ruby on Rails and GraphQL from https://www.howtographql.com/graphql-ruby/0-introduction/. Features include creating accounts, creating and searching for links, as well as up voting links.
Having gained some exposure to REST APIs, I have wanted to start digging into and learning about GraphQL, given increased popularity and growing community. This marks one of the first of many future GraphQL projects!
To install and test locally yourself:
- Clone this repo
- Install the required gems by running
$ bundle install
- Start the server
$ rails server
- Open a browser and open the in-browser GraphQL IDE at http://localhost:3000/graphiql
Once in the GraphQL IDE, there are a number of different queries and mutations which can be run to test any of the functionality. Some examples...
List first 10 links, containing "example":
{
allLinks(first: 10, filter: {descriptionContains: "example"}) {
id
url
description
createdAt
postedBy {
id
name
}
}
}
Create new user:
mutation {
createUser(
name: "Radoslav Stankov",
authProvider: {
credentials: { email: "[email protected]", password: "123456" }
}
) {
id
email
name
}
}
Create new user token:
mutation {
signinUser(credentials: {email: "[email protected]", password: "123456"}) {
token
user {
id
email
name
}
}
}
Create new link:
mutation {
createLink(url:"http://example.com", description:"Example") {
id
url
description
postedBy {
id
name
}
}
}
Create new vote:
mutation {
createVote(linkId:"TGluay0yMQ==") {
user {
id
name
}
link {
id
url
description
}
}
}