Skip to content

Ellebkey/football-data-graphql-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Football Data GraphQL API

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.

Technology Stack

  • Node.js
  • PostgreSQL
  • GraphQL (Apollo Server)
  • Docker & Docker Compose
  • Sequelize ORM

Quick Start

  1. Clone the repository

  2. Create a .env file 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
  1. Start the application:
docker-compose up --build

The API will be available at:

API Documentation

REST Endpoints

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

GraphQL Endpoints

Queries

  1. 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
}
  1. 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"
}

Mutations

  1. Import League
mutation ImportLeague($leagueCode: String!) {
  importLeague(leagueCode: $leagueCode) {
    id
    name
    code
    areaName
    teams {
      name
      tla
      players {
        name
        position
      }
      coach {
        name
      }
    }
  }
}

# Variables:
{
  "leagueCode": "PL"
}

Data Model

Competition

  • id: ID
  • name: String
  • code: String
  • areaName: String
  • teams: [Team]

Team

  • id: ID
  • name: String
  • tla: String
  • shortName: String
  • areaName: String
  • address: String
  • players: [Player]
  • coach: Coach
  • competitions: [Competition]

Player

  • id: ID
  • name: String
  • position: String
  • dateOfBirth: String
  • nationality: String
  • team: Team

Coach

  • id: ID
  • name: String
  • dateOfBirth: String
  • nationality: String
  • team: Team

Development

Running in Development Mode

The project is configured with hot-reloading enabled:

  1. Code changes will automatically restart the server
  2. GraphQL schema changes are reflected immediately
  3. Database changes require manual sync

Database Management

To reset the database:

# Stop containers
docker-compose down

# Remove volume
docker volume rm your_project_postgres_data

# Restart
docker-compose up --build

Testing the API

  1. First, import a league:
mutation { importLeague(leagueCode: "PL") { name } }
  1. Then query the data:
query {
  players(leagueCode: "PL", tla: "ARS") {
    name
    position
  }
}

Common League Codes

  • PL: Premier League
  • CL: Champions League
  • BL1: Bundesliga
  • SA: Serie A
  • PD: La Liga

Rate Limiting

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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors