Craft GraphQL APIs in Elixir with Absinthe
Flexible, Robust Services for Queries, Mutations, and Subscriptions
by Bruce Williams, Ben Wilson
Version: P1.0 (March 2018)
Copyright 2018 The Pragmatic Programmers, LLC. This book is licensed to the individual who purchased it. We don't copy-protect it because that would limit your ability to use it for your own purposes. Please don't break this trustyou can use this across all of your devices but please do not share this copy with other members of your team, with friends, or via file sharing services. Thanks.
Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and The Pragmatic Programmers, LLC was aware of a trademark claim, the designations have been printed in initial capital letters or in all capitals. The Pragmatic Starter Kit, The Pragmatic Programmer, Pragmatic Programming, Pragmatic Bookshelf and the linking g device are trademarks of The Pragmatic Programmers, LLC.
Every precaution was taken in the preparation of this book. However, the publisher assumes no responsibility for errors or omissions, or for damages that may result from the use of information (including program listings) contained herein.
About the Pragmatic Bookshelf
The Pragmatic Bookshelf is an agile publishing company. Were here because we want to improve the lives of developers. We do this by creating timely, practical titles, written by programmers for programmers.
Our Pragmatic courses, workshops, and other products can help you and your team create better software and have more fun. For more information, as well as the latest Pragmatic titles, please visit us at http://pragprog.com.
Our ebooks do not contain any Digital Restrictions Management, and have always been DRM-free. We pioneered the beta book concept, where you can purchase and read a book while its still being written, and provide feedback to the author to help make a better book for everyone. Free resources for all purchasers include source code downloads (if applicable), errata and discussion forums, all available on the book's home page at pragprog.com. Were here to make your life easier.
New Book Announcements
Want to keep up on our latest titles and announcements, and occasional special offers? Just create an account on pragprog.com (an email address and a password is all it takes) and select the checkbox to receive newsletters. You can also follow us on twitter as @pragprog.
About Ebook Formats
If you buy directly from pragprog.com, you get ebooks in all available formats for one price. You can synch your ebooks amongst all your devices (including iPhone/iPad, Android, laptops, etc.) via Dropbox. You get free updates for the life of the edition. And, of course, you can always come back and re-download your books when needed. Ebooks bought from the Amazon Kindle store are subject to Amazon's polices. Limitations in Amazon's file format may cause ebooks to display differently on different devices. For more information, please see our FAQ at pragprog.com/frequently-asked-questions/ebooks. To learn more about this book and access the free resources, go to https://pragprog.com/book/wwgraphql, the book's homepage.
Thanks for your continued support,
Andy Hunt
The Pragmatic Programmers
The team that produced this book includes: Andy Hunt (Publisher) Janet Furlow (VP of Operations) Brian MacDonald (Managing Editor) Jacquelyn Carter (Supervising Editor) Series editor: Bruce A. Tate Nicole Abramowitz (Copy Editor) Potomac Indexing, LLC (Indexing) Gilson Graphics (Layout)
For customer support, please contact .
For international rights, please contact .
Table of Contents
Copyright 2018, The Pragmatic Bookshelf.
Early Praise for Craft GraphQL APIs in Elixir with Absinthe
Like GraphQLs meteoric rise, this book is sure to be a breakout hitfor readers looking to revolutionize the way they write APIs. Ben andBruce combine their Absinthe expertise with their productionexperience to take readers from the basics of GraphQL to exercisingits most powerful features with Elixir and Phoenix.
Chris McCord |
Author, Phoenix framework |
If were lucky, about once per decade or so well come across a technology that has the chance to revolutionize the Web. GraphQL is one such set of technologies. This book is written by two of the industrys expertsco-authors of one of the best and most complete GraphQL implementations. Even if youre not planning to deploy on Elixir, this book will show you GraphQL done right.
Chad Fowler |
Microsoft and BlueYard Capital |
Absinthe single-handedly made one of the most critical and complex parts of Trailposts infrastructure the piece I worry about least. This book should be on the radar of anyone developing APIs in Elixir, and probably some who arent.
Daniel Pehrson |
Founder, Trailpost.com |
GraphQL is a broad but rewarding topic, and Bruce and Ben have covered it comprehensively. The book introduces the key GraphQL concepts in a very approachable way. It then makes sure you have all the tools and techniques to build robust, well-structured, and incredibly fast GraphQL APIs using Elixir, Absinthe, Ecto, and Phoenix. A killer combination for building amazing applications if ever there was one!
Josh Price |
Technical Director, Alembic |
GraphQL is a game changer, and now you can use it with Elixir! This book is an invaluable must-read for any Elixir developer. I referred to it often as I helped prepare our web team for the next generation of APIs.
Daniel Berkompas |
Senior Software Engineer, Infinite Red; Creator of LearnElixir.tv & LearnPhoenix.tv |
Acknowledgements
Wed like to thank our editor, Jackie Carter, and the rest of the staff at The Pragmatic Bookshelf for their guidance and assistance turning this book into a reality. While its a clich, writing a book is hard workand it would have been immeasurably more difficult without your help. Likewise, a small army of technical reviewersAndrea Leopardi, Brian OGrady, Chad Wooley, Chengyin Liu, Gabor Hajba, Jack Marchant, James Fish, Jesse Cooke, Kim Shieir, Lou Xun, Mark Goody, Nate Vick, Paulo A. Pereira, Rodrigo Franco, and Sebastian Koschhelped us improve the content and code in this book. Any remaining issues fall squarely and solely on our shoulders.
Bruce would like to thank his wife, Melissa, and their three sonsBraedyn, Jamis, and Colewithout whose love, support, and deep, abiding well of patience, no book would be worth writing (or would get done in the first place). Hed also like to thank Maria Gutierrez, a dear friend who hell eventually forgive for the gentle nudge that convinced him to invest the time to write another book.
Ben is grateful to his colleagues, friends, and family for their seemingly endless willingness to listen, offer advice, and humor the most insane ideas throughout this process. In particular, Ben wants to thank his wife, Becca, whose constant care and dedication to those around her serves as both an inspiration and a daily joy.
Finally, wed like to show our appreciation for those who have contributed to Absinthe, the project this book covers.
We deeply appreciate the time and encouragement given to us by Jos Valim and Chris McCord as the Absinthe project has grown. Their answers to hard questions and warnings about pitfalls, their open minds and imaginations, have made all the difference between the project becoming a fun yet subtly broken toy, and a robust, useful tool for the Elixir/Phoenix community they lead.