apollo-server/docs/source/features/playground.md
Evans Hauser 02d31559da
Add GraphQL Playground Documentation (#1270)
* add initial playground documentation

* link to playground in whats-new

* address feedback
2018-07-05 16:17:39 -07:00

1.6 KiB

title description
GraphQL Playground Visually exploring a Apollo Server

GraphQL Playground is a graphical interactive in-browser GraphQL IDE, created by Prisma, based on GraphiQL. In development, Apollo Server collocates a GraphQL Playground instance with the GraphQL path. When a browser sends a request to Apollo Server, it receives the GraphQL Playground gui. When NODE_ENV is set to production, introspection and Playground are disabled as a production best practice.

![GraphQL Playground](../images/playground.png)

Enabling Playground in Production

To enable Playground in production, an integration package must be installed to provide more control over the middlewares used. The following example uses the express integration:

npm install --save apollo-server-express@rc graphql

Introspection and the gui can be enabled explicitly in the following manner.

const { ApolloServer, gql } = require('apollo-server-express');
const express = require('express');
const { typeDefs, resolvers } = require('./schema');

const server = new ApolloServer({
  typeDefs,
  resolvers,
  introspection: true,
});

const app = express();

// gui accepts a Playground configuration
server.applyMiddleware({
  app,
  gui: true,
});

app.listen({ port: 4000 }, () =>
  console.log(`🚀 Server ready at http://localhost:4000${server.graphqlPath}`),
);

Note: when using apollo-server-express, you can remove apollo-server from your package.json