so I have this code for both my server.js and schema.js from following the apollo doc tutorial https://www.apollographql.com/docs/tutorial/introduction/
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
only tweak I did was to choose the ES modules method of import/exporting modules over the commonJS way as used in the documentation, which I think shouldn't be a problem, it compiles without errors but instead of getting the graphql playground to see my schema, I get a cannot Get /
I haven't done the resolvers, but at this point, I believe I should see the playground in action already. as per the docs