Apollo-server-express返回“无法获取/”而不是Graphql游乐场

问题描述

因此,按照阿波罗文档教程https://www.apollographql.com/docs/tutorial/introduction/

,我对我的server.js和schema.js都有这段代码

server.js

import apollo from "apollo-server-express";
const { ApolloServer } = apollo;
import express from "express";
import typeDefs from "./schema.js";

const app = express();
const server = new ApolloServer({
  typeDefs,playground: true,});

server.applyMiddleware({ app });

const PORT = process.env.PORT || 4000;
app.listen(PORT,() => {
  console.log(`operating on port ${PORT}`);
})

schema.js

import pkg from "apollo-server-express"
const { gql } = pkg

// defining schema
 const typeDefs = gql`
  type Launch {
    id: ID!
    site: String
    mission: Mission
    rocket: Rocket
    isBooked: Boolean!
  }
  type Rocket {
    id: ID!
    name: String
    type: String
  }

  type User {
    id: ID!
    email: String!
    trips: [Launch]!
  }

  type Mission {
    name: String
    missionPatch(size: PatchSize): String
  }

  enum PatchSize {
    SMALL
    LARGE
  }
  type Query {
    launches: [Launch]!
    launch(id: ID!): Launch
    me: User
  }
  type Mutation {
    bookTrips(launchIds: [ID]!): TripUpdateResponse!
    cancelTrip(launchId: ID!): TripUpdateResponse!
    login(email: String): String # login token
  }
  type TripUpdateResponse {
    success: Boolean!
    message: String
    launches: [Launch]
  }
`
export default typeDefs

我只是做过调整,就是选择文档中使用的commonJS方式导入/导出模块的ES模块方法,我认为应该没问题,它编译时没有错误,但没有得到graphql游乐场看我的模式,我得到一个cannot Get /

我还没有做过解析器,但是到现在为止,我相信我应该已经看到了操场。根据文档

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)