O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Learning GraphQL

Book Description

With Early Release ebooks, you get books in their earliest form — the author's raw and unedited content as he or she writes — so you can take advantage of these technologies long before the official release of these titles. You'll also receive updates when significant changes are made, new chapters are available, and the final ebook bundle is released.

GraphQL, a data query language that provides an alternative to REST and ad-hoc webservice architectures, is the most revolutionary technology for data fetching since Ajax. Just as React has changed the way web developers approach UI, GraphQL will change the way web developers work with data over HTTP. This practical guide simplifies the process of getting started with this language.

Alex Banks and Eve Porcello, software engineers/architects and instructors, start with an overview of graph theory to provide a solid understanding of the powerful graph data structure. You'll then learn about GraphQL types, as well as how to build a schema to describe your API. This book also includes an overview of Apollo and Relay, two popular frameworks that are used to connect GraphQL to your user interface.

Table of Contents

  1. Preface
    1. Conventions Used in This Book
    2. Using Code Examples
    3. O’Reilly Safari
    4. How to Contact Us
    5. Acknowledgments
  2. 1. Welcome to GraphQL
    1. What is GraphQL?
      1. The GraphQL Specification
      2. Design Principles of GraphQL
    2. Origins of GraphQL
    3. History of Data Transport
      1. RPC
      2. SOAP
      3. REST
    4. REST Drawbacks
      1. Overfetching
      2. Underfetching
      3. Managing REST Endpoints
    5. GraphQL in the Real World
      1. GraphQL Clients
  3. 2. Graph Theory
    1. Graph Theory Vocabulary
    2. History of Graph Theory
    3. Trees are Graphs
    4. Graphs in the Real World
  4. 3. The GraphQL Query Language
    1. GraphQL API Tools
      1. GraphiQL
      2. GraphQL Playground
      3. Public GraphQL APIs
    2. The GraphQL Query
      1. Edges and Connections
      2. Fragments
    3. Mutations
      1. Using Query Variables
    4. Subscriptions
    5. Introspection
    6. Abstract Syntax Trees
  5. 4. Designing a Schema
    1. Defining Types
      1. Types
      2. Scalar Types
      3. Enums
    2. Connections and Lists
      1. One-to-One Connections
      2. One-to-Many Connections
      3. Many-to-Many Connections
      4. Lists of Different Types
    3. Arguments
      1. Filtering Data
    4. Mutations
    5. Input Types
    6. Return Types
    7. Subscriptions
    8. Schema Documentation
  6. 5. Creating a GraphQL API
    1. Resolvers
      1. Root Resolvers
      2. Type Resolvers
      3. Using Inputs and Enums
      4. Edges & Connections
      5. Custom Scalars
    2. GraphQL Servers
      1. GraphQL Yoga
    3. Context
      1. Installing Mongo
      2. Adding Database to Context
    4. GitHub Authorization
      1. Setting Up GitHub OAuth
      2. The Authorization Process
      3. githubAuth Mutation
      4. Authenticating Users
    5. Conclusion
  7. 6. GraphQL Clients
    1. Using a GraphQL API
      1. fetch Requests
      2. graphql-request
    2. Apollo Client
      1. Project Setup
      2. Apollo Link
      3. Apollo Client and Cache
    3. Apollo with React
      1. The Query Component
      2. The Mutation Component
    4. Authorization
      1. Authorizing the User
      2. Identifying the User
      3. Logging Out
  8. 7. GraphQL in the Real World
    1. Subscriptions
      1. Working with Subscriptions
      2. Consuming Subscriptions
    2. Uploading Files
      1. Handling Uploads on the Server
      2. Posting a New Photo with Apollo
    3. Security
      1. Request Timeouts
      2. Data Limitations
      3. Limiting Query Depth
      4. Limiting Query Complexity
      5. Monitoring your API
  9. 8. Taking the Next Steps
    1. Incremental Migration
    2. Schema-First Development
    3. GraphQL Events
    4. Community
    5. Community Slack Channels
  10. Index