GraphQL in Action

This document was uploaded by one of our users. The uploader already confirmed that they had the permission to publish it. If you are author/publisher or own the copyright of this documents, please report to us by using this DMCA report form.

Simply click on the Download Book button.

Yes, Book downloads on Ebookily are 100% Free.

Sometimes the book is free on Amazon As well, so go ahead and hit "Search on Amazon"

Reduce bandwidth demands on your APIs by getting only the results you need—all in a single request! The GraphQL query language simplifies interactions with web servers, enabling smarter API queries that can hugely improve the efficiency of data requests. In GraphQL in Action, you'll learn how to bring those benefits to your own APIs, giving your clients the power to ask for exactly what they need from your server, no more, no less. Practical and example-driven, this book teaches everything you need to get started with GraphQL—from design principles and syntax right through to performance optimization. About the Technology GraphQL APIs are fast, efficient, and easy to maintain. They reduce app latency and server cost while boosting developer productivity. This powerful query layer offers precise control over API requests and returns, making apps faster and less prone to error. About the book GraphQL in Action gives you the tools to get comfortable with the GraphQL language, build and optimize a data API service, and use it in a front-end client application. By working through set up, security, and error handling you'll learn to create a complete GraphQL server. You'll also unlock easy ways to incorporate GraphQL into your existing codebase so you can build simple, scalable data APIs. What's inside • Define a GraphQL schema for relational and document databases • Implement GraphQL types using both the schema language and object constructor methods • Optimize GraphQL resolvers with data caching and batching • Design GraphQL fragments that match UI components' data requirements • Consume GraphQL API queries, mutations, and subscriptions with and without a GraphQL client library About the reader For web developers familiar with client-server applications. About the author Samer Buna has over 20 years of experience in software development including front-ends, back-ends, API design, and scalability.

Author(s): Samer Buna
Edition: 1
Publisher: Manning Publications
Year: 2021

Language: English
Commentary: Vector PDF
Pages: 384
City: Shelter Island, NY
Tags: Databases; Web Programming; Web Applications; GraphQL; API Design; REST API

