Skip to Content
GraphQL 学习指南
book

GraphQL 学习指南

by Eve Porcello, Alex Banks
June 2019
Intermediate to advanced
181 pages
3h 37m
Chinese
China Machine Press
Content preview from GraphQL 学习指南
GraphQL
客户端
119
React 客户端应用在 http://localhost:3000 上成功运行。本章的所有代码都可
以在 GitHub 仓库中找到,网址为
http://github.com/moonhighway/learning-graphql
配置 Apollo Client
你需要安装几个包,以便使用 Apollo 工具构建 GraphQL 客户端。首先你需要安装
graphql 它包含了 GraphQL 语言解析器。接下来安装 apollo-boost,它包含了创
Apollo Client 和发送操作所必需的 Apollo 包。最后我们需要安装 react-apollo
它是包含了构建 Apollo 用户界面的 React 组件。
译注 1
同时安装这三个包:
npm install graphql apollo-boost react-apollo
现在准备创建我们的客户端。apollo-boost 中的构造函数 ApolloClient 可用于创
建我们的第一个客户端。我们将
src/index.js
文件中的内容替换一下:
import ApolloClient from 'apollo-boost'
const client = new ApolloClient({ uri: 'http://localhost:4000/
graphql' })
我们通过 ApolloClient 构造函数创建了一个新的 client 实例。该 client 已准
备好处理和
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

面向对象的思考过程(原书第5版)

面向对象的思考过程(原书第5版)

马特 魏斯费尔德
精通模块化JavaScript

精通模块化JavaScript

Nicolás Bevacqua
Java并发编程实战

Java并发编程实战

Brian Goetz, Tim Peierls

Publisher Resources

ISBN: 9787111628613