Created
June 22, 2019 16:00
-
-
Save ssaumyaranjan7/13b7f892da3c5eba3ae00da1c5481e57 to your computer and use it in GitHub Desktop.
This is the index.js file of Hello world GraphQL project.
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
const express = require('express'); | |
const { ApolloServer, gql } = require('apollo-server-express'); | |
// This is the schema types | |
const typeDefs = gql` | |
type Query { | |
hello: String | |
} | |
`; | |
// This is the resolver methods | |
const resolvers = { | |
Query: { | |
hello: () => 'Hello world!', | |
}, | |
}; | |
const server = new ApolloServer({ typeDefs, resolvers }); | |
const app = express(); | |
server.applyMiddleware({ app }); | |
app.listen({ port: 4000 }, () => | |
console.log(` Server started at http://localhost:4000${server.graphqlPath}`) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment