Skip to content

Instantly share code, notes, and snippets.

View itkrt2y's full-sized avatar
✂️
Yak Shaving

Tatsuya Itakura itkrt2y

✂️
Yak Shaving
View GitHub Profile
@itkrt2y
itkrt2y / association.rb
Last active March 11, 2024 22:55
Association dataloader with graphql-ruby
# official docs: https://graphql-ruby.org/dataloader/sources.html
# app/graphql/sources/association.rb
class Sources::Association < ::GraphQL::Dataloader::Source
def initialize(association_name, scope = nil)
@association_name = association_name
@scope = scope
end
def fetch(records)
@itkrt2y
itkrt2y / file-base-routing-with-preact-vite-wouter.tsx
Last active April 22, 2024 09:43
File based routing for vite, preact and wouter
import { Route, Switch } from "wouter-preact";
const pageFiles = import.meta.globEager("./pages/**/*.tsx");
const pages = Object.keys(pageFiles)
.sort()
.reverse() // Ensure the order of page file names. Put `:<filename>` to the end of the array.
.map((filePath) => {
const path = filePath.slice(8, -4).replace(/\/?index$/, "");
const { Page } = pageFiles[filePath];