All You Need Is a Contract…

Rate this content
Bookmark

How many times have you had to wait for your backend team to finish building the API so you can start your tasks? What if all you needed to move that task to in progress was the API contract? What if there was a library that did this for REST and GraphQL APIs and, at the same time, taking your tests to the next level? Join me and prepare to enhance your developer experience while learning all the battle-earned experiences of using one of my favorite libraries: Mock Service Worker.

Daniel Afonso
Daniel Afonso
29 min
20 Oct, 2023

Comments

Sign in or register to post your comment.

Video Summary and Transcription

The speaker discusses the challenges of server state and test maintenance, and how they found solutions using React Query and Mock Service Worker. They emphasize the benefits of defining contracts for faster development and stress reduction. The speaker also highlights the advantages of using Mock Service Worker over mock servers and explains how it allows for easy customization and test overrides. They mention the upcoming release of V2 of MS-Double and encourage the audience to stay updated.

1. Introduction and Annoyances as a Developer

Short description:

In this part, the speaker expresses gratitude towards the audience and acknowledges the hard work of the conference organizers. They also mention three things that annoy them as a developer: unmaintainable code, tests affected by unmaintainability, and late tasks in sprints. The speaker promises to share a story about how they and their team fixed these issues.

Okay, so let me just clear up the room. There's not going to be contract testing here. This is a joke we were talking before coming on stage. Also, I'm going to move a lot, so I'm trying to figure out the spot. That's cool, if I don't get blinded by the light.

Before anything else, React Advance, thank you so much for having me here. It's a pleasure. I'll walk around for that spot because apparently the camera won't get me on the other one, so I'll try not to move a lot.

I just wanted to start this talk with like, I would like to give a cheerful applause, because there was so many hard work setting up this conference for everyone from Git nation, everyone from the tech team. I don't know if you're aware, but when we started today, we were having some issues plugging everything, and now everything is working up already so far, so can I get an everyone that's working on this? Okay. Thank you so much.

So, let's start this because already one minute went away, and there are really three things that annoy me as a developer. The first one is when you have unmaintainable code. You know the feeling. Your code is not really that good sometimes. The more you add, the worse it gets. It's struggling. Yeah, it's hard. And then the second thing that really annoys me, it's when that unmaintainability finds a way of getting into your tests. Now it's not bad that your code is not good, your tests are not good as well. Probably you're not sleeping that well at night because you know what flaky tests feel like. And the third thing that really annoys me, and I'll promise to not start a rant here, is when you have a task that arrives late into the sprint. I know some of you relate to the feeling. Let's picture we have a team where two parts are working on a task and the first part takes 98% of the time, and once the task gets to you, you have 2% of the time. So obviously your product manager is going to expect you to deliver that thing yesterday. And this is a feeling that I could start talking about here and I wouldn't stop.

So let's continue, because I have a story about how me and my team fixed these issues a couple of years ago. So let's start at the beginning on how we had just cleared up the first issue. Me and my team had just defeated the unmaintainable code monster. Because this had been something that is been working around, it was threatening us, it was hard.

2. Server State Challenges and Test Issues

Short description:

The speaker discusses the challenges of server state and how they had to implement various functionalities themselves. They then discovered React query, which solved their server state issues. However, a new challenge arose with unmaintainable and flaky tests. The speaker eventually found a solution and introduces themselves as Daniel Alfonso, a developer advocate at OLX.

And what was the reason? Well, the reason was server state. Now, I don't know if you are aware of what server state is. It's typically the state that exists somewhere on the Internet as external to your application. And it has a bunch of challenges. Caching, deduping requests, data prefetching. There is a maintainer here from React query which you can talk about of many of these challenges and you can probably understand how much pain it is understanding and having to implement this thing by hand and I can tell you that me and my team, we didn't have React query back then or in the beginning, we didn't. So we were implementing all of these things by ourselves and the more code we were having, the worse got the unmaintainable code monster. So we started thinking, why are we implementing this ourselves again? What are we trying to prove to going in this direction? And well, a couple of months went by and this was when a couple of, well, these months went by, a co-worker, like the King Arthur in the Sword and the Stone movie. I think that's how you say it in English. Sorry, non-native English speaker here. One co-worker approached the stone and brought out a 10-stack query. So apparently, this new thing, React query, had just come up and it was the solution for our issues. And 10-stack query brought harmony to our code because now all the stuff and issues we had with server state were solved and we didn't have to worry about implementing that thing for a while that is.

Now, a new threat was lurking in the shadows. You see, that unmaintainability found a way outside of our code and going inside of our tests. Now, I don't know if you remember this image I showed you a couple of minutes ago, but this is Hydra. And you know what they say about Hydras. Cut one head, two more take its place. And this is kind of what was starting to happen with us because now our tests were not just unmaintainable. They were flaky. They were complex. I couldn't sleep at night because I had no trust on what the heck I was doing and now you're wondering, okay, what's the relation? What are we going to see? Well, safely now, a couple of years ago I can tell you that me and my team managed to fix these issues. And the fun part was that all we needed was a contract. So this is the part where I actually start the talk.

Let me just introduce myself real quickly. I'm Daniel Alfonso. I'm working as a developer advocate at OLX. I'm an AGIT instructor and an out-there ambassador and you can find me, I'm going to say Twitter because of the pool before on Twitter and pretty much any social network at the end So Daniel GC Alfonso. Also something about me, I recently published a book called State Management with React Query. Thanks.

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

