Craft GraphQL APIs in Elixir with Absinthe

Book description

Your domain is rich and interconnected, and your API should be too. Upgrade your web API to GraphQL, leveraging its flexible queries to empower your users, and its declarative structure to simplify your code. Absinthe is the GraphQL toolkit for Elixir, a functional programming language designed to enable massive concurrency atop robust application architectures. Written by the creators of Absinthe, this book will help you take full advantage of these two groundbreaking technologies. Build your own flexible, high-performance APIs using step-by-step guidance and expert advice you won't find anywhere else.

GraphQL is a new way of structuring and building web services, and the result is transformational. Find out how to offer a more tailored, cohesive experience to your users, easily aggregate data from different data sources, and improve your back end's maintainability with Absinthe's declarative approach to defining how your API works.

Build a GraphQL-based API from scratch using Absinthe, starting from core principles. Learn the type system and how to expand your schema to suit your application's needs. Discover a growing ecosystem of tools and utilities to understand, debug, and document your API. Take it to production, but do it safely with solid best practices in mind. Find out how complexity analysis and persisted queries can let you support your users flexibly, but responsibly too. Along the way, discover how Elixir makes all the difference for a high performance, fault-tolerant API. Use asynchronous and batching execution, or write your own custom add-ons to extend Absinthe. Go live with subscriptions, delivering data over websockets on top of Elixir (and Erlang/OTP's) famous solid performance and real-time capabilities.

Transform your applications with the powerful combination of Elixir and GraphQL, using Absinthe.

What You Need:

To follow along with the book, you should have Erlang/OTP 19+ and Elixir 1.4+ installed. The book will guide you through setting up a new Phoenix application using Absinthe.

Publisher resources

View/Submit Errata

Table of contents

  1.  Acknowledgements
  2.  Introduction
    1. About This Book
    2. About the Code
    3. Online Resources
  3. Part I. Build a GraphQL API
    1. 1. Meet GraphQL
      1. On the Client
      2. On the Server
      3. Absinthe and the Tech Stack
      4. Moving On
    2. 2. Building a Schema
      1. Preparing the Application
      2. Our Schema Module
      3. Making a Query
      4. Running Our Query with GraphiQL
      5. Testing Our Query
      6. Moving On
    3. 3. Taking User Input
      1. Defining Field Arguments
      2. Providing Field Argument Values
      3. Using Enumeration Types
      4. Modeling Input Objects
      5. Marking Arguments as Non-Null
      6. Creating Your Own Scalar Types
      7. Moving On
    4. 4. Adding Flexibility
      1. Organizing a Schema
      2. Understanding Abstract Types
      3. Using Named Fragments
      4. Moving On
    5. 5. Making a Change with Mutations
      1. Defining a Root Mutation Type
      2. Building the Resolver
      3. Handling Mutation Errors
      4. Moving On
    6. 6. Going Live with Subscriptions
      1. Setting Up Subscriptions
      2. Event Modeling
      3. Submitting Subscriptions
      4. Testing Subscriptions
      5. Subscription Triggers
      6. Moving On
  4. Part II. Publish Your API
    1. 7. Resolution Middleware
      1. Our First Module
      2. Applying Middleware
      3. Setting Defaults
      4. Moving On
    2. 8. Securing with Authentication and Authorization
      1. Logging In
      2. Using the Execution Context
      3. Securing Fields
      4. Structuring for Authorization
      5. Moving On
    3. 9. Tuning Resolution
      1. Understanding the Problem
      2. Using Built-in Plugins
      3. Discovering Dataloader
      4. Moving On
  5. Part III. Use Your API
    1. 10. Driving Phoenix Actions with GraphQL
      1. Building an Action
      2. Handling Input
      3. Complex Queries
      4. Moving On
    2. 11. Integrating with the Frontend
      1. Starting Simple
      2. Choosing a Framework
      3. Using Apollo Client
      4. Using Relay
      5. Wrapping Up
  6. A1. GraphQL Types
    1. Object
    2. InputObject
    3. Enum
    4. Interface
    5. Union
    6. Scalar Types
    7. Special Types
  7.  Bibliography

Product information

  • Title: Craft GraphQL APIs in Elixir with Absinthe
  • Author(s): Bruce Williams, Ben Wilson
  • Release date: March 2018
  • Publisher(s): Pragmatic Bookshelf
  • ISBN: 9781680502558