Skip to content

Instantly share code, notes, and snippets.

@ssaumyaranjan7
Created June 22, 2019 16:00
Show Gist options
  • Save ssaumyaranjan7/13b7f892da3c5eba3ae00da1c5481e57 to your computer and use it in GitHub Desktop.
Save ssaumyaranjan7/13b7f892da3c5eba3ae00da1c5481e57 to your computer and use it in GitHub Desktop.
This is the index.js file of Hello world GraphQL project.
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