Giter VIP home page Giter VIP logo

movie-api's Introduction

Movie API

Introduction

GraphQL wrapper for the The Movie Database API.

CI/CD using Circle CI

Deployed to Heroku at https://eu-movie-api.herokuapp.com/

Installation

In project root run the following:

echo API_KEY={API_KEY} > .env

Replacing {API_KEY} with a valid api key created at the Movie Database API

echo DB_PWD={DB_PWD} >> .env

Replacing {DB_PWD} with the password created for user dbUser on MongoDB Atlas Account

Run npm i

Run & Build Locally

Run npm start

Browse to GraphQL Playground running locally and test by running the following queries exposed below.

Any changes to the code using this method force a rebuild

Run & Build with Docker

Ensure Docker is installed locally.

For MacOS review the following documentation

Run npm run start:docker

Browse to GraphQL Playground running locally

GraphQL Queries

  1. Get Trending Movies
 query {
    trending (imageSize: "w154", period: week) {
      id
      title
      overview
      voteAverage
      popularity
      voteCount
      releaseDate
      originalLanguage
      images {
        poster
        backDrop
      }
    }
  }

period is optional and defaults to day Options are day|week

  1. Get Popular Movies
 query {
    popular(imageSize: "w154") {
      id
      title
      overview
      voteAverage
      popularity
      voteCount
      releaseDate
      originalLanguage
      images {
        poster
        backDrop
      }
    }
  }
  1. Get Image Configuration
query {
    imageConfiguration {
      baseUrl
      imageSizes
    }
  }
  1. Search Movies
query {
  search(filter:{ searchText:"sharknado"}, page:1) {
    totalCount
    page
    noOfPages
    edges {
      node {
        id
        title
        overview
        voteAverage
        popularity
        voteCount
        releaseDate
        originalLanguage
        images {
          poster
          backDrop
        }
      }
    }
    pageInfo {
      hasNextPage
      hasPreviousPage
    }
  }
}
  1. Get a Movie By Id
 query {
    movie(id: 545609, showCast: $showCast, creditsLimit:$creditsLimit) {
      id
      title
      overview
      voteAverage
      popularity
      voteCount
      releaseDate
      originalLanguage
      runTime
      images {
        poster
        backDrop
      }
      genres {
        id
        name
      }
      homePage,
      similar {
        id
        title
      }
      recommended {
        id
        title
      }
      certifications {
        countryCode
        certification
      }
      credits {
        crew {
          id
          name
          job
        }
        cast @include(if: $showCast) {
          id
          character
          person {
            id
            name
            imageUrl
          }
        }
    }
  }

creditslimit restricts the limit for cast and crew members returned. Currently defaults to 100.

showCast defines if cast should be returned in the query.

  1. Get a Person By Id
query{
  person(imageSize: "w154", id: 10990) {
    id
    name
    biography
    birthDate
    deathDate
    age
    imageUrl
    placeOfBirth
    credits {
      id
      character
      movie {
        title
        overview
        voteAverage
        popularity
        voteCount
        releaseDate
        originalLanguage
        images {
          poster
          backDrop
        }
      }
    }
  }
}

Recommended and similar movies can contain an array of Movie objects.

The above search pagination is a hybrid based on standard relay cursor pagination and limitations in the current MovieDB REST API.

The MovieDB REST API has a fixed page size of 20 records and requires a page number to be passed as part of the query. This therefore restricts the implementation of a pure cursor based pagination in relation to performance.

Notes

imageSize parameter can be obtained by querying the imageConfiguration end point and selecting an entry from the imageSizes property.

If no imageSizes argument is passed this defaults to original

Setting up Circle CI

Add the following Environment Variables to movie api project settings:

API_KEY - MovieDb API Key
HEROKU_API_KEY - Heroku API Key
HEROKU_APP_NAME - eu-movie-api

Add additional SSH Key for github

Hostname: github.com
Private key: see details below on how to create this

SSH Keys

As part of deployment via Circle CI need to create a ssh key to push changes to github

ssh-keygen -m PEM -t rsa -C "[email protected]"

Press enter for each option (no passphrase required as this will encrypt the key)

A key is generated in the following file id_rsa.pub (public) and id_rsa (private)

Run ls -al ~/.ssh to see all keys created

Copy key to clipboard pbcopy < ~/.ssh/id_rsa.pub

Public key needs to be added to gitHub

Copy key to clipboard pbcopy < ~/.ssh/id_rsa

Private key needs to be added to Circle Ci

Scheduler

A scheduler is run on a daily basis to store the current featured movie. The following task is run at midnight using the Heroku Scheduler add-on.

npm run tasks

movie-api's People

Contributors

dependabot[bot] avatar markaphillips avatar martysavva avatar mediasplash avatar

Watchers

 avatar  avatar

movie-api's Issues

Add Age to Person

calculated from DOB if no DOB listed - return null
if date of death listed - age should be based on this date

Improve Circle ci workflow

  1. Git Tag a deployment after Docker build and deploy is completed - finding that errors can occur in the Docker build and the release is tagged
  2. Review [ci skip] to see if there are other method to prevent a build showing up in circle - i.e not run - showing Tag is useful but not the following : Release version 1.0.5 [ci skip]
  3. There is an issue when PRs are run concurrently - version no and tags are reused which causes an error - review how this can be improved

Add mongoDB to be able to store additional data outside of MovieDB

mongoDb Atlas - initial prerequisite to build a simple mutation in GraphQL that stores the featured Movie to allow for a history

Can use mongoDb timestamp to stored history - and the movieId

at the beginning of every day a cron job is run that updates the history collection in mongoDB with the above data

Extend API search to include pagination

Includes - last param - review before and after
set hasPreviousPage and hasNextPage
ensure correct records obtained when passing different params in relation to paging

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.