Complete the code to start the GraphQL Playground server on port 4000.
const server = new ApolloServer({ typeDefs, resolvers });
server.listen({ port: [1] }).then(({ url }) => {
console.log(`Server ready at ${url}`);
});The default port for GraphQL Playground examples is usually 4000. This code sets the server to listen on port 4000.
Complete the code to import the GraphQL Playground middleware for Express.
const express = require('express'); const { graphqlHTTP } = require('express-graphql'); const [1] = require('graphql-playground-middleware-express').default;
The package exports the middleware as the default export, commonly imported as playgroundMiddleware or similar. Here, playgroundMiddleware is the correct import name.
Fix the error in the GraphQL Playground setup by completing the missing path in the Express route.
app.get([1], playgroundMiddleware({ endpoint: '/graphql' }));
The GraphQL Playground middleware is usually mounted on a separate path like '/playground' to serve the interactive UI, while the GraphQL API runs on '/graphql'.
Fill both blanks to configure Apollo Server to enable GraphQL Playground in production.
const server = new ApolloServer({
typeDefs,
resolvers,
[1]: true,
[2]: 'playground'
});To enable GraphQL Playground in production, introspection must be set to true, and playground must be enabled.
Fill all three blanks to create a GraphQL Playground query that fetches a user's name and email by ID.
query GetUser {
user(id: [1]) {
[2]
[3]
}
}The query requests a user with ID "123" and asks for the name and email fields.