Connecting a relationship using a hook in Keystone.js 6

I’m writing this for the weary internet traveler because I spent 3 hours debugging this and finally had some coffee ☕️ and figured it out after running into a ton of errors.

This is my desired outcome: every time a user signs up for my app, I want to associate the “Reader” role with that user. I had the option of doing this from the frontend but I would’ve had to run two mutations which isn’t ideal and I’m sure I was going to encounter a race condition in some cases.

The role list in my app can either be an “Admin”, “Reader”, or “Robot”. Pretty self-explanatory but I wanted to make sure all new users signing up are of the Reader role so they can’t mess with other users etc. Keystone does not come with a lot of built in control for this and I’m following Wes Bos’ example of Roles for Users.

Here’s the code:

// this is the Role schema
Role: list({
    fields: {
      name: text({ validation: { isRequired: true } }),
      assignedTo: relationship({
        ref: "User.role", // this is how the user is related to this list
        many: true,
      }),
    },
  }),
// this is the User schema, truncated to only show the Role relation

role: relationship({
        ref: "Role.assignedTo",
        hooks: {
          resolveInput: async ({ resolvedData, operation, context }) => {
            if (operation === "create") {
              const reader = await context.query.Role.findMany({
                where: { name: { equals: "Reader" } },
              });
              resolvedData.role = { connect: { id: reader[0].id } };
            }
            return resolvedData["role"];
          },
        },
      }),

The part I was struggling with was a vague Prisma error like the following, the UI only said “Prisma error”

Unknown arg `role` in data.role for type UserUncheckedCreateInput. Did you mean `roleId`? Available args:
type UserUncheckedCreateInput {
  id?: String
  name?: String
  username?: String
  email?: String
  password: String
  roleId?: String | Null
  readings?: ReadingUncheckedCreateNestedManyWithoutUserInput
}

I guess this error is not very helpful to someone running into this for the first time so my best understanding of it is that it’s due to the resolvedData being returned incorrect. I was returning resolvedData but instead needed to return resolvedData["role"] where role is the field name.

Some terminology

TermDescription
listKeystone’s way of indicating tables, more documentation: https://keystonejs.com/docs/apis/config#lists
field, or field nameA property on a list, aka a column in a table.

Packing up, and having a font for it

I’ve had a few interests this year, finding a good water enhancer (e.g. flavor mixes without sugar) being one of the recent ones but my interest this year has stayed pretty steady in typography. Mainly printing out labels has led me down rabbit holes of font families. I’m making labels for moving and I’ve found a typeface I like. It’s San Francisco Pro Rounded or SF Pro Rounded for short. You can get it from Apple’s website on macOS. I started making labels using it, you can see an example below:

The Dymo Turbo 45 is a pretty nice label maker, it’s thermal so I don’t have to worry about ink usage. I’m not sure if label makers out there use ink for just basic printing because it seems like thermal printing would be way more economical in large scale uses. But I do love using the label maker to print out labels for everything around the house. I think this has been a worthwhile interest for the year.

An introduction to music by Nusrat Fateh Ali Khan

This post was written in 2018 and has been sitting in my Drafts for over 3 years. I decided to write this after realizing it’s going to get deleted if I don’t get to it.

When I discover new music, I love to go the extra few steps of finding out more about the musician, songs I like, albums by the musician, and even related artists. I also love sharing music with people. In this post, I’ll talk about Nusrat Fateh Ali Khan, the greatest qawwal ever recorded.

But before we get into Nusrat Fateh Ali Khan, I’d like to introduce you to the art of “qawwali”. It’s the form of music that’s devotional and emotionally powerful, it has elements of religious worship, love, praise for Sufism, and many other explorations of the human condition. An important part of a qawwali is the repetitive but slightly altered parts of the lyrics. Qawwali originates from South Asia and Central Asia (India to Turkey) and each region has practiced qawwali in slightly different forms. When listening to qawwali, it’s important to remember that the musician or qawwal might be singing their own song or they might be reciting a poem, song, or ghazal from another qawwal. A qawwali will also include a group of musicians known as the party, thus it’s usually called a qawwali party. The main qawwal is considered the leader of the qawwali party, in this post that person is Nusrat Fateh Ali Khan. A qawwali is often longer than a typical song, anywhere between 10-15 minutes for a short one and there are some that have gone up to an hour. You can read more about qawwalis on Wikipedia.

Since qawwalis are a type of a song, I will interchangeably use the words “song” and “qawwali” to mean the same thing. Once you listen to some qawwalis in this post and elsewhere, you’ll notice that there are some that will let you get lost within them and whether you’re listening to it while relaxing, driving, working, or emotionally trying to connect to the meaning of the qawwali, it’ll be easy to get lost within one.


