Complete the code to import the Express library.
const express = require('[1]');
The Express library is imported using require('express'). This allows us to create an Express app.
Complete the code to create an Express application instance.
const app = [1]();Calling express() creates a new Express application instance.
Fix the error in the code to start the Express server on port 4000.
app.listen([1], () => { console.log('Server running on port 4000'); });
The listen method expects a number for the port, not a string.
Fill both blanks to add a GraphQL endpoint using Express and Apollo Server.
const [1] = require('express-graphql'); app.use('/graphql', [2]({ schema, graphiql: true }));
The express-graphql package exports graphqlHTTP which is used as middleware in Express.
Fill all three blanks to define a simple GraphQL schema and integrate it with Express.
const { [1], GraphQLSchema, GraphQLString } = require('graphql');
const schema = new [2]({
query: new [3]({
name: 'RootQueryType',
fields: {
hello: {
type: GraphQLString,
resolve() {
return 'Hello world!';
}
}
}
})
});We import GraphQLObjectType and GraphQLSchema from 'graphql'. The schema is created with new GraphQLSchema and the query is a GraphQLObjectType.