首页 > 其他 > 详细

[Apollo Server] Get started with Apollo Server

时间:2019-01-11 16:52:11      阅读:215      评论:0      收藏:0      [点我收藏+]

Get started with apollo server with node.js:

 

Install:

npm install --save apollo-server graphql

 

index.js:

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`
  # Comments in GraphQL are defined with the hash (#) symbol.
  type Book {
    "Title of the book, this will appear in graphql playground"
    title: String
    author: String
  }

  # The "Query" type is the root of all GraphQL queries.
  # (A "Mutation" type will be covered later on.)
  type Query {
    books: [Book]
  }
`;

// Resolvers define the technique for fetching the types in the
// schema.  We‘ll retrieve books from the "books" array above.
const resolvers = {
  Query: {
    books: () => books,
  },
};

const server = new ApolloServer({ typeDefs, resolvers });


server.listen().then(({ url }) => {
  console.log(`??  Server ready at ${url}`);
});

 

[Apollo Server] Get started with Apollo Server

原文:https://www.cnblogs.com/Answer1215/p/10255745.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!