Typescript – What is a Partial?

A common theme in TypeScript is to define an interface for a data structure. Additionally, it’s fairly common to post data structures to an HTTP endpoint to create resources. You may even find yourself posting another structure with some of the same properties to update that data structure. Instead of creating another interface for the update, in this example, is where the use of Typescript’s Partial comes in to play. Imagine that we have the following interface. interface User { id: int; email: string; password: string; hairColor: string; } It’s safe to assume that there may be a time where...

Fetching Data with React Hooks

React hooks have changed the way that I (and arguably the React Community) prefer to build components. I’ve been working on a GraphQL project for a while, and when we migrated to functional components and hooks, I was able to use Apollo’s hooks for my data fetching needs. However, I find myself now working on a new project that doesn’t use GraphQL. Consequentially, I find myself wondering “How do I fetch data with React Hooks?” If you’d just like to see a codepen example of the code, you can find it here. In Apollo, I’m able to use the useQuery...

Autosaving with React Hooks

React hooks have really changed the game for me when it comes to building react components. However, I’ve found that writing autosaving functionality is a little less obvious via hooks. Thankfully, it is still possible (and arguably a lot cleaner) when using hooks. We can accomplish autosaving functionality through use of useEffect. You’ll also need a way to post the data to your server. In my case, I’m using Apollo’s useMutation hook as well. This allows me to post a graphql mutation from a hook-like interface. The useEffect hook The useEffect hook effectively replaces componentDidMount, componentWillUpdate, and componentWillUnmount. Here’s how...

Introducing the Design Doc Podcast

Hey there! I’ll keep this brief, as all of the good content for this post is audio. Yesterday, I worked with a close friend of mine to release our first episode of the Design Doc podcast. That’s the podcast where I dig into questions about personal projects from experienced Software Engineers and we talk through some of the choices they’ve made, issues they’ve run into, and more. You can find Design Doc anywhere podcasts are found (if you can’t, please let me know and ill work to get it listed on your favorite platform), but I also have an Anchor.fm...

Auth Guarding React Router Routes

A common theme in web applications is to serve specific content to authenticated users while serving other content to everyone else. I’ve heard this referred to in the past as “auth guarding” specific content. In this case of our example today, we want to auth guard react-router routes. There are a couple of different ways to do this, but I’ve found a pattern that I really like that uses higher-order function components to help create the functionality that would be expected of an auth guarded route. Namely, we show them an unauthorized screen if they’re not authorized and, if they...

Using Mongo’s ObjectIDs with Go-Graphql

I’ve been working on building a Graphql API in Go and recently ran into an issue serializing Mongo’s ObjectIDs. This doesn’t sound like a difficult task, and thankfully it’s not, but it wasn’t super obvious how to go about this. First, we need to identify what an object ID really is. In the official Mongo driver, we can see that there is a type representation for ObjectID. Additionally, there are methods to convert an ObjectID to a hex value and vice-versa. This means that we could maintain two structs for our models, one with the hex value for an ID...

Pagination in Scala with Slick

Pagination is the idea that a list of content can be broken into separate pages. When I first heard of pagination, the common practice was to use query params to influence which rows of content was loaded by the server. If you clicked the “next” button on the page, it would reload the page with new query params. Fundamentally, pagination hasn’t changed much, but the landscape in which it exists has changed drastically. While some monolithic apps are still built today, the pattern for modern web development involves APIs and SPAs. In the example we’ll cover today, we’ll talk about...