GraphQL in Action
Samer Buna
  • MEAP began December 2019
  • Publication in December 2020 (estimated)
  • ISBN 9781617295683
  • 375 pages (estimated)
  • printed in black & white

My go to introduction to GraphQL. This was the resource that made it all click for me.

Jeremy Lange
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

The type-based GraphQL query language solves issues with over- or under-fetching data from an API, providing client apps with a predictable interface for interacting with a server. By organizing data as types and fields, GraphQL gives apps complete control over what they’re requesting, including data format, how much to fetch, and more. The result is faster transfer roundtrips, errors that are easier to spot, and virtually no need for clients to write time-consuming manual parsing code. Language-agnostic, GraphQL can be used with any language and incorporated easily into your existing stack.

About the book

In GraphQL in Action, you’ll learn to use GraphQL to simplify interactions with your web servers and improve the performance of your data APIs. Twenty-year web development veteran Samer Buna starts by introducing GraphQL’s unique query-based API paradigm, laying out its unique design concepts and advantages over traditional APIs. From there, you’ll master the GraphQL way of creating APIs for hierarchical data, unlock easy ways to incorporate GraphQL into your existing codebase, and learn how to consume a GraphQL API with queries, mutations, and subscriptions using the GraphQL query language. When you’re done, you’ll have all the skills you need to get started writing and using scalable data APIs with GraphQL. GraphQL is a new paradigm. Are you ready?
Table of Contents detailed table of contents

Part 1: Exploring GraphQL

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

1.4 Summary

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

2.4 Summary

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

3.5 Summary

Part 2: Building GraphQL APIs

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 List of 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 own Task records

4.3.9 Authentication and authorization

4.4 Mutations

4.4.1 Mutations 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

4.8 Summary

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 Objects to schema language conversion

5.5.1 The schema language vs the object-based method

5.6 Working with asynchronous functions

5.7 Summary

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

6.5 Summary

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 Deep-nested fields 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

7.6 Summary

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

8.8 Summary

Part 3: Using GraphQL APIs

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

9.8 Summary

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 Leveraging 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

10.5 Wrap-up

10.6 Summary

What's inside

  • Define a GraphQL schema for relational and document databases
  • Query services and other APIs efficiently
  • Optimize GraphQL resolvers with data caching and batching
  • Cache a data graph for clients
  • Design GraphQL fragments that match UI components' data requirements

About the reader

For web developers familiar with building client-server applications.

About the author

Samer Buna has over 20 years of experience in software development including front-ends, back-ends, mobile apps, API design, databases, and scalability. He operates jsComplete.com.

placing your order...

Don't refresh or navigate away from the page.
Manning Early Access Program (MEAP) Read chapters as they are written, get the finished eBook as soon as it’s ready, and receive the pBook long before it's in bookstores.
print book $29.99 $49.99 pBook + eBook + liveBook
Additional shipping charges may apply
GraphQL in Action (print book) added to cart
continue shopping
go to cart

eBook $31.99 $39.99 3 formats + liveBook
GraphQL in Action (eBook) added to cart
continue shopping
go to cart

Prices displayed in rupees will be charged in USD when you check out.
customers also reading

This book 1-hop 2-hops 3-hops

FREE domestic shipping on three or more pBooks