Skip to content

Instantly share code, notes, and snippets.

View JoSuzuki's full-sized avatar
🏂
Chilling

Jonathan Suzuki JoSuzuki

🏂
Chilling
View GitHub Profile
@JoSuzuki
JoSuzuki / cache-with-mergeable-types.ts
Created March 31, 2021 14:11
Cache with mergeable types
const cache = new InMemoryCache({
possibleTypes: {
MergeableTypes: mergeableTypesArray,
},
typePolicies: {
MergeableTypes: {
merge: true,
},
},
});
@JoSuzuki
JoSuzuki / generate-apollo-mergeable-types.js
Created March 31, 2021 14:12
A custom plugin for graphql-codegen to generate mergeable types
const { isInterfaceType, isObjectType } = require('graphql');
module.exports = {
plugin: (schema, _documents, _config) => {
const typesMap = schema.getTypeMap();
let fileString =
'/* This is an auto-generated file by generate-apollo-mergeable-types.js */\n\n';
fileString += 'export const mergeableTypesArray = [\n';
@JoSuzuki
JoSuzuki / codegen.yml
Created March 31, 2021 14:13
codegen.yml to use apollo-mergeable-types.js
overwrite: true
schema: '../../../app/graphql/schema.graphql'
generates:
./src/schema-types/fragments/introspection-result.ts:
plugins:
- fragment-matcher
config:
apolloClientVersion: 3
./src/schema-types/fragments/apollo-mergeable-types.ts:
plugins:
@JoSuzuki
JoSuzuki / navbar-example-1.tsx
Created September 16, 2021 16:56
[Dont add, subtract] Navbar example 1
const MyApp = () => {
return (
<div>
<Navbar
items={[
{
label: 'Home',
href: '/home',
},
{
@JoSuzuki
JoSuzuki / navbar-example-2-interface.tsx
Created September 16, 2021 16:56
[Dont add, subtract] Navbar interface
interface NavbarProps {
items: {
component: React.ReactElement;
link: { href: string, label: string };
}[];
}
@JoSuzuki
JoSuzuki / navbar-example-3-adding.tsx
Created September 16, 2021 16:57
[Dont add, subtract] Navbar solution adding
const MyApp = () => {
return (
<div>
<Navbar
items={[
{
label: 'Home',
href: '/home',
},
@JoSuzuki
JoSuzuki / navbar-example-4-subtracting.tsx
Created September 16, 2021 16:58
[Dont add, subtract] Navbar example subtracting
const MyApp = () => {
return (
<div>
<Navbar>
<Link href="/home">Home</Link>
<Link href="/products">Products</Link>
<Button onClick={openSupport}>Support</Button>
<Link href="/about">About</Link>
</Navbar>
<Main />
@JoSuzuki
JoSuzuki / active_record_freeze_save_error.md
Created July 4, 2023 22:12
You won't believe this bug! Active record association save freeze error

Chapter 0: Setup

Recently I came across a bug that took me a day to understand what was happening. Below is a sample reproduction of the relevant files I was working with:

app/models/user.rb

class User < ApplicationRecord
  # columns id, email, name
  has_many :comments, dependent: :destroy
end