Skip to content

Instantly share code, notes, and snippets.

@Mefistophell
Last active August 17, 2018 08:08
Show Gist options
  • Save Mefistophell/79bbb641e414d735c2e46cd48a155369 to your computer and use it in GitHub Desktop.
Save Mefistophell/79bbb641e414d735c2e46cd48a155369 to your computer and use it in GitHub Desktop.
apollo-graphql-api
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