Skip to content

Instantly share code, notes, and snippets.

@ahafidi
Created August 2, 2018 13:48
Show Gist options
  • Save ahafidi/a573a21e450d10bdb17c18af6df6afdd to your computer and use it in GitHub Desktop.
Save ahafidi/a573a21e450d10bdb17c18af6df6afdd to your computer and use it in GitHub Desktop.
A Tiny GraphQL Server using Apollo Server.
const { ApolloServer, gql } = require('apollo-server')
// The GraphQL schema
const typeDefs = gql`
type Query {
"A simple type for getting started!"
foo: String
foofoo: Int
}
`
// A map of functions which return data for the schema.
const resolvers = {
Query: {
foo: () => 'Hello World!',
foofoo: () => 42,
}
}
const server = new ApolloServer({
typeDefs,
resolvers,
})
server
.listen() // By default, Apollo Server listens on port 4000
.then(({ url }) => {
console.log(`My server is running at ${url}`)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment