[Apollo Server] Get started with Apollo Server
2024-08-29 14:13:47
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(`最新文章
- 相克军_Oracle体系_随堂笔记008-存储结构
- Oracle恢复删除数据 &;&; connect by 树形结构查询
- BZOJ2773 : ispiti
- xx
- UVA 11610 Reverse Prime (数论+树状数组+二分,难题)
- 启动 mysql 失败 Warning:The /usr/local/mysql/data directory is not owned by the 'mysql' or '_mysql'
- IntelliJ IDEA 14 利用JRebel实现热部署 二
- C语言和C++中动态申请内存
- Linux网桥
- AndroidUI 布局动画-点九PNG技术
- NYoj 部分和问题(深搜经典)
- ORM项目中小知识点积累
- 借用nginx.vim工具进行语法高亮和格式化配置nginx.conf文件
- [NOI2012]随机数生成器
- Ubuntu中安装和配置 Java JDK,并卸载自带OpenJDK(以Ubuntu 14.04为例)
- event.stopPropagation(),event.preventDefault()和return false的区别
- RN TextInput用法
- windows开启Apache的mod_rewrite模块
- spring boot整合JWT例子
- Cocos2d-x 2.2.3 使用NDK配置编译环境
热门文章