Professional Documents
Culture Documents
Wiley GQL-Arch. FINAL 11 7 22-v3 PDF
Wiley GQL-Arch. FINAL 11 7 22-v3 PDF
by Brian Culp
These materials are © 2022 John Wiley & Sons, Inc. Any dissemination, distribution, or unauthorized use is strictly prohibited.
Choosing a GraphQL Architecture For Dummies®, Apollo
Special Edition
Published by
John Wiley & Sons, Inc.
111 River St.
Hoboken, NJ 07030-5774
www.wiley.com
Copyright © 2022 by John Wiley & Sons, Inc.
No part of this publication may be reproduced, stored in a retrieval system or transmitted in any
form or by any means, electronic, mechanical, photocopying, recording, scanning or otherwise,
except as permitted under Sections 107 or 108 of the 1976 United States Copyright Act, without
the prior written permission of the Publisher. Requests to the Publisher for permission should be
addressed to the Permissions Department, John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ
07030, (201) 748-6011, fax (201) 748-6008, or online at http://www.wiley.com/go/permissions.
Trademarks: Wiley, For Dummies, the Dummies Man logo, The Dummies Way, Dummies.com,
Making Everything Easier, and related trade dress are trademarks or registered trademarks of
John Wiley & Sons, Inc. and/or its affiliates in the United States and other countries, and may not
be used without written permission. Apollo Graph and the Apollo Graph logo are registered
trademarks of Apollo Graph. All other trademarks are the property of their respective owners.
John Wiley & Sons, Inc., is not associated with any product or vendor mentioned in this book.
For general information on our other products and services, or how to create a custom For
Dummies book for your business or organization, please contact our Business Development
Department in the U.S. at 877-409-4177, contact info@dummies.biz, or visit www.wiley.com/go/
custompub. For information about licensing the For Dummies brand for products or services,
contact BrandedRights&Licenses@Wiley.com.
ISBN: 978-1-119-89988-4 (pbk); ISBN: 978-1-119-89989-1 (ebk). Some blank pages in the print
version may not be included in the ePDF version.
Publisher’s Acknowledgments
Some of the people who helped bring this book to market include the following:
Project Manager: Carrie Acquisitions Editor: Ashley Coffey
Burchfield-Leighton Client Account Manager: Cynthia
Sr. Managing Editor: Rev Mengle Tweed
Managing Editor: Camille Graves
These materials are © 2022 John Wiley & Sons, Inc. Any dissemination, distribution, or unauthorized use is strictly prohibited.
Introduction
T hirty million GraphQL downloads on NPM (npmcharts.com)
can’t be wrong. And that’s 30 million per month, by the way.
Introduction 1
These materials are © 2022 John Wiley & Sons, Inc. Any dissemination, distribution, or unauthorized use is strictly prohibited.
»» Developers and engineers: Whether you’re on a client team
building features utilizing your graph or actively maintaining
a GraphQL server, this book should provide a better
understanding of how your work aligns to a broader
GraphQL strategy.
The Tip icon points out practical advice that saves you time and
effort when designing/consolidating your graph.
These materials are © 2022 John Wiley & Sons, Inc. Any dissemination, distribution, or unauthorized use is strictly prohibited.
IN THIS CHAPTER
»» Finding solutions to problems with
GraphQL
Chapter 1
Understanding GraphQL
I
f you’re reading this sentence, you’re likely using or consider-
ing using GraphQL already, or at the very least you’re familiar
with some of the issues it solves — problems like underfetching
or overfetching.
These materials are © 2022 John Wiley & Sons, Inc. Any dissemination, distribution, or unauthorized use is strictly prohibited.
scored. What I describe here is the textbook underfetching prob-
lem of REST. One query doesn’t always fetch all the data you want.
Or, the API you use may retrieve all stats from all players. Your
job, then, would be to sift through the results of that massive
pile of soccer player information and display just the desired data:
something like the name and number of goals to date. This data
dump of too much information sums up the overfetching problem.
To get the most out of your GraphQL stack, make sure you’re using
the recommended architecture. The rest of this book explores this
very topic.
These materials are © 2022 John Wiley & Sons, Inc. Any dissemination, distribution, or unauthorized use is strictly prohibited.
IN THIS CHAPTER
»» Managing suboptimal GraphQL
architectures
Chapter 2
Facing Common
GraphQL Architectures
Challenges
I
n this chapter, you look at the options available for engineers
and software architects planning a GraphQL implementation or
optimizing an existing one. As with any tool, if you don’t use it
in the way it was designed, chaos can ensue.
These materials are © 2022 John Wiley & Sons, Inc. Any dissemination, distribution, or unauthorized use is strictly prohibited.
Looking at GraphQL Architecture Options
Graphs are powerful tools for modeling many real-world phenom-
ena because they resemble our natural mental models and verbal
descriptions of the underlying business. Best practice, then, dic-
tates that you think of your business domain as a graph and then
define the schema accordingly. If it helps, think of your GraphQL
schema as a shared language for both your team and your users.
Monolith
Teams eager to reap the benefits of GraphQL’s client-centric
data-fetching capabilities charge ahead and implement a GraphQL
application programming interface (API) within the context of
their, and only their, use case. But other teams soon want to get
in on the act. The result is a heroic attempt at company after com-
pany setting about designing the one perfect schema — the one
schema that will serve all the companies needs for all time.
The monolith pattern can take on two forms. In its first form,
teams may share one codebase for a GraphQL server that’s used
by one or more clients. In some cases, client code may even live
in the same repository as the GraphQL server. No matter how the
code is organized, ownership of this graph is shared by the differ-
ent developers who contribute to the graph.
These materials are © 2022 John Wiley & Sons, Inc. Any dissemination, distribution, or unauthorized use is strictly prohibited.
teams often solve the issue (or try to) by adding more schemas.
This becomes an architecture pattern known as Backend for
Frontend (BFF). You can learn more about BFFs at samnewman.io/
patterns/architectural/bff.
As a solution, BFFs add a new layer where each client has a ded-
icated BFF service that directly receives the client’s requests and
is tightly coupled to that user experience. For teams creating
BFF services, GraphQL can be a natural fit for building out this
intermediary.
So what’s the issue? Why not just stop there? Because BFFs also
don’t scale well. In fact, BFFs end up resembling the problem that
GraphQL is so good at solving. BFFs result in duplicated logic and
more surface area to maintain. Additionally, BFFs lead to capabil-
ity gaps between platforms.
These materials are © 2022 John Wiley & Sons, Inc. Any dissemination, distribution, or unauthorized use is strictly prohibited.
The supergraph
Apollo Federation was first announced in 2019 as a better
approach to monoliths, BFFs, and schema stitched graphs. With
Apollo Federation, you create a supergraph composed of sub-
graphs that can be maintained by independent backend teams.
The supergraph provides both a unified interface and modular
architecture for building your GraphQL API. Learn more about the
supergraph here: www.apollographql.com/supergraph.
These materials are © 2022 John Wiley & Sons, Inc. Any dissemination, distribution, or unauthorized use is strictly prohibited.
IN THIS CHAPTER
»» Looking GraphQL architecture attributes
Chapter 3
Choosing the Right
GraphQL Architecture
T
he architecture that you choose is whatever delivers the
most value for your company. That said, there’s a reason
this book exists, and one of those reasons is to convey the
notion that some architectures are better choices than others.
These materials are © 2022 John Wiley & Sons, Inc. Any dissemination, distribution, or unauthorized use is strictly prohibited.
» Incremental adoption: For most teams, a “big bang” rewrite
of all existing GraphQL application programming interfaces
(APIs) or all portions of a monolithic GraphQL schema may
not be fruitful or even advisable. Taking an incremental
approach to building the graph allows you to gradually
define services boundaries, identify appropriate connection
points, and learn as you go.
» Separation of concerns: The schema should be separated
by concerns and not types. Types will often contain fields
that can’t be neatly encapsulated within a single service’s
boundaries.
So why all the fuss? This section shows you all the benefits of the
supergraph.
These materials are © 2022 John Wiley & Sons, Inc. Any dissemination, distribution, or unauthorized use is strictly prohibited.
Apollo has authored the Principled GraphQL manifesto, which
is brief, inspirational, and definitely worth a few minutes of
your time. Take time to check it out at https://principle
dgraphql.com.
It’s flexible
From a data request/retrieval standpoint, the supergraph is flex-
ible for the front end and does it all, connecting a wide variety of
data and application services. If you’re working at a company that
makes apps for soccer fans, for example, you could use a super-
graph to connect many disparate services, facilitating a complete
view of a fan data: age, income bracket, past ticket orders, and
much more. It can also connect to many different consumers,
powering front-end experiences across many platforms such as
websites, iOS, Android, voice, and watch apps.
It’s robust
The Apollo Router is robust for the back end and both stateless
and horizontally scalable. Capable of serving demanding work-
loads, it powers some of the largest supergraphs in the world.
What’s more, adopting managed federation lets you decou-
ple schema delivery from schema deployment by hosting your
schema in cloud registry, which can be integrated with your con-
tinuous integration and continuous delivery (CI/CD) to validate
that schema changes don’t break your applications.
It’s demand-driven
GraphQL’s value lies in providing an abstraction between services
and consumers, so the schema shouldn’t be tightly coupled either
to one service implementation or one consumer. To accomplish
this, the supergraph utilizes a demand-oriented schema that
provides a superior developer experience for app developers. This
standard helps prevent the graph from becoming coupled to a
service implementation that could change in the future.
It’s agile
The supergraph architecture follows Agile software development
principles. Subgraphs can be added incrementally, and its imple-
mentation can (and should) use a phased approach, with regu-
lar periods to inspect and adapt, making sure value is delivered
These materials are © 2022 John Wiley & Sons, Inc. Any dissemination, distribution, or unauthorized use is strictly prohibited.
to your software team. You can start with just one subgraph and
gradually add more and more subgraphs that represent more
business domains.
It’s fast
Development teams have the ability to work independently
because they can now traverse a single supergraph to get the data
they need. As a result, features go from ticket to production much
faster, increasing the time to value. Backend teams can contribute
independently to the supergraph, and their changes can be auto-
matically composed into the supergraph.
These materials are © 2022 John Wiley & Sons, Inc. Any dissemination, distribution, or unauthorized use is strictly prohibited.
IN THIS CHAPTER
»» Discussing your architecture
Chapter 4
Ten Questions for
Proceeding with a
Supergraph
S
oftware architects juggle hundreds of data points in order to
design the digital blueprint for a team or an enterprise. How
do they get many of those key data points? By asking the
right questions. At a strategic level, evolving to a supergraph
implementation can be measured reliably by using a question
matrix. By answering these questions periodically, technology
leaders are better prepared to evaluate when, and how, to proceed
with adopting a Supergraph. This chapter looks at those key ques-
tions, with guidance to follow.
These materials are © 2022 John Wiley & Sons, Inc. Any dissemination, distribution, or unauthorized use is strictly prohibited.
delivered to the customer — instead of the feature. How you
answer the question “What needs or painpoints motivate
adoption?” is your touchstone as you move to a supergraph.
» Are multiple teams contributing to your graph? If this is
an initial federated implementation, identify your graph
champions — people who advocate for your graph and help
drive adoption — and establish education, review, and
governance processes. Your organization’s Graph
Champions use their foresight and influence to shape an
organization’s technology adoption.
» How many services do you support? More services make
for a larger, more complex GraphQL schema, which means
additional governance for that schema. The supergraph also
provides value as an abstraction layer, allowing you to evolve
your backend services over time without having to make
changes to your clients. A supergraph can make it easier for
many teams to share capabilities across service boundaries.
To review the federated decision matrix, visit www.apollo
graphql.com/docs/enterprise-guide/graphql-
consolidation.
» How many clients consume the application program-
ming interface (API)? What are the demands being put on
the API? What part of your schema can be generalized and
what needs to be specific for a given client. Speaking with
frontend and mobile engineers that consume your graph
helps you determine what their painpoints are and how to
educate them more effectively. A supergraph reduces the
number of bespoke APIs you have to build as client develop-
ers can self-serve capabilities out of your supergraph.
» How distributed are your teams? Companies operating
across multiple time zones benefit from the decoupled/
distributed approach made possible by the supergraph. The
supergraph’s federated architecture empowers teams to
work independently and still contribute to a cohesive whole.
» Who owns what? How are the tasks and responsibilities
divided among your team? The supergraph enables a shared
ownership architecture that offers a more scalable and
flexible solution for most teams.
» Are your teams autonomous? When autonomous teams
working on the same monolithic architecture make changes
according to mismatched schedules, chaos ensues. Slower
release cycles are usually the result.
These materials are © 2022 John Wiley & Sons, Inc. Any dissemination, distribution, or unauthorized use is strictly prohibited.
WILEY END USER LICENSE AGREEMENT
Go to www.wiley.com/go/eula to access Wiley’s ebook EULA.