如何在无服务器生产中禁用GraphQL Playground?

时间:2018-09-10 03:01:53

标签: graphql serverless-framework

是否可以在生产中禁用游乐场功能?

在我的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

在我的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 个答案:

没有答案