This is a GraphQL application that supports GQL queries and traditional REST endpoints.
NVM was used to manage node and yarn versions. You will need to install the versions of yarn and node set in the package.json file, engines section.
nvm use
To install dependencies:
yarn
If you would like to add additional dependencies, simply run:
yarn add --save <package-name>
yarn add --save --dev <package-name>
To run the test suite:
yarn test
To run code linting:
yarn lint
yarn lint-fix
To build and run the app in dev mode:
yarn dev
To build the production deployment:
yarn build
To run the production deployment:
yarn start
To view the application:
http://localhost:3000
The main entry point for this application is server.js. In this file, I have configured a "sport" endpoint with the following line of code:
import nbaRouter from './router/nba'
graphQLServer.use('/nba', nbaRouter)
If you want to reuse these secondary endpoints for another sport, use this router with another endpoint:
import ncaaRouter from './router/nba'
graphQLServer.use('/ncaa', ncaaRouter)
When a request is made to one of these traditional REST endpoints, it is translated into a GraphQL query and send to the /graphql endpoint.
http://localhost:3000/nba/teams
http://localhost:3000/nba/teams/1
http://localhost:3000/nba/players
http://localhost:3000/nba/players?date=01012016
http://localhost:3000/nba/player/1
http://localhost:3000/nba/player/1/stats
http://localhost:3000/nba/games
http://localhost:3000/nba/games?date=01012016
http://localhost:3000/nba/games/1
GET /sport/teams
query {
all_teams {id,name,city,full_name,abbrev}
}
curl \
-X GET \
-H "Content-Type: application/json" \
http://localhost:3000/nba/teams
GET /sport/teams/:id
query ($id: Int) {
team (id: $id) {id,city,name,full_name,abbrev}
}
{
"id": 1
}
curl \
-X GET \
-H "Content-Type: application/json" \
http://localhost:3000/nba/teams/1
GET /sport/players
query {
all_players {id,name,team_id}
}
curl \
-X GET \
-H "Content-Type: application/json" \
http://localhost:3000/nba/players
GET /sport/player/:id
query ($id: Int) {
player(id: $id) {id,name,team_id}
}
{
"id": 1
}
curl \
-X GET \
-H "Content-Type: application/json" \
http://localhost:3000/nba/player/1
GET /sport/players?date=:date
query ($date: Date) {
players(date: $date) {id,name,team_id}
}
{
"date":"1/1/2016"
}
curl \
-X GET \
-H "Content-Type: application/json" \
http://localhost:3000/nba/players?date=01012016
GET /sport/player/:id/stats
query ($id: Int) {
player_stats(id: $id) {id,game_id,player_id,team_id,points,assists,rebounds,nerd}
}
{
"id":1
}
curl \
-X GET \
-H "Content-Type: application/json" \
http://localhost:3000/nba/player/1/stats
GET /sport/games
query {
all_games {id,home_team_id,away_team_id,date}
}
curl \
-X GET \
-H "Content-Type: application/json" \
http://localhost:3000/nba/games
GET /sport/games?date=:date
query($date: Date) {
games(date: $date) {id,home_team_id,away_team_id,date}
}
{
"date":"1/1/2016"
}
curl \
-X GET \
-H "Content-Type: application/json" \
http://localhost:3000/nba/games?date=01012016
GET /sport/games/:id
query ($id: Int) {
game(id: $id) {id,home_team_id,away_team_id,date}
}
{
"id": 1
}
curl \
-X GET \
-H "Content-Type: application/json" \
http://localhost:3000/nba/games/1