I don’t remember the first song I heard by Nusrat Fateh Ali Khan (NFAK), it must’ve been before I could even walk or talk. I do remember there would always be some sort of music being played around the house that included NFAK’s music. As time went on, I noticed some songs and remembered their names and would occasionally look them up. When Youtube came around, I would look up just his name and listen to some music. When Spotify finally came to the US, that was one of the first time where I started collecting his songs I liked.

Over his career, Nusrat Fateh Ali Khan recorded 125+ albums and released 30+ concert recordings. This is amazing but at the same time, it makes it a bit tough to find the greatest amongst the great. I’ll list some of my favorites below.

By the time I was able to remember songs I liked, a subculture of remixing NFAK’s music became popularized after his death and due to this phenomenon, I discovered one of my favorite songs, Jhoole Jhoole Lal:

When you listen to this song, you can hear a lot of post-editing and mixing to make the song sound modern, I didn’t have any options when I first heard this song to know that there were other versions of it and I became a fan. Eventually I discovered the original version:

The original features NFAK’s voice as the most important part of the song, it doesn’t have any additional sounds added on. This is an example of a song that’s poetic in a sense that a simple listen once in awhile will not let you hear the words and their meaning as easily. It’s a song about praising the savior who is unnamed in the song but there are many interpretations of who the savior is being referenced.

Next checkout one of the shorter songs on this list:

In this song, it’s a lamenting cry for a long lost lover. A story about a lover who might’ve died or gone away, but the world knows not the pain felt by the narrative’s subject. In this qawwali, the perspective from which the song is sang is unclear and that makes it so much better because it’s letting the listener determine who it’s for or from. The song is also a prayer in a form to say that nobody else should lose their love as the narrator has.

Below are some songs that I think you’ll just enjoy, not much description needed:

And if you’d really like to go deep on more of NFAK’s music, here’s a Spotify playlist you can listen to:

Nusrat Fateh Ali Khan (Discography)

Wood by Rostam

I love this song by Rostam, it has a warm sound to it and it reminds me of being between two cultures perfectly.

I made a profile photo inspired by the album cover below:

“Carnival Jump” by Sandy Bull

I’ve been listening to Sandy Bull since I first discovered his music through a now defunct music service called Songza. It’s a tragedy that Google shut down Songza because their expertly curated playlists were top notch. The playlist I found Sandy Bull and similar artists was part of a genre called American Primitivism or “America primitive guitar” which was majorly influenced by John Fahey. Both, Sandy Bull and John Fahey, worked with Vanguard Records which sort of led me to hear a lot more music like this.

I’ve listened to this one song over 200 times since I first heard it and I wanted to share it here for everyone else to hear it:

A better shortcut for emojis on macOS

I just saw the new MX Keys Mini, it’s a $100 non-mechanical keyboard but one of its primary marketing touts is that it comes with an emoji key:

The emoji key as F7 on the MX Mini

I love to use custom keyboard shortcuts for basically everything and of my least favorite shortcuts is the ⌘ + ⇧ + Space to bring up the Emojis & Symbols floating menu.

So if you’d like to change your emojis menu shortcut follow the steps below:

  1. Open up the Keyboard settings (in System Preferences)
  2. Go to “Shortcuts”
  3. For “App Shortcuts” add a new one (using the + button)
  4. Set it for “All Applications” and then type in “Emoji & Symbols” and for the shortcut, set whatever you’d like it to be. 😊

TIL: checkout the previous branch using git checkout –

If you want to check out a branch you had checked out right before switching to the current branch (usually during merges from main this will happen).

git checkout feature-branch
... do some work
git checkout main
... merge stuff
git checkout -
# ↑ this will take you back to feature-branch

Clearing and resetting dock on macOS

You can clear the dock’s persistent items (default apps that show up on dock) by running the following:

defaults write com.apple.dock persistent-apps -array; killall Dock

You can reset the dock using:

rm ~/Library/Preferences/com.apple.dock.plist; killall Dock

Note: it might not be necessary to kill the dock but I needed to run that on Monterey.

And then there were none, by Agatha Christie

I just finished reading this murder mystery for Halloween. Took me a little over a month to finish it so it was perfect timing. It didn’t have too much of a spooky vibe but the murder mystery aspect is great. I was completely confused until the epilogue.

My favorite photo subjects

I’m attempting to pick up my camera more often and take photos of things around me. And I realized, my two favorite subjects to shoot are my pets. I’ve always liked taking photos of them as having a gray cat is the perfect gray card to have around. Having a black dog is not the same, his photos become a bit more tough against bright backgrounds.

Here are photos from today:

Heisenberg outside in the yard
Samson relaxing in the hallway

Bonus

I’m working on a theme for my blog that will replace this theme because I am looking at making my blog more photo friendly.