Skip to content

Instantly share code, notes, and snippets.

View bessey's full-sized avatar

Matt Bessey bessey

View GitHub Profile
from typing import Any, Callable, Self
from htpy import (
Element,
Node,
Iterator,
Attribute,
_id_class_names_from_css_str,
_kwarg_attribute_name,
div,
button,
@bessey
bessey / traced_json_log_formatter.rb
Created July 28, 2021 16:31
Ruby log formatter with JSON output and Datadog APM trace correlation injection
# frozen_string_literal: true
require 'json'
module Utils
# Ruby Log Formatter that serves two purposes:
# 1. Formats logs to JSON, so that they can be indexed by our log processor (currently Datadog)
# 2. Enriches logs with Datadog APM trace information, so logs can be associated back to APM traces
class TracedJSONLogFormatter
def initialize
@bessey
bessey / graphql-ruby-fiber-loading.rb
Last active December 22, 2020 18:24
Proposal for alternative Fiber based design for GraphQL Ruby batched data loading
# The general idea is that similarly to lazy evaluation, the interpreter executes each resolver from inside a Fiber.
# Once we have instantiated a Fiber for every resolver reachable in this pass, we loop over the Fibers, yielding till
# they are dead (the resolver has returned). Resolvers that are not using the Fiber based Loader API would simply
# return there value on the first pass.
# Complete pseudo-cpde, I don't know GraphQL Ruby internals well
def main_graphql_ruby_interpreter_loop(reachable_fields)
unresolved_fields = reachable_fields.reduce({}) do |acc, field|
# Creating one Fiber per field is probably too expensive, and we'd want to re-use them across loops or even across
# different fields in the same loop. A topic for another time.
DEPENDENCIES
active_model_serializers (= 0.9.4)
active_record_union
activeadmin (~> 1.2.1)
acts_as_list
amatch
annotate
autoprefixer-rails
awesome_nested_set (~> 3.1.0)
aws-sdk-v1
### IMPLEMENTATION ###
# Flattens an arbitrarily nested enumerable of enumerables.
# Works for Arrays of Integers, and more.
class EnumerableFlattener
attr_reader :array
def initialize(array)
@array = array
end
@bessey
bessey / gist:9ea70d8a9127c28adf680524c4ec28ef
Created July 26, 2018 17:43
Duplicate type definition found for name 'Account' at 'Field LocalChain.account's return type' (Types::AccountType, Types::AccountType)
RuntimeError: Duplicate type definition found for name 'Account' at 'Field LocalChain.account's return type' (Types::AccountType, Types::AccountType)
from graphql/schema/traversal.rb:168:in `visit'
from graphql/schema/traversal.rb:205:in `visit_field_on_type'
from graphql/schema/traversal.rb:185:in `block in visit_fields'
from graphql/schema/traversal.rb:184:in `each'
from graphql/schema/traversal.rb:184:in `visit_fields'
from graphql/schema/traversal.rb:143:in `visit'
from graphql/schema/traversal.rb:205:in `visit_field_on_type'
from graphql/schema/traversal.rb:185:in `block in visit_fields'
from graphql/schema/traversal.rb:184:in `each'
@bessey
bessey / graphq_testing_type_tester.rb
Last active March 21, 2022 16:02
Beginnings of a reusable GraphQL Ruby type testing toolkit.
# Assumptions
# 1. Your schema implements the Relay Query.node(id:) field, Schema.id_from_object, and Schema.object_from_id
# 2. The types you wish to test implement the Node interface
# 3. (In order to be compatible with Node) the object you test resolves to a single type
# 4. The object you wish to test has a unique identifier
# TODO
# Maybe we can remove 3. by making use of an override in context?
# Since Schema.resolve_type takes a context object, perhaps if you must test an object that is
# presented via multiple types in the schema, you can force the decision via context. I have not
@bessey
bessey / ruby-install-graphqlparser-no-sudo-travis.bash
Created June 12, 2018 12:35
Install libgraphqlparser + ruby gem graphql-libgraphqlparser on Travis without sudo
# Install libgraphql parser
if [ ! -d $HOME/gql/usr/local/lib ]
then
wget https://github.com/graphql/libgraphqlparser/archive/v0.7.0.tar.gz
tar -xzvf v0.7.0.tar.gz
cd libgraphqlparser-0.7.0/ && cmake . && make && make DESTDIR=$HOME/gql install && cd $TRAVIS_BUILD_DIR
else
echo "libgraphqlparser install detected"
fi
@bessey
bessey / Error message
Created December 23, 2016 05:15
Mocked graphql schema, and the error it generates
Expected a value of type "Time" but received: 2016-12-23T05:04:10.611Z
@bessey
bessey / snippets.js
Created December 8, 2016 20:43
my "JavaScript React" snippets for VS Code
{
/*
// Place your snippets for JavaScript React here. Each snippet is defined under a snippet name and has a prefix, body and
// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, ${id} and ${id:label} and ${1:label} for variables. Variables with the same id are connected.
// Example:
"Print to console": {
"prefix": "log",
"body": [
"console.log('$1');",