├── .babelrc ├── .github └── FUNDING.yml ├── .gitignore ├── .npmrc ├── LICENSE ├── README.md ├── package.json └── src ├── api.js ├── config.json ├── schema.graphql └── server.js /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": ["@babel/preset-env"], 3 | "plugins": ["@babel/plugin-transform-runtime"] 4 | } 5 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: xxczaki 4 | patreon: akepinski 5 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | 8 | # Runtime data 9 | pids 10 | *.pid 11 | *.seed 12 | *.pid.lock 13 | 14 | # Directory for instrumented libs generated by jscoverage/JSCover 15 | lib-cov 16 | 17 | # Coverage directory used by tools like istanbul 18 | coverage 19 | 20 | # nyc test coverage 21 | .nyc_output 22 | 23 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 24 | .grunt 25 | 26 | # Bower dependency directory (https://bower.io/) 27 | bower_components 28 | 29 | # node-waf configuration 30 | .lock-wscript 31 | 32 | # Compiled binary addons (https://nodejs.org/api/addons.html) 33 | build/Release 34 | 35 | # Dependency directories 36 | node_modules/ 37 | jspm_packages/ 38 | 39 | # TypeScript v1 declaration files 40 | typings/ 41 | 42 | # Optional npm cache directory 43 | .npm 44 | 45 | # Optional eslint cache 46 | .eslintcache 47 | 48 | # Optional REPL history 49 | .node_repl_history 50 | 51 | # Output of 'npm pack' 52 | *.tgz 53 | 54 | # Yarn Integrity file 55 | .yarn-integrity 56 | 57 | # dotenv environment variables file 58 | .env 59 | 60 | # next.js build output 61 | .next 62 | -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | package-lock=false 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Antoni Kepinski 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # OMDb API GraphQL Wrapper 2 | 3 | > Easily use [OMDb API](http://www.omdbapi.com/) with [GraphQL](https://graphql.org/) :rocket: 4 | 5 | 6 | **[Demo :wrench:](https://omdb-graphql.now.sh)** 7 | 8 | --- 9 | 10 | ## Setup a server: 11 | 12 | 1. Clone this repository 13 | 2. Run `npm install` 14 | 3. Get the OMDb API key and paste it in the [`config.json`](https://github.com/xxczaki/omdb-graphql-wrapper/blob/master/src/config.json) file 15 | 4. Run `npm run dev` to start the server in the development mode 16 | 5. Go to [localhost:2121](http://localhost:2121/) and play with the GraphQL Playground 17 | 6. If you want to build the server, run `npm run build` and then `npm start` to start the server from the recently created `dist` directory. 18 | 19 | ## Usage 20 | 21 | > Check out the [GraphQL documentation](https://graphql.github.io/learn/) first! 22 | 23 | ### Queries 24 | 25 | **Using the movie title:** 26 | 27 | ```graphql 28 | { 29 | ByTitle(title: "Matrix") { 30 | Title 31 | Year 32 | Rated 33 | Plot 34 | Genre 35 | } 36 | } 37 | ``` 38 | 39 | **Using IMDb ID** 40 | 41 | ```graphql 42 | { 43 | ById(id: "100") { 44 | Director 45 | Actors 46 | Country 47 | } 48 | } 49 | ``` 50 | 51 | ### Fields: 52 | 53 | #### Title 54 | 55 | Returns: `string` 56 | 57 | Title of the movie/tv show 58 | 59 | #### Year 60 | 61 | Returns: `string` 62 | 63 | Year the movie was released 64 | 65 | #### Rated 66 | 67 | Returns: `string` 68 | 69 | Movie rating (eg. 12+) 70 | 71 | #### Released 72 | 73 | Returns: `string` 74 | 75 | Full date of release 76 | 77 | #### Runtime 78 | 79 | Returns: `string` 80 | 81 | Runtime of the movie 82 | 83 | #### Genre 84 | 85 | Returns: `string` 86 | 87 | Genre(s) of the movie 88 | 89 | #### Director 90 | 91 | Returns: `string` 92 | 93 | Movie Director(s) 94 | 95 | #### Writer 96 | 97 | Returns: `string` 98 | 99 | Movie Writer(s) 100 | 101 | #### Actors 102 | 103 | Returns: `string` 104 | 105 | Actors 106 | 107 | #### Plot 108 | 109 | Returns: `string` 110 | 111 | Plot 112 | 113 | #### Language 114 | 115 | Returns: `string` 116 | 117 | Language(s) 118 | 119 | #### Country 120 | 121 | Returns: `string` 122 | 123 | Country or countries where the movie was made 124 | 125 | #### Awards 126 | 127 | Returns: `string` 128 | 129 | Awards 130 | 131 | #### Poster 132 | 133 | Returns: `string` 134 | 135 | Link to a movie poster 136 | 137 | #### Metascore 138 | 139 | Returns: `string` 140 | 141 | Metascore 142 | 143 | #### imdbRating 144 | 145 | Returns: `string` 146 | 147 | Rating from IMDb 148 | 149 | #### imdbVotes 150 | 151 | Returns: `string` 152 | 153 | Number of votes from IMDb 154 | 155 | #### Type 156 | 157 | Returns: `string` 158 | 159 | Type (movie, tv show etc.) 160 | 161 | #### DVD 162 | 163 | Returns: `string` 164 | 165 | DVD release date 166 | 167 | #### BoxOffice 168 | 169 | Returns: `string` 170 | 171 | Box Office 172 | 173 | #### Production 174 | 175 | Returns: `string` 176 | 177 | Production company 178 | 179 | #### Website 180 | 181 | Returns: `string` 182 | 183 | Website of the movie 184 | 185 | #### Response 186 | 187 | Returns: `string` 188 | 189 | Check, if there was a response from OMDb 190 | 191 | ### License 192 | 193 | MIT 194 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "omdb-graphql-wrapper", 3 | "description": "GraphQL wrapper for Open Movie Database (OMDb) API", 4 | "main": "index.js", 5 | "scripts": { 6 | "dev": "nodemon src/server.js --exec babel-node", 7 | "build": "babel --minified --copy-files src --out-dir dist", 8 | "start": "node dist/server.js", 9 | "test": "xo" 10 | }, 11 | "dependencies": { 12 | "apollo-server-express": "^2.2.6", 13 | "compression": "^1.7.3", 14 | "express": "^4.16.4", 15 | "got": "^9.3.2", 16 | "graphql": "^14.0.2" 17 | }, 18 | "devDependencies": { 19 | "@babel/cli": "^7.2.0", 20 | "@babel/core": "^7.2.0", 21 | "@babel/node": "^7.2.0", 22 | "@babel/plugin-transform-runtime": "^7.2.0", 23 | "@babel/preset-env": "^7.2.0", 24 | "@babel/runtime": "^7.2.0", 25 | "nodemon": "^1.18.7", 26 | "xo": "*" 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/api.js: -------------------------------------------------------------------------------- 1 | import got from 'got'; 2 | import config from './config'; 3 | 4 | // Make a request with the provided API key 5 | const get = async (string, queryType) => { 6 | const response = await got(`http://omdbapi.com?apikey=${config.key}${queryType}${string}`, {json: true}); 7 | return response.body; 8 | }; 9 | 10 | export default get; 11 | -------------------------------------------------------------------------------- /src/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "key": "OMDB_API_KEY", 3 | "apollo": "APOLLO_SERVICE_KEY" 4 | } 5 | -------------------------------------------------------------------------------- /src/schema.graphql: -------------------------------------------------------------------------------- 1 | type Query { 2 | ByTitle(title: String!): Fields 3 | ByID(id: String!): Fields 4 | } 5 | 6 | type Fields { 7 | Title: String 8 | Year: String 9 | Rated: String 10 | Released: String 11 | Runtime: String 12 | Genre: String 13 | Director: String 14 | Writer: String 15 | Actors: String 16 | Plot: String 17 | Language: String 18 | Country: String 19 | Awards: String 20 | Poster: String 21 | Metascore: String 22 | imdbRating: String 23 | imdbVotes: String 24 | Type: String 25 | DVD: String 26 | BoxOffice: String 27 | Production: String 28 | Website: String 29 | Response: String 30 | } -------------------------------------------------------------------------------- /src/server.js: -------------------------------------------------------------------------------- 1 | import {readFileSync} from 'fs'; 2 | import {join} from 'path'; 3 | import express from 'express'; 4 | import {ApolloServer, gql} from 'apollo-server-express'; 5 | import compression from 'compression'; 6 | 7 | import get from './api'; 8 | import config from './config'; 9 | 10 | const resolvers = { 11 | Query: { 12 | ByTitle: (root, {title}) => get(title, '&t=').then(payload => { 13 | return payload; 14 | }), 15 | ByID: (root, {id}) => get(id, '&i=').then(payload => { 16 | return payload; 17 | }) 18 | } 19 | }; 20 | 21 | // Configure Apollo GraphQL Server 22 | const server = new ApolloServer({ 23 | typeDefs: gql(readFileSync(join(__dirname, './schema.graphql')).toString()), resolvers, 24 | playground: true, 25 | engine: { 26 | apiKey: config.apollo 27 | } 28 | }); 29 | 30 | const app = express(); 31 | 32 | // Use compression 33 | app.use(compression()); 34 | 35 | // Setup middleware & the GraphQL endpoint 36 | server.applyMiddleware({app, path: '/'}); 37 | 38 | // Port 39 | const port = 2121; 40 | 41 | // Start a server 42 | app.listen({port}, () => 43 | console.log(`🚀 Server ready at http://localhost:${port}${server.graphqlPath}`), 44 | ); 45 | 46 | --------------------------------------------------------------------------------