Reputation: 1637
what i wanted to do is to separate my schema from the index.js file. so here are the index.js file and schema.js file after separation.
//schema.js
import { gql, makeExecutableSchema } from 'apollo-server-express';
const typeDefs = gql`
type Query {
hello : String
}
`;
const resolvers = {
Query:{
hello: () => 'HelloWorld!'
}
};
export default makeExecutableSchema({
typeDefs,
resolvers,
});
//index.js
import { ApolloServer } from 'apollo-server-express';
import express from 'express';
const schema = require('./schema');
const app = express();
const server = new ApolloServer({schema});
server.applyMiddleware({app});
app.listen(4000, ()=> {
console.log(`app is working on port 4000 ${server.graphqlPath}`);
});
i still can open graphql playground on localhost:4000/graphql but after the separation i receive the following error.
Upvotes: 2
Views: 5808
Reputation: 1637
I replaced the line const schema = require('./schema');
to import schema from './schema';
solved my problem.
even though I am using node V8.10 I used the babel compiler to use modern syntax with node. the old syntax was the issue.
Upvotes: 2