Created
August 2, 2018 13:48
-
-
Save ahafidi/a573a21e450d10bdb17c18af6df6afdd to your computer and use it in GitHub Desktop.
A Tiny GraphQL Server using Apollo Server.
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 { 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