2

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.

enter image description here

1 Answer 1

2

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.