有没有办法在生产环境中禁用playground功能?
在我的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"
});
process.env.NODE_ENV === 'production'
)。或者,它允许您专门为 playground 设置布尔值,并将其连接到环境变量。因此,也许更新可能是值得的? - Herku