Last active
August 17, 2018 08:08
-
-
Save Mefistophell/79bbb641e414d735c2e46cd48a155369 to your computer and use it in GitHub Desktop.
apollo-graphql-api
This file contains 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 Koa = require('koa'); | |
const { ApolloServer, gql } = require('apollo-server-koa'); | |
// Construct a schema, using GraphQL schema language | |
const typeDefs = gql` | |
type Query { | |
hello: String | |
} | |
`; | |
// Provide resolver functions for your schema fields | |
const resolvers = { | |
Query: { | |
hello: () => 'Hello world!', | |
}, | |
}; | |
// Set playground settings | |
const playground = { | |
settings: { | |
'editor.theme': 'dark', | |
'editor.cursorShape': 'line' | |
} | |
} | |
const server = new ApolloServer({ typeDefs, resolvers, playground }); | |
const app = new Koa(); | |
server.applyMiddleware({ app }); | |
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