Capstone Project at the Turing School of Software and Design. This is the backend API for that project.
Habit Golf is the capstone project for a team composed of members of both the Back-End Engineering Program and the Front-End Engineering Program at the Turing School of Software & Design. Habit Golf is a full-stack application built using a Rails API backend using GraphQL and a React frontend. This repo is the Habit Golf API. You can find the frontend repo here.
To install this project on your local machine:
- Clone the repo to your machine:
git clone git@github.com:lptaylor/habit_golf_be.git
-
Change into the new directory.
-
Install Ruby(2.4.1) and Rails 5.2.3 on your local machine.
-
Install bundler
- Install dependencies:
bundle install
To run the code locally, use the following command to start the development server:
rails s
Once running, point your browser to:
http://localhost:3000/graphiql
This will bring up the IDE to allow you to send queries locally.
As with all GraphQL applications there is only a single endpoint found at https://habit-golf-api.herokuapp.com/graphql.
Additionally, a CORS package has been added to allow you to consume this API without CORS errors.
The frontend for this app and it's documentation can be found at https://github.com/ericweissman/habit-golf-fe.
All responses return a JSON object with the queried fields available.
These queries can be run in POSTMAN to check they are working in the production environment by running the development server as described above by using the graphiql IDE and sending a request with the network developer tools tab open. If you click on the request and right clicking (Windows) or ctrl+click (Mac) and copying the request as cURL. From there open POSTMAN and click import paste the raw text into the box and set the request type to POST and the url from http://localhost:3000/graphiql to https://habit-golf-api.herokuapp.com/graphql).
There is an optional argument for players query if none given will return all players.
{players(*optional argument ids: [Array of playerIds]){
id
name
}
}
There are two optional arguments for shots query if none given will return all shots. rating is an Integer.
{shots(*optional argument ids: [Array of shotIds] OR rating: [Array of shotRatings]){
id
rating
}
}
There are two optional arguments for clubs query if none given will return all clubs. styleOfClub is an Integer.
{clubs(*optional argument ids: [Array of clubIds] OR rating: [Array of styleOfClubs]){
id
styleOfClub
}
}
The playerId argument is required.
{
playerStats(playerId: 1){
playerId
greatShotPercentage
hookPercentage
pullPercentage
pushPercentage
slicePercentage
todayGreatShotPercentage
todayHookPercentage
todayPullPercentage
todayPushPercentage
todaySlicePercentage
}
}
Same optional arguments apply as the basic queries but you can also grab shots by their association with their clubs.
{clubs(*optional argument ids: [Array of clubIds] OR rating: [Array of styleOfClubs]){
id
styleOfClub
shots{
id
rating
}
}
}
All Fields are required!
mutation{
createPlayer(name: "someName", email: "someEmail", password: "somePassword")
{
id
name
}
}
All Fields are required!
mutation{
createShot(clubId: 1, rating: 1, playerId: 1)
{
id
rating
clubId
playerId
}
}
All Fields are required!
mutation{
deleteShot(id:1)
{
id
}
}
If you wish to contribute to this repo, you are welcome to make a PR and we would be happy to review it. Please use the Pull Request Template that has been included with all appropriate fields filled in.