Learning GraphQL

Book description

Why is GraphQL the most innovative technology for fetching data since Ajax? By providing a query language for your APIs and a runtime for fulfilling queries with your data, GraphQL presents a clear alternative to REST and ad hoc web service architectures. With this practical guide, Alex Banks and Eve Porcello deliver a clear learning path for frontend web developers, backend engineers, and project and product managers looking to get started with GraphQL.

Youâ??ll explore graph theory, the graph data structure, and GraphQL types before learning hands-on how to build a schema for a photo-sharing application. This book also introduces you to Apollo Client, a popular framework you can use to connect GraphQL to your user interface.

  • Explore graph theory and review popular graph examples in use today
  • Learn how GraphQL applies database querying methods to the internet
  • Create a schema for a PhotoShare application that serves as a roadmap and a contract between the frontend and backend teams
  • Use JavaScript to build a fully functioning GraphQL service and Apollo to implement a client
  • Learn how to prepare GraphQL APIs and clients for production

Publisher resources

View/Submit Errata

Table of contents

  1. Preface
    1. Acknowledgments
    2. Conventions Used in This Book
    3. Using Code Examples
    4. O’Reilly Safari
    5. How to Contact Us
  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. Remote Procedure Call
      2. Simple Object Access Protocol
      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. Project Setup
    2. Resolvers
      1. Root Resolvers
      2. Type Resolvers
      3. Using Inputs and Enums
      4. Edges and Connections
      5. Custom Scalars
    3. apollo-server-express
    4. Context
      1. Installing Mongo
      2. Adding Database to Context
    5. GitHub Authorization
      1. Setting Up GitHub OAuth
      2. The Authorization Process
      3. githubAuth Mutation
      4. Authenticating Users
    6. Conclusion
  7. 6. GraphQL Clients
    1. Using a GraphQL API
      1. fetch Requests
      2. graphql-request
    2. Apollo Client
    3. Apollo Client with React
      1. Project Setup
      2. Configure Apollo Client
      3. The Query Component
      4. The Mutation Component
    4. Authorization
      1. Authorizing the User
      2. Identifying the User
    5. Working with the Cache
      1. Fetch Policies
      2. Persisting The Cache
      3. Updating the Cache
  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 Client
    3. Security
      1. Request Timeouts
      2. Data Limitations
      3. Limiting Query Depth
      4. Limiting Query Complexity
      5. Apollo Engine
    4. Taking the Next Steps
      1. Incremental Migration
      2. Schema-First Development
      3. GraphQL Events
      4. Community
      5. Community Slack Channels
  9. Index

Product information

  • Title: Learning GraphQL
  • Author(s): Eve Porcello, Alex Banks
  • Release date: August 2018
  • Publisher(s): O'Reilly Media, Inc.
  • ISBN: 9781492030713