繁体   English   中英

2022年如何使用apollo server express打开graphql游乐场页面?

[英]How to open graphql playground page using apollo server express in 2022?

We have a API project using express with Apollo server express and graphql, I am new to graphql so I don't know how to land graphql playground page by default. 当我试图运行它时,它会出现在“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-server-core 并从插件部分添加 {ApolloServerPluginLandingPageGraphQLPlayground}

来源https://www.apollographql.com/docs/apollo-server/api/plugin/landing-pages/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM