logo资料库

Learning GraphQL.pdf

第1页 / 共292页
第2页 / 共292页
第3页 / 共292页
第4页 / 共292页
第5页 / 共292页
第6页 / 共292页
第7页 / 共292页
第8页 / 共292页
资料共292页,剩余部分请下载后查看
Preface
Acknowledgments
Conventions Used in This Book
Using Code Examples
O’Reilly Safari
How to Contact Us
1. Welcome to GraphQL
What Is GraphQL?
The GraphQL Specification
Design Principles of GraphQL
Origins of GraphQL
History of Data Transport
Remote Procedure Call
Simple Object Access Protocol
REST
REST Drawbacks
Overfetching
Underfetching
Managing REST Endpoints
GraphQL in the Real World
GraphQL Clients
2. Graph Theory
Graph Theory Vocabulary
History of Graph Theory
Trees are Graphs
Graphs in the Real World
3. The GraphQL Query Language
GraphQL API Tools
GraphiQL
GraphQL Playground
Public GraphQL APIs
The GraphQL Query
Edges and Connections
Fragments
Mutations
Using Query Variables
Subscriptions
Introspection
Abstract Syntax Trees
4. Designing a Schema
Defining Types
Types
Scalar Types
Enums
Connections and Lists
One-to-One Connections
One-to-Many Connections
Many-to-Many Connections
Lists of Different Types
Arguments
Filtering Data
Mutations
Input Types
Return Types
Subscriptions
Schema Documentation
5. Creating a GraphQL API
Project Setup
Resolvers
Root Resolvers
Type Resolvers
Using Inputs and Enums
Edges and Connections
Custom Scalars
apollo-server-express
Context
Installing Mongo
Adding Database to Context
GitHub Authorization
Setting Up GitHub OAuth
The Authorization Process
githubAuth Mutation
Authenticating Users
Conclusion
6. GraphQL Clients
Using a GraphQL API
fetch Requests
graphql-request
Apollo Client
Apollo Client with React
Project Setup
Configure Apollo Client
The Query Component
The Mutation Component
Authorization
Authorizing the User
Identifying the User
Working with the Cache
Fetch Policies
Persisting The Cache
Updating the Cache
7. GraphQL in the Real World
Subscriptions
Working with Subscriptions
Consuming Subscriptions
Uploading Files
Handling Uploads on the Server
Posting a New Photo with Apollo Client
Security
Request Timeouts
Data Limitations
Limiting Query Depth
Limiting Query Complexity
Apollo Engine
Taking the Next Steps
Incremental Migration
Schema-First Development
GraphQL Events
Community
Community Slack Channels
Index
Learning GraphQL Declarative Data Fetching for Modern Web Apps Eve Porcello and Alex Banks
Learning GraphQL by Eve Porcello and Alex Banks Copyright © 2018 Eve Porcello and Alex Banks. All rights reserved. Printed in the United States of America. Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472. O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions are also available for most titles (http://oreilly.com/safari). For more information, contact our corporate/institutional sales department: 800- 998-9938 or corporate@oreilly.com. Acquisitions Editor: Mary Treseler Development Editor: Alicia Young Production Editor: Justin Billing Copyeditor: Chris Edwards Proofreader: Octal Publishing, Inc. Indexer: WordCo, Inc. Interior Designer: David Futato Cover Designer: Karen Montgomery Illustrator: Melanie Yarbrough August 2018: First Edition
Revision History for the First Edition 2018-08-08: First Release See http://oreilly.com/catalog/errata.csp?isbn=9781492030713 for release details. The O’Reilly logo is a registered trademark of O’Reilly Media, Inc. Learning GraphQL, the cover image, and related trade dress are trademarks of O’Reilly Media, Inc. The views expressed in this work are those of the authors, and do not represent the publisher’s views. While the publisher and the authors have used good faith efforts to ensure that the information and instructions contained in this work are accurate, the publisher and the authors disclaim all responsibility for errors or omissions, including without limitation responsibility for damages resulting from the use of or reliance on this work. Use of the information and instructions contained in this work is at your own risk. If any code samples or other technology this work contains or describes is subject to open source licenses or the intellectual property rights of others, it is your responsibility to ensure that your use thereof complies with such licenses and/or rights. 978-1-492-03071-3 [LSI]
Preface
Acknowledgments This book would not be a book without the help of many phenomenal people. It started with the idea from Ally MacDonald, our editor for Learning React, who encouraged us to write Learning GraphQL. We were then very lucky to get to work with Alicia Young, who shepherded the book to its printing. Thanks to Justin Billing, Melanie Yarbrough, and Chris Edwards who sanded off all of the rough edges during an extremely thorough production edit. Throughout the process, we were fortunate to get feedback from Peggy Rayzis and Sashko Stubailo from the Apollo team who shared their insights and hot tips about the latest features. Thanks also to Adam Rackis, Garrett McCullough, and Shivi Singh, who were excellent technical editors. We wrote this book about GraphQL because we love GraphQL. We think you will too.
Conventions Used in This Book The following typographical conventions are used in this book: Italic Indicates new terms, URLs, email addresses, filenames, and file extensions. Constant width Used for program listings, as well as within paragraphs to refer to program elements such as variable or function names, databases, data types, environment variables, statements, and keywords. Constant width bold Shows commands or other text that should be typed literally by the user. Constant width italic Shows text that should be replaced with user-supplied values or by values determined by context. This element signifies a tip or suggestion. TIP NOTE This element signifies a general note. This element indicates a warning or caution. WARNING
Using Code Examples Supplemental material (code examples, exercises, etc.) is available for download at https://github.com/moonhighway/learning-graphql/. This book is here to help you get your job done. In general, if example code is offered with this book, you may use it in your programs and documentation. You do not need to contact us for permission unless you’re reproducing a significant portion of the code. For example, writing a program that uses several chunks of code from this book does not require permission. Selling or distributing a CD- ROM of examples from O’Reilly books does require permission. Answering a question by citing this book and quoting example code does not require permission. Incorporating a significant amount of example code from this book into your product’s documentation does require permission. We appreciate, but do not require, attribution. An attribution usually includes the title, author, publisher, and ISBN. For example: “Learning GraphQL by Eve Porcello and Alex Banks (O’Reilly). Copyright 2018 Eve Porcello and Alex Banks, 978-1-492-03071-3.” If you feel your use of code examples falls outside fair use or the permission given above, feel free to contact us at permissions@oreilly.com.
分享到:
收藏