How to disable GraphQL Playground in Serverless production?

Viewed 2535

Is there a way to disable the playground function in production?

In my serverless.yml

functions:
  graphql:
    # this is formatted as <FILENAME>.<HANDLER>
    handler: handler.graphqlHandler
    events:
    - http:
        path: api/v1
        method: post

  playground:
    handler: handler.playgroundHandler
    events:
    - http:
        path: playground
        method: get

In my handler.js

import { ApolloServer, gql } from "apollo-server-lambda";
import lambdaPlayground from "graphql-playground-middleware-lambda";

// Construct a schema, using GraphQL schema language
const typeDefs = gql`
  type Query {
    hello: String
  }
`;

// Provide resolver functions for your schema fields
const resolvers = {
  Query: {
    hello: () => "Hello world!"
  }
};

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

export const graphqlHandler = server.createHandler({
  cors: {
    origin: "*",
    credentials: true
  }
});
export const playgroundHandler = lambdaPlayground({
  endpoint: "/api/v1"
});
0 Answers
Related