'use strict'; const express = require('express'); const graphqlHTTP = require('express-graphql'); const { GraphQLSchema, GraphQLObjectType, GraphQLID, GraphQLString, GraphQLInt, GraphQLBoolean } = require('graphql'); const { getVideoById } = require('./src/data/index'); const PORT = process.env.PORT || 3000; const server = express(); const videoType = new GraphQLObjectType({ name: 'Video', description: 'A video on egghead.io', fields: { id: { type: GraphQLID, description: 'The ID of the video' }, title: { type: GraphQLString, description: 'The title of the video' }, duration: { type: GraphQLInt, description: 'The duration of the video, in seconds', }, watched: { type: GraphQLBoolean, description: 'Whether or not the viewer has watched the video' } } }); const queryType = new GraphQLObjectType({ name: 'QueryType', description: 'The root query type', fields: { video: { type: videoType, args: { id: { type: GraphQLID, description: 'The ID of the video' } }, resolve: (_, args) => { return getVideoById(args.id); } } } }); const schema = new GraphQLSchema({ query: queryType // Also available: // mutation: ... // subscription: ... }); server.use('/graphql', graphqlHTTP({ schema, graphiql: true })); server.listen(PORT, () => { console.log(`Listening on http://localhost:${PORT}`); });