Modern Web Debugging
JSNation 2023JSNation 2023
29 min
Modern Web Debugging
Top Content
Few developers enjoy debugging, and debugging can be complex for modern web apps because of the multiple frameworks, languages, and libraries used. But, developer tools have come a long way in making the process easier. In this talk, Jecelyn will dig into the modern state of debugging, improvements in DevTools, and how you can use them to reliably debug your apps.
The Future of Performance Tooling
JSNation 2022JSNation 2022
21 min
The Future of Performance Tooling
Top Content
Our understanding of performance & user-experience has heavily evolved over the years. Web Developer Tooling needs to similarly evolve to make sure it is user-centric, actionable and contextual where modern experiences are concerned. In this talk, Addy will walk you through Chrome and others have been thinking about this problem and what updates they've been making to performance tools to lower the friction for building great experiences on the web.
Remix Flat Routes – An Evolution in Routing
Remix Conf Europe 2022Remix Conf Europe 2022
16 min
Remix Flat Routes – An Evolution in Routing
Top Content
This talk introduces the new Flat Routes convention that will most likely be the default in a future version of Remix. It simplifies the existing convention as well as gives you new capabilities.
Get rid of your API schemas with tRPC
React Day Berlin 2022React Day Berlin 2022
29 min
Get rid of your API schemas with tRPC
Do you know we can replace API schemas with a lightweight and type-safe library? With tRPC you can easily replace GraphQL or REST with inferred shapes without schemas or code generation. In this talk we will understand the benefit of tRPC and how apply it in a NextJs application. If you want reduce your project complexity you can't miss this talk.
pnpm – a Fast, Disk Space Efficient Package Manager for JavaScript
DevOps.js Conf 2022DevOps.js Conf 2022
31 min
pnpm – a Fast, Disk Space Efficient Package Manager for JavaScript
You will learn about one of the most popular package managers for JavaScript and its advantages over npm and Yarn.A brief history of JavaScript package managersThe isolated node_modules structure created pnpmWhat makes pnpm so fastWhat makes pnpm disk space efficientMonorepo supportManaging Node.js versions with pnpm
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

React, TypeScript, and TDD
React Advanced Conference 2021React Advanced Conference 2021
174 min
React, TypeScript, and TDD
Top Content
Featured WorkshopFree
Paul Everitt
Paul Everitt
ReactJS is wildly popular and thus wildly supported. TypeScript is increasingly popular, and thus increasingly supported.

The two together? Not as much. Given that they both change quickly, it's hard to find accurate learning materials.

React+TypeScript, with JetBrains IDEs? That three-part combination is the topic of this series. We'll show a little about a lot. Meaning, the key steps to getting productive, in the IDE, for React projects using TypeScript. Along the way we'll show test-driven development and emphasize tips-and-tricks in the IDE.
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.
Hands-on with AG Grid's React Data Grid
React Summit 2022React Summit 2022
147 min
Hands-on with AG Grid's React Data Grid
WorkshopFree
Sean Landsman
Sean Landsman
Get started with AG Grid React Data Grid with a hands-on tutorial from the core team that will take you through the steps of creating your first grid, including how to configure the grid with simple properties and custom components. AG Grid community edition is completely free to use in commercial applications, so you'll learn a powerful tool that you can immediately add to your projects. You'll also discover how to load data into the grid and different ways to add custom rendering to the grid. By the end of the workshop, you will have created an AG Grid React Data Grid and customized with functional React components.- Getting started and installing AG Grid- Configuring sorting, filtering, pagination- Loading data into the grid- The grid API- Using hooks and functional components with AG Grid- Capabilities of the free community edition of AG Grid- Customizing the grid with React Components
Database Workflows & API Development with Prisma
Node Congress 2022Node Congress 2022
98 min
Database Workflows & API Development with Prisma
WorkshopFree
Nikolas Burk
Nikolas Burk
Prisma is an open-source ORM for Node.js and TypeScript. In this workshop, you’ll learn the fundamental Prisma workflows to model data, perform database migrations and query the database to read and write data. You’ll also learn how Prisma fits into your application stack, building a REST API and a GraphQL API from scratch using SQLite as the database.
Table of contents:
- Setting up Prisma, data modeling & migrations- Exploring Prisma Client to query the database- Building REST API routes with Express- Building a GraphQL API with Apollo Server
Best Practices and Patterns for Managing API Requests and States
React Advanced Conference 2022React Advanced Conference 2022
206 min
Best Practices and Patterns for Managing API Requests and States
Workshop
Thomas Findlay
Thomas Findlay
With the rise of frameworks, such as React, Vue or Angular, the way websites are built changed over the years. Modern applications can be very dynamic and perform multiple API requests to populate a website with fresh content or submit new data to a server. However, this paradigm shift introduced new problems developers need to deal with. When an API request is pending, succeeds, or fails, a user should be presented with meaningful feedback. Other problems can comprise API data caching or syncing the client state with the server. All of these problems require solutions that need to be coded, but these can quickly get out of hand and result in a codebase that is hard to extend and maintain. In this workshop, we will cover how to handle API requests, API states and request cancellation by implementing an API Layer and combining it with React-Query.
Prerequisites: To make the most out of this workshop, you should be familiar with React and Hooks, such as useState, useEffect, etc. If you would like to code along, make sure you have Git, a code editor, Node, and npm installed on your machine.