Advertisement
Guest User

Untitled

a guest
Sep 12th, 2019
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. // const { ApolloServer } = require("apollo-server");
  2. // const path = require("path");
  3. // const { makeSchema } = require("nexus");
  4. // const types = require("./graphql/schema");
  5.  
  6. // const schema = makeSchema({
  7. // types,
  8. // outputs: {
  9. // schema: path.join(__dirname, "/graphql/generated/schema.graphql"),
  10. // typegen: path.join(__dirname, "/graphql/generated/typings.ts"),
  11. // },
  12. // });
  13.  
  14. // const server = new ApolloServer({
  15. // schema,
  16. // });
  17.  
  18. // server.listen().then(({ url, server }) => {
  19. // console.log(`Server is running on ${url}`)
  20. // })
  21. // .catch(err => {
  22. // console.log('something is wrong: ', err);
  23. // })
  24.  
  25.  
  26. const { ApolloServer, gql } = require('apollo-server');
  27.  
  28. const books = [
  29. {
  30. title: 'Harry Potter and the Chamber of Secrets',
  31. author: 'J.K. Rowling',
  32. },
  33. {
  34. title: 'Jurassic Park',
  35. author: 'Michael Crichton',
  36. },
  37. ];
  38.  
  39. const typeDefs = gql`
  40. type Book {
  41. title: String
  42. author: String
  43. }
  44.  
  45. type Query {
  46. books: [Book]
  47. }
  48. `;
  49.  
  50. const resolvers = {
  51. Query: {
  52. books: () => books,
  53. },
  54. };
  55.  
  56. const server = new ApolloServer({ typeDefs, resolvers });
  57.  
  58. server.listen().then(({ url }) => {
  59. console.log(`Server is running on ${url}`)
  60. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement