Last active
September 17, 2019 08:02
-
-
Save arminyahya/d9122c32025372d9dfdd3d6590303432 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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