with nicolas, thank you!

  • db.js
import fetch from "node-fetch";

const API_URL =
  "https://yts.lt/api/v2/list_movies.json?limit=50&minimum_rating=9";

export const getMovies = (limit, rating) => {
  let REQUEST_URL = API_URL;
  if (limit > 0) {
    REQUEST_URL += `limit=${limit}`;
  }
  if (rating > 0) {
    REQUEST_URL += `&minimum_rating=${rating}`;
  }
  return fetch(REQUEST_URL)
    .then(res => res.json())
    .then(json => json.data.movies);
};
  • resolvers.js
import { getMovies } from "./db";

const resolvers = {
  Query: {
    movies: (_, { limit, rating }) => getMovies(limit, rating)
  }
};

export default resolvers;
  • schema.graphql
type Movie {
  id: Int!
  title: String!
  rating: Float!
  summary: String
  language: String
  medium_cover_image: String
}

type Query {
  movies(limit: Int, rating: Float): [Movie]!
}