标签:server ted over div ret listen author retrieve this
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
标签:server ted over div ret listen author retrieve this
原文地址:https://www.cnblogs.com/Answer1215/p/10255745.html