Skip to content

Instantly share code, notes, and snippets.

@arminyahya
Last active November 11, 2021 03:19
Show Gist options
  • Save arminyahya/a8bc6c216c277eb5c15c9b14e31a7996 to your computer and use it in GitHub Desktop.
Save arminyahya/a8bc6c216c277eb5c15c9b14e31a7996 to your computer and use it in GitHub Desktop.
var { buildSchema } = require('graphql');
var { MoviesList } = require('./movie-list');
var schema = buildSchema(`
type Query {
movieInfo(id: Int!): Movie
movieList(rate: String): [Movie]
},
type Movie {
id: Int
title: String
rate: String
year: Int
}
`);
var getMovie = function(args) {
var id = args.id;
return MoviesList.filter(movie => {
return movie.id == id;
})[0];
}
var getMovies = function(args) {
if (args.rate) {
var rate = args.rate;
return MoviesList.filter(movie => movie.rate === rate);
} else {
return MoviesList;
}
}
var root = {
movieInfo: getMovie,
movieList: getMovies,
};
module.exports = {
schema: schema,
root: root
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment