Last active
March 25, 2020 05:17
-
-
Save Salamit/dfedb8395403042e9ba9605dce98dc7c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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