如何在2022年使用apollo服务器express打开graphql游乐场页面



我们有一个API项目,使用Apollo服务器express和graphql的express,我是graphql的新手,所以我不知道如何默认登录graphql游乐场页面。当我试图运行时;http://localhost:8080/graphql但它显示

无法加载完整的登录页;看来您可能已离线

有人能帮我如何登陆graphql游乐场页面吗?

我遵循了以下代码

const express = require('express');
const { ApolloServer, gql } = require('apollo-server-express');

const typeDefs = gql`
type Query {
hello: String
}
`;
const resolvers = {
Query: {
hello: () => 'Hello world!',
},
};
const server = new ApolloServer({ typeDefs, resolvers });
const app = express();
server.applyMiddleware({ app });
const port = 8080;
app.listen({ port }, () =>
console.log(`🚀 Server ready at http://localhost:${port}${server.graphqlPath}`),
);

安装apollo服务器核心并从插件部分添加{ApoloServerPluginLandingPageGraphQLPlayground}

来源https://www.pollographql.com/docs/apollo-server/api/plugin/landing-pagess/

最新更新