Skip to content

Instantly share code, notes, and snippets.

@arminyahya
Last active September 17, 2019 08:02
Show Gist options
  • Save arminyahya/d9122c32025372d9dfdd3d6590303432 to your computer and use it in GitHub Desktop.
Save arminyahya/d9122c32025372d9dfdd3d6590303432 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
}
type User {
id: Int
password: String
}
`);
var getMovie = function(args) {
var id = args.id;
return MoviesList.filter(movie => {
return movie.id == id;
})[0];
}
var getMovies = function(args, req) {
if(!req.isAuth) {
throw new Error('Unauthenticated');
}
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