Adopting GraphQL in an Enterprise

Rate this content
Bookmark
Shruti Kapoor
Shruti Kapoor
32 min
08 Dec, 2021

Comments

Sign in or register to post your comment.

Video Summary and Transcription

Today's Talk is about adopting GraphQL in an enterprise. It discusses the challenges of using REST APIs and the benefits of GraphQL. The Talk explores different approaches to adopting GraphQL, including coexistence with REST APIs. It emphasizes the power of GraphQL and provides tips for successful adoption. Overall, the Talk highlights the advantages of GraphQL in terms of efficiency, collaboration, and control over APIs.

Available in Español: Adoptando GraphQL en una Empresa

1. Introduction to Adopting GraphQL in an Enterprise

Short description:

Today, I'm going to be talking about adopting GraphQL in an enterprise. We'll discuss the reasons why GraphQL is a good technology for an enterprise, our experience of adopting GraphQL in PayPal, the challenges we faced, best practices we adopted, and how to get started with GraphQL. I'm Shruti Kapoor, a senior software engineer at PayPal. Follow me on Twitter at Shruti Kapoor08 or Twitch at twitch.tv/ShrutiKapoor for live streaming sessions. When I started at PayPal, I had no experience with GraphQL, but we decided to use it as the frontend layer for a NodeJS app consuming REST APIs. The Checkout app was the first team to adopt GraphQL at PayPal, inspiring others to follow. Since then, GraphQL usage has grown significantly with 50 apps in production and a GraphQL public API powered by BrainTree. We provide support and training for teams adopting GraphQL.

Hello, everybody. Thank you for coming to my talk. Today, I'm going to be talking about adopting GraphQL in an enterprise. Before we get started in the talk, here's what we're going to talk about. We're going to talk about why GraphQL may be a good technology for an enterprise. Our story of adopting GraphQL in PayPal and the lessons we learned, the challenges we had, some best practices we adopted, and if you are interested in getting started with GraphQL, how you can get started.

Before I get started with my talk, I would introduce myself. My name is Shruti Kapoor. I'm a senior software engineer at PayPal. You can find me on Twitter at Shruti Kapoor08 or you can find me on Twitch at twitch.tv slash Shruti Kapoor where I share live streaming sessions of me working on something like a presentation like this. So I invite you to come and work on your side projects with me.

When we started adopting GraphQL at PayPal, when I first started PayPal I had actually never worked on GraphQL before. I kind of thought like GraphQL was like this technology that was used to fetch data, but I thought it was connected somehow to Facebook so I had no idea how to work with GraphQL. I thought it was related to GraphCMS and that was the extent of my knowledge. So when I got started at PayPal, my role in the team was to work on an internal project which was a brand new project and we were supposed to consume almost five internal APIs. These are all REST APIs. Our front-end application was supposed to be a NodeJS app, but what we used in the frontend of that NodeJS app was up to us and so we decided to use GraphQL as the frontend layer of that NodeJS app.

Why we decided to use GraphQL, I'll get into in a bit, but when I first got started into GraphQL at PayPal, there weren't a lot of people or a lot of teams that were using GraphQL. The main team that was using GraphQL was the Checkout app, which you may have seen when you check out at PayPal. That was actually the trailblazer of adoption of GraphQL at PayPal. They advocated GraphQL and the benefits of adopting GraphQL within PayPal and inspired the rest of the company to start adopting GraphQL. At the time, in 2018, we didn't have a lot of central support. Initially, teams were slowly starting to pick up GraphQL, but it was kind of very independent and dependent on the team itself to adopt GraphQL and kind of overcome challenges. Even the community was pretty early stages, but since then, a lot has changed outside in the community and at PayPal itself. Within PayPal, in the last three years, there's now 50 apps that use GraphQL in production. We do have a GraphQL public API as well that is powered by BrainTree. And in our internal Slack community, we have almost 500 members. So all of that is to say that GraphQL is picking up a lot in PayPal and we're heavily using GraphQL at PayPal. We have built internal tools to support GraphQL, especially the libraries that we had at PayPal. Now we provide infrastructure support and we provide training to adopt GraphQL for teams that are now adopting GraphQL, especially giving them some sample frontend apps and some sample backend apps to get them started easily on GraphQL.

