This project provides a GraphQL API that interfaces with football-data.org to import and serve football competition data. It stores the data locally in PostgreSQL and exposes it through both GraphQL and REST endpoints.
- Node.js
- PostgreSQL
- GraphQL (Apollo Server)
- Docker & Docker Compose
- Sequelize ORM
-
Clone the repository
-
Create a
.envfile in the root directory:
# Database
DB_USER=user
DB_PASSWORD=password
DB_NAME=dbname
DB_PORT=5432
DB_HOST=postgres
# Football API
FOOTBALL_API_TOKEN=your_token_here- Start the application:
docker-compose up --buildThe API will be available at:
- GraphQL Playground: http://localhost:3000/graphql
- REST endpoints: http://localhost:3000
These endpoints are provided for testing the football-data.org API directly:
GET /competition
Returns Premier League competition data
Response: Competition details from football-data.org
GET /teams
Returns Premier League teams
Response: List of teams in the Premier League
GET /squad
Returns Arsenal's squad (team ID: 57)
Response: Team squad details including players and coach
- Players Query
query GetPlayers($leagueCode: String!, $tla: String) {
players(leagueCode: $leagueCode, tla: $tla) {
id
name
position
dateOfBirth
nationality
team {
name
tla
}
}
}
# Variables:
{
"leagueCode": "PL",
"tla": "ARS" # Optional - Team's three-letter code
}- Team Query
query GetTeam($name: String!) {
team(name: $name) {
id
name
tla
shortName
areaName
players {
name
position
}
coach {
name
nationality
}
competitions {
name
code
}
}
}
# Variables:
{
"name": "Arsenal"
}- Import League
mutation ImportLeague($leagueCode: String!) {
importLeague(leagueCode: $leagueCode) {
id
name
code
areaName
teams {
name
tla
players {
name
position
}
coach {
name
}
}
}
}
# Variables:
{
"leagueCode": "PL"
}- id: ID
- name: String
- code: String
- areaName: String
- teams: [Team]
- id: ID
- name: String
- tla: String
- shortName: String
- areaName: String
- address: String
- players: [Player]
- coach: Coach
- competitions: [Competition]
- id: ID
- name: String
- position: String
- dateOfBirth: String
- nationality: String
- team: Team
- id: ID
- name: String
- dateOfBirth: String
- nationality: String
- team: Team
The project is configured with hot-reloading enabled:
- Code changes will automatically restart the server
- GraphQL schema changes are reflected immediately
- Database changes require manual sync
To reset the database:
# Stop containers
docker-compose down
# Remove volume
docker volume rm your_project_postgres_data
# Restart
docker-compose up --build- First, import a league:
mutation { importLeague(leagueCode: "PL") { name } }- Then query the data:
query {
players(leagueCode: "PL", tla: "ARS") {
name
position
}
}- PL: Premier League
- CL: Champions League
- BL1: Bundesliga
- SA: Serie A
- PD: La Liga
The application implements rate limiting to respect the football-data.org API restrictions:
- 10 calls per minute for free tier
- Automatic request throttling
- Error handling for rate limit exceeded