Let's Talk GraphQL With Your Services

Rate this content
Bookmark

GraphQL is a query language for APIs, but what if your API doesn't support GraphQL? There's a lot of information on how you can use GraphQL to make your APIs more readable or even more content on using GraphQL as a data layer for your existing APIs. This all makes perfect sense, but what if you actually want to know how to transform existing services to GraphQL? In this talk I'll demonstrate how you can use your existing services to create GraphQL schemas using Abstract Syntax Trees and TypeScript.

This is not a talk to show how to wrap services with GraphQL, in this talk I'll show data models to use an AST to transform existing services to GraphQL. Also, thinking patterns and best class approaches will be shown.

Roy Derks
Roy Derks
28 min
02 Jul, 2021

Comments

Sign in or register to post your comment.

Video Summary and Transcription

This talk explores the use cases for GraphQL with existing services and legacy code, focusing on an e-commerce platform. It discusses the challenges of using REST and the benefits of using GraphQL. The talk covers different approaches to implementing GraphQL with existing services, such as using libraries like GraphQL Mesh or creating a custom data layer. It also discusses the importance of mapping data specifications to a GraphQL schema and creating resolvers. The talk concludes by highlighting the benefits of using GraphQL for client-facing applications.

1. Introduction to GraphQL and Existing Services

Short description:

Hi, welcome everyone. Today, I will present use cases for GraphQL with existing services and legacy code. We'll explore how to talk GraphQL with existing services, specifically in the context of an e-commerce platform. The platform uses JavaScript, React, a REST API, and a database. We'll discuss the challenges of using REST and the benefits of using GraphQL to connect all the components together.

Hi, welcome everyone. So this is Roy at GraphQL Galaxy with Let's Talk GraphQL with your services. So what does this talk about? So during today, I will present you some use cases for GraphQL also with existing services. So let's have a look at legacy codes. It might look like this, right? Or is this actually PASTA? I'm not sure if you know, but what was the last time you tried talking with PASTA? For me it was never. So let's assume we're going to be looking at existing services as legacy code.

So a little bit about myself. So my name is Roy. You can find me on Twitter with Github team. Currently, I work for a renewable energy company called Vanderbrand, previously I worked for a lot of different companies, including the city of Amsterdam, most lately, where we created open source projects for the city. And also, you can find me online on YouTube either with conference videos from previous times or some of my books about React or React Native. And in the topic of today, my most current book about Fullstack GraphQL. So this is a book about how you can build GraphQL servers and clients with React, Node.js and TypeScript. So if you have any questions afterwards, make sure to get it.

So for today, we're going to be looking at how you can talk GraphQL with existing services. So suppose you start working on this great project, you would just get hired at a new job, or maybe a new project starts at your current company. And this one is called the e-commerce platform of the future. Probably you've been approached by recruiters that had something similar like this, like hey, we're going to build the e-commerce platform of the future, we want you to be part of it. Well, let's assume you fell into this trick and you started working at a company that is going to build this platform. So this might be the stack, right? So we have, on the left, you can see an example UI and on the right, you can see technologies. So it's using JavaScript and React, which all seems fine. And then it's using a REST API with a database and a database as a back-end. So, maybe after seeing this, you're thinking it's an e-commerce platform, but it might not be the e-commerce platform of the future. If you think by now, that's okay. If you think it's still the e-commerce platform of the future, that's also okay, because we might be able to find another way to use this platform and make it future-proof. Or you might also think the REST API and the database together are like the pretty bowl of spaghetti we saw before, which is the legacy code that we're going to be interacting with. So still, we have some legacy code back end, we have JavaScript and React, and we somehow want to connect all this together with GraphQL, because if it's using REST, it's going to lead to several problems, right? Because this might be the REST API, you have three different requests, or maybe even more, and all these requests will be called by your UI. So every single bits and pieces of our UI is using a separate REST API call, which in the end is going to be troublesome for people that are using mobile internet. And these often are directly correlated to a database. So we have a REST API and we have database, and those are closely linked together.

2. Using GraphQL with Existing Services

Short description:

So every table in your database will have a separate API call that returns JSON. We want to prevent separate requests, parsing, and normalization in the UI. Let's find a way to use GraphQL with the backend without touching the legacy code. One option is to use existing libraries like GraphQL Mesh. Another approach is to create our own data layer, providing simplified access to legacy code using GraphQL. This helps with caching, monitoring, and prevents mistakes in legacy code changes.

So every table in your database will have a separate API call that will work like this in the UI. And all these API calls will also return some JSON, that might be a lot of JSON, and you're actually using small pieces of this JSON. So once you've seen this, you're probably thinking we should start using GraphQL for this, and that's exactly what we're going to be looking at today. So we don't want to do this, having all these separate requests that return a lot of JSON, it all needs to be going into our UI, that needs to be parsed, it needs to be normalized. That's something you absolutely want to prevent.

So this can be done more efficiently, like we already saw, and this is of course with GraphQL. But the service isn't using GraphQL already. So let's try and find a way to have this backend service interact using GraphQL with our frontend UI. And let's do this in a way that we don't have to touch the legacy code or the PASTA or Spaghetti or whatsoever that's living there on the back. So what we want to prevent is having to touch anything that has been built by previous developers.

So you have multiple options to do this. And I believe one of the best options is using existing libraries, because it's going to get rid of a lot of stuff. It's going to prevent you from making mistakes, it's going to prevent you from having to maintain another service. And for this, I would definitely advise you to use GraphQL Mesh. I believe Uri Goldstein is also a speaker today, or maybe he already presented. I'm not sure. At least Uri will be probably will be talking a bit about GraphQL Mesh and how you can use it. And if you want to stay away from making any custom code, it's definitely a way to go. But for today, we're going to be looking at a different approach. And this is by creating your own data layer or data access layer. And using this layer, you'll be able to use GraphQL for your backend services without having to change those services. And it's a similar to what GraphQL Mesh does, except we're going to be owning the entire data flow. We're going to be owning all the logic in there. And in case you're not familiar, a data access layer, or data layer is a layer of a computer program that provides simplified access to the data of that surface.

So what we'll be doing, we'll be building a data layer that provides simplified access using GraphQL over our legacy code. So this will help us do a lot of different things like caching, like monitoring, but also it's going to prevent us from making mistakes while making changes to legacy code that runs, but somehow nobody knows how it runs, which often is the case with legacy code, of course. So this is the question you might ask yourself, why would I be creating a layer on top of a surface that already exists, that runs perfectly fine? Why should we do that? Because is my API already a data layer? Because probably your legacy code already provides an API with an interface that's going to give you all the data that you need. But we're going to be creating a data layer on top of a data layer. You might feel like inception right now because somehow we're creating something on top of something, or maybe it's already inside something. So something to think about for the rest of this talk.

QnA

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.