2. Challenges of REST APIs and the Need for GraphQL

Short description:

GraphQL became the default pattern for frontend applications building a UI. We faced challenges with overfetching data from REST APIs, calling multiple APIs for one field, and maintaining consistency in integration. Upgrading APIs and dealing with inconsistent field names added complexity. We needed a technology that provided a uniform experience and easy integration. Detailed analytics and intelligent deprecation were also important. Versioning APIs posed challenges, and adding more data required considering breaking changes and client updates.

And for any frontend application that's building a UI, GraphQL has now become a default pattern for adopting, for putting it as the frontend layer of UI. Our reasons to adopt GraphQL at the time could be explained by understanding what our challenges at the time were. So when we were thinking of adopting a new technology or when we were thinking of a solution actually, these were some of the problems that we had at the time.

Our number one problem was that because, and this is specifically in regards to our company being a heavily REST, heavily REST API powered company, so we did have a lot of REST APIs and our frontend application that we were working on was supposed to talk to five different REST APIs. What ended up happening was that our UI may need like one field, but to get that one field, we would have to call a REST endpoint and the REST endpoint may be servicing a bunch of different UI applications as well. And so what ended up happening was we would call the REST API and we would get lots of overfetched data and that data would have to throw away on the client side and only use that one field. So one of the problems, one of the biggest problems we were facing at the time was we were fetching too much data from REST APIs and not using all of it.

And because we had so many different REST APIs, we also had to figure out which API to call to get the information we needed. And what that often involved was we first have to get authenticated from an API, then we'd have to use that token to call another API, maybe we get the user's ID from that information, from that API, and then we'd use that ID to maybe call their profile API and get their name and such and maybe their balance and such information. So basically what ended up happening was we'd call multiple round trips, use one field from one API and send it over to another API. And so that led to a lot of frustration because we were calling so many different APIs on our front-end applications.

Also because we were heavily versioned APIs, what ended up happening was that we would release a new version and if we had to update a field or if we had to rename a field, anybody who would be integrated with the previous version would now become outdated. And it was becoming really hard for us to deliver updates to these clients. It wasn't always feasible for clients to upgrade to our latest versions. So what ended up happening was most of our clients started staying on the older version while we were publishing newer versions of the API. Another problem was because we had REST APIs all across the board, what may have happened is that one field was called something else in one API like username, but something else in the other API like user or name. And so the integration experience itself was also very inconsistent. So as a frontend developer, we had to figure out what maybe do some formatting on the client end side, even to call the API itself and format our data before we send it to the server side. So the integration experience itself was quite inconsistent. So the right candidate that we were looking, would provide us the ability to have a uniform experience for all of the APIs that we were about to fetch across the board. And another important thing was the ease of integration across the board. So we wanted to make sure that the API, that the technology we would use, would not require a client, especially our sister companies, to have any prior information about our APIs itself. So for example, if our sister company like Braintree had to integrate with PayPal, we didn't want Braintree to know the ins and outs of calling a REST API, or calling an API on PayPal's side. We wanted them to have an easy interface that they could just integrate with, something that they'd be familiar with, without having to worry about what goes behind the scenes. Another thing that we wanted was because we were pushing out updates and we wanted to deprecate fields intelligently, we wanted to make sure that we have detailed analytics on which field was being used from the graph QL endpoints, or from our REST endpoints, or from our API endpoints. So we wanted to make sure that if we are pushing out updates, we are doing them intelligently and we have instrumentation behind those. Another thing that we noticed that was happening in our teams was our frontend and backend developers often would have this conversation. So the frontend developers would say like, we need to add more data. And one of the questions that was asked is, should we get version APIs? But the problem with version API is that if you do introduce breaking changes, then what is the best practice of introducing a breaking change? And if you go from V1 to V2, what happens to all of the clients that are not integrated with V2 yet? They do not get the updates yet. So what is the best solution there? Another alternative is if you need to ask more data.

Check out more articles and videos

We constantly think of articles and videos that might spark Git people interest / skill us up or help building a stellar career

From GraphQL Zero to GraphQL Hero with RedwoodJS
GraphQL Galaxy 2021GraphQL Galaxy 2021
32 min
From GraphQL Zero to GraphQL Hero with RedwoodJS
Top Content
We all love GraphQL, but it can be daunting to get a server up and running and keep your code organized, maintainable, and testable over the long term. No more! Come watch as I go from an empty directory to a fully fledged GraphQL API in minutes flat. Plus, see how easy it is to use and create directives to clean up your code even more. You're gonna love GraphQL even more once you make things Redwood Easy!
Local State and Server Cache: Finding a Balance
Vue.js London Live 2021Vue.js London Live 2021
24 min
Local State and Server Cache: Finding a Balance
Top Content
How many times did you implement the same flow in your application: check, if data is already fetched from the server, if yes - render the data, if not - fetch this data and then render it? I think I've done it more than ten times myself and I've seen the question about this flow more than fifty times. Unfortunately, our go-to state management library, Vuex, doesn't provide any solution for this.For GraphQL-based application, there was an alternative to use Apollo client that provided tools for working with the cache. But what if you use REST? Luckily, now we have a Vue alternative to a react-query library that provides a nice solution for working with server cache. In this talk, I will explain the distinction between local application state and local server cache and do some live coding to show how to work with the latter.
Batteries Included Reimagined - The Revival of GraphQL Yoga
GraphQL Galaxy 2021GraphQL Galaxy 2021
33 min
Batteries Included Reimagined - The Revival of GraphQL Yoga
The Guild has recently released Envelop - a new, modern GraphQL Server Framework and plugin system. In this talk I’ll share a brief overview of Envelop and why you should probably upgrade your existing GraphQL server to it.
Rock Solid React and GraphQL Apps for People in a Hurry
GraphQL Galaxy 2022GraphQL Galaxy 2022
29 min
Rock Solid React and GraphQL Apps for People in a Hurry
In this talk, we'll look at some of the modern options for building a full-stack React and GraphQL app with strong conventions and how this can be of enormous benefit to you and your team. We'll focus specifically on RedwoodJS, a full stack React framework that is often called 'Ruby on Rails for React'.
Step aside resolvers: a new approach to GraphQL execution
GraphQL Galaxy 2022GraphQL Galaxy 2022
16 min
Step aside resolvers: a new approach to GraphQL execution
Though GraphQL is declarative, resolvers operate field-by-field, layer-by-layer, often resulting in unnecessary work for your business logic even when using techniques such as DataLoader. In this talk, Benjie will introduce his vision for a new general-purpose GraphQL execution strategy whose holistic approach could lead to significant efficiency and scalability gains for all GraphQL APIs.

Workshops on related topic

Build with SvelteKit and GraphQL
GraphQL Galaxy 2021GraphQL Galaxy 2021
140 min
Build with SvelteKit and GraphQL
Top Content
Featured WorkshopFree
Scott Spence
Scott Spence
Have you ever thought about building something that doesn't require a lot of boilerplate with a tiny bundle size? In this workshop, Scott Spence will go from hello world to covering routing and using endpoints in SvelteKit. You'll set up a backend GraphQL API then use GraphQL queries with SvelteKit to display the GraphQL API data. You'll build a fast secure project that uses SvelteKit's features, then deploy it as a fully static site. This course is for the Svelte curious who haven't had extensive experience with SvelteKit and want a deeper understanding of how to use it in practical applications.

Table of contents:
- Kick-off and Svelte introduction
- Initialise frontend project
- Tour of the SvelteKit skeleton project
- Configure backend project
- Query Data with GraphQL
- Fetching data to the frontend with GraphQL
- Styling
- Svelte directives
- Routing in SvelteKit
- Endpoints in SvelteKit
- Deploying to Netlify
- Navigation
- Mutations in GraphCMS
- Sending GraphQL Mutations via SvelteKit
- Q&A
End-To-End Type Safety with React, GraphQL & Prisma
React Advanced Conference 2022React Advanced Conference 2022
95 min
End-To-End Type Safety with React, GraphQL & Prisma
Featured WorkshopFree
Sabin Adams
Sabin Adams
In this workshop, you will get a first-hand look at what end-to-end type safety is and why it is important. To accomplish this, you’ll be building a GraphQL API using modern, relevant tools which will be consumed by a React client.
Prerequisites: - Node.js installed on your machine (12.2.X / 14.X)- It is recommended (but not required) to use VS Code for the practical tasks- An IDE installed (VSCode recommended)- (Good to have)*A basic understanding of Node.js, React, and TypeScript
GraphQL for React Developers
GraphQL Galaxy 2022GraphQL Galaxy 2022
112 min
GraphQL for React Developers
Featured Workshop
Roy Derks
Roy Derks
There are many advantages to using GraphQL as a datasource for frontend development, compared to REST APIs. We developers in example need to write a lot of imperative code to retrieve data to display in our applications and handle state. With GraphQL you cannot only decrease the amount of code needed around data fetching and state-management you'll also get increased flexibility, better performance and most of all an improved developer experience. In this workshop you'll learn how GraphQL can improve your work as a frontend developer and how to handle GraphQL in your frontend React application.
Build a Headless WordPress App with Next.js and WPGraphQL
React Summit 2022React Summit 2022
173 min
Build a Headless WordPress App with Next.js and WPGraphQL
Top Content
WorkshopFree
Kellen Mace
Kellen Mace
In this workshop, you’ll learn how to build a Next.js app that uses Apollo Client to fetch data from a headless WordPress backend and use it to render the pages of your app. You’ll learn when you should consider a headless WordPress architecture, how to turn a WordPress backend into a GraphQL server, how to compose queries using the GraphiQL IDE, how to colocate GraphQL fragments with your components, and more.
Relational Database Modeling for GraphQL
GraphQL Galaxy 2020GraphQL Galaxy 2020
106 min
Relational Database Modeling for GraphQL
Top Content
WorkshopFree
Adron Hall
Adron Hall
In this workshop we'll dig deeper into data modeling. We'll start with a discussion about various database types and how they map to GraphQL. Once that groundwork is laid out, the focus will shift to specific types of databases and how to build data models that work best for GraphQL within various scenarios.
Table of contentsPart 1 - Hour 1      a. Relational Database Data Modeling      b. Comparing Relational and NoSQL Databases      c. GraphQL with the Database in mindPart 2 - Hour 2      a. Designing Relational Data Models      b. Relationship, Building MultijoinsTables      c. GraphQL & Relational Data Modeling Query Complexities
Prerequisites      a. Data modeling tool. The trainer will be using dbdiagram      b. Postgres, albeit no need to install this locally, as I'll be using a Postgres Dicker image, from Docker Hub for all examples      c. Hasura
Building GraphQL APIs on top of Ethereum with The Graph
GraphQL Galaxy 2021GraphQL Galaxy 2021
48 min
Building GraphQL APIs on top of Ethereum with The Graph
WorkshopFree
Nader Dabit
Nader Dabit
The Graph is an indexing protocol for querying networks like Ethereum, IPFS, and other blockchains. Anyone can build and publish open APIs, called subgraphs, making data easily accessible.

In this workshop you’ll learn how to build a subgraph that indexes NFT blockchain data from the Foundation smart contract. We’ll deploy the API, and learn how to perform queries to retrieve data using various types of data access patterns, implementing filters and sorting.

By the end of the workshop, you should understand how to build and deploy performant APIs to The Graph to index data from any smart contract deployed to Ethereum.