Skip to content

JenniferDwinall/graphql-apollo-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Description

This is a GraphQL application that supports GQL queries and traditional REST endpoints.

Getting Started

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

REST Endpoints

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.

API Endpoints

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

Teams

Returns all teams

GET /sport/teams

query {
  all_teams {id,name,city,full_name,abbrev}
}

GraphIQLLink

curl \
  -X GET \
  -H "Content-Type: application/json" \
  http://localhost:3000/nba/teams

Returns just the team object of the id specified

GET /sport/teams/:id

query ($id: Int) {
  team (id: $id) {id,city,name,full_name,abbrev}
}
{
  "id": 1
}

GraphIQLLink

curl \
  -X GET \
  -H "Content-Type: application/json" \
  http://localhost:3000/nba/teams/1

Players

Returns all player

GET /sport/players

query {
  all_players {id,name,team_id}
}

GraphIQLLink

curl \
  -X GET \
  -H "Content-Type: application/json" \
  http://localhost:3000/nba/players

Returns the player object of the id specified

GET /sport/player/:id

query ($id: Int) {
  player(id: $id) {id,name,team_id}
}
{
  "id": 1
}

GraphIQLLink

curl \
  -X GET \
  -H "Content-Type: application/json" \
  http://localhost:3000/nba/player/1

Returns all players who played (i.e. had player stats) on a specific date (date format: MMDDYYYY)

GET /sport/players?date=:date

query ($date: Date) {
  players(date: $date) {id,name,team_id}
}
{
  "date":"1/1/2016"
}

GraphIQL Link

curl \
  -X GET \
  -H "Content-Type: application/json" \
  http://localhost:3000/nba/players?date=01012016

Returns all player stats objects for the specified player

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
}

GraphIQL Link

curl \
  -X GET \
  -H "Content-Type: application/json" \
  http://localhost:3000/nba/player/1/stats

Games

Returns all games (with scores)

GET /sport/games

query {
  all_games {id,home_team_id,away_team_id,date}
}

GraphIQL Link

curl \
  -X GET \
  -H "Content-Type: application/json" \
  http://localhost:3000/nba/games

Returns all games for a given date (date format: MMDDYYYY)

GET /sport/games?date=:date

query($date: Date) {
  games(date: $date) {id,home_team_id,away_team_id,date}
}
{
  "date":"1/1/2016"
}

GraphIQL Link

curl \
  -X GET \
  -H "Content-Type: application/json" \
  http://localhost:3000/nba/games?date=01012016

Returns the game objects of the id specified

GET /sport/games/:id

query ($id: Int) {
  game(id: $id) {id,home_team_id,away_team_id,date}
}
{
  "id": 1
}

GraphIQL Link

curl \
  -X GET \
  -H "Content-Type: application/json" \
  http://localhost:3000/nba/games/1