GraphQL in Action
brief contents
contents
preface
acknowledgments
about this book
Who should read this book
How this book is organized: a roadmap
About the code
Other online resources
about the author
about the cover illustration
Part 1: Exploring GraphQL
Chapter 1: Introduction to GraphQL
1.1 What is GraphQL?
1.1.1 The big picture
1.1.2 GraphQL is a specification
1.1.3 GraphQL is a language
1.1.4 GraphQL is a service
1.2 Why GraphQL?
1.2.1 What about REST APIs?
1.2.2 The GraphQL way
1.2.3 REST APIs and GraphQL APIs in action
1.3 GraphQL problems
1.3.1 Security
1.3.2 Caching and optimizing
1.3.3 Learning curve
Chapter 2: Exploring GraphQL APIs
2.1 The GraphiQL editor
2.2 The basics of the GraphQL language
2.2.1 Requests
2.2.2 Fields
2.3 Examples from the GitHub API
2.3.1 Reading data from GitHub
2.3.2 Updating data at GitHub
2.3.3 Introspective queries
Chapter 3: Customizing and organizing GraphQL operations
3.1 Customizing fields with arguments
3.1.1 Identifying a single record to return
3.1.2 Limiting the number of records returned by a list field
3.1.3 Ordering records returned by a list field
3.1.4 Paginating through a list of records
3.1.5 Searching and filtering
3.1.6 Providing input for mutations
3.2 Renaming fields with aliases
3.3 Customizing responses with directives
3.3.1 Variables and input values
3.3.2 The @include directive
3.3.3 The @skip directive
3.3.4 The @deprecated directive
3.4 GraphQL fragments
3.4.1 Why fragments?
3.4.2 Defining and using fragments
3.4.3 Fragments and DRY
3.4.4 Fragments and UI components
3.4.5 Inline fragments for interfaces and unions
Part 2: Building GraphQL APIs
Chapter 4: Designing a GraphQL schema
4.1 Why AZdev?
4.2 The API requirements for AZdev
4.2.1 The core types
4.3 Queries
4.3.1 Listing the latest Task records
4.3.2 Search and the union/interface types
4.3.3 Using an interface type
4.3.4 The page for one Task record
4.3.5 Entity relationships
4.3.6 The ENUM type
4.3.7 List of scalar values
4.3.8 The page for a user’s Task records
4.3.9 Authentication and authorization
4.4 Mutations
4.4.1 Mutation input
4.4.2 Deleting a user record
4.4.3 Creating a Task object
4.4.4 Creating and voting on Approach entries
4.5 Subscriptions
4.6 Full schema text
4.7 Designing database models
4.7.1 The User model
4.7.2 The Task/Approach models
4.7.3 The Approach Details model
Chapter 5: Implementing schema resolvers
5.1 Running the development environment
5.1.1 Node.js packages
5.1.2 Environment variables
5.2 Setting up the GraphQL runtime
5.2.1 Creating the schema object
5.2.2 Creating resolver functions
5.2.3 Executing requests
5.3 Communicating over HTTP
5.4 Building a schema using constructor objects
5.4.1 The Query type
5.4.2 Field arguments
5.4.3 Custom object types
5.4.4 Custom errors
5.5 Generating SDL text from object-based schemas
5.5.1 The schema language versus the object-based method
5.6 Working with asynchronous functions
Chapter 6: Working with database models and relations
6.1 Running and connecting to databases
6.2 The taskMainList query
6.2.1 Defining object types
6.2.2 The context object
6.2.3 Transforming field names
6.2.4 Transforming field values
6.2.5 Separating interactions with PostgreSQL
6.3 Error reporting
6.4 Resolving relations
6.4.1 Resolving a one-to-one relation
6.4.2 Resolving a one-to-many relation
Chapter 7: Optimizing data fetching
7.1 Caching and batching
7.1.1 The batch-loading function
7.1.2 Defining and using a DataLoader instance
7.1.3 The loader for the approachList field
7.2 Single resource fields
7.3 Circular dependencies in GraphQL types
7.3.1 Deeply nested field attacks
7.4 Using DataLoader with custom IDs for caching
7.4.1 The taskMainList field
7.4.2 The search field
7.5 Using DataLoader with MongoDB
Chapter 8: Implementing mutations
8.1 The mutators context object
8.2 The Mutation type
8.3 User mutations
8.3.1 The userCreate mutation
8.3.2 The userLogin mutation
8.4 Authenticating API consumers
8.4.1 The me root query field
8.5 Mutations for the Task model
8.6 Mutations for the Approach model
8.6.1 The approachCreate mutation
8.6.2 The approachVote mutation
8.7 The userDelete mutation
Part 3: Using GraphQL APIs
Chapter 9: Using GraphQL APIs without a client library
9.1 Using a web UI library
9.2 Running the web server
9.3 Making Ajax requests
9.4 Performing GraphQL query requests
9.4.1 Using GraphQL fragments in UI components
9.4.2 Including variables in requests
9.5 Performing GraphQL mutation requests
9.5.1 The login/signup forms
9.5.2 Handling generic server errors
9.5.3 Authenticating GraphQL requests
9.5.4 The Create Task form
9.5.5 The Create Approach form
9.5.6 Voting on an Approach
9.6 Performing query requests scoped for a user
9.6.1 The Search form
9.7 Next up
Chapter 10: Using GraphQL APIs with Apollo client
10.1 Using Apollo Client with JavaScript
10.1.1 Making a query request
10.1.2 Making a mutation request
10.2 Using Apollo Client with React
10.2.1 Using the query and mutate methods directly
10.2.2 Including authentication headers
10.2.3 Using Apollo hook functions
10.2.4 Using the automatic cache
10.2.5 Manually updating the cache
10.2.6 Performing operations conditionally
10.3 Managing local app state
10.4 Implementing and using GraphQL subscriptions
10.4.1 Polling and refetching
10.4.2 Implementing subscriptions
10.4.3 Apollo Server
10.4.4 Using subscriptions in UIs
Wrapping up
index
A
B
C
D
E
F
G
H
I
J
L
M
N
O
P
Q
R
S
T
U
V
W
X