Skip to content

Instantly share code, notes, and snippets.

@Salamit
Last active March 25, 2020 05:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Salamit/dfedb8395403042e9ba9605dce98dc7c to your computer and use it in GitHub Desktop.
Save Salamit/dfedb8395403042e9ba9605dce98dc7c to your computer and use it in GitHub Desktop.
//Check this link for more info
//https://spectrum.chat/apollo/apollo-server/using-express-alongside-apollo-server~0da4a3f3-e441-46b8-987e-de3374fb3e66
const { ApolloServer, gql } = require('apollo-server-express');
import Express from 'express';
const app = new Express();
const restRoutes = Express.Router();
const path = '/'
const message = `
type Query {
message: String,
}
`;
const typeDefs = [
message
]
const resolvers = {
Query: {
// message: () => 'Hello World!'
message: () => 'Hello World!'
}
};
const server = new ApolloServer({
typeDefs,
resolvers,
});
app.use('/', restRoutes)
app.get('/', (req, res) => {
res.send({'hello': 'Johnny'})
})
app.get('/api/def_text_query', function (req, res) {
return res.send({
success: 'Your request has been submitted successfully'
})
})
server.applyMiddleware({ app, path });
app.listen({ port: 4000 }, () =>
console.log(`🚀 Server ready at http://localhost:4000${server.graphqlPath}`)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment