Skip to content

Instantly share code, notes, and snippets.

@builtbyproxy
Created September 1, 2019 06:46
Show Gist options
  • Save builtbyproxy/545b295a34038420e5367291de2d6116 to your computer and use it in GitHub Desktop.
Save builtbyproxy/545b295a34038420e5367291de2d6116 to your computer and use it in GitHub Desktop.
apollo-server app.js
// const { ApolloServer } = require("apollo-server");
// const path = require("path");
// const { makeSchema } = require("nexus");
// const types = require("./graphql/schema");
// const schema = makeSchema({
// types,
// outputs: {
// schema: path.join(__dirname, "/graphql/generated/schema.graphql"),
// typegen: path.join(__dirname, "/graphql/generated/typings.ts"),
// },
// });
// const server = new ApolloServer({
// schema,
// });
// server.listen().then(({ url, server }) => {
// console.log(`Server is running on ${url}`)
// })
// .catch(err => {
// console.log('something is wrong: ', err);
// })
const { ApolloServer, gql } = require('apollo-server');
const books = [
{
title: 'Harry Potter and the Chamber of Secrets',
author: 'J.K. Rowling',
},
{
title: 'Jurassic Park',
author: 'Michael Crichton',
},
];
const typeDefs = gql`
type Book {
title: String
author: String
}
type Query {
books: [Book]
}
`;
const resolvers = {
Query: {
books: () => books,
},
};
const server = new ApolloServer({ typeDefs, resolvers });
server.listen().then(({ url }) => {
console.log(`Server is running on ${url}`)
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment