Skip to content

Instantly share code, notes, and snippets.

@rmosolgo
rmosolgo / inline_fragments.rb
Last active May 30, 2022 18:27
Inline Fragments
require "bundler/inline"
gemfile do
gem "graphql", "~>2.0"
end
# This visitor will inline any fragment definitions in the document.
# It assumes that the document is valid; it will :boom: if there are
# cycles in the fragment spreads.
@rmosolgo
rmosolgo / caching_test.rb
Created March 5, 2022 14:32
ObjectCache with __typename
require "bundler/inline"
gemfile do
gem "graphql", "1.13.10"
gem "graphql-pro", "1.21.4"
gem "graphql-enterprise", "1.1.3"
end
class CachingSchema < GraphQL::Schema
@rmosolgo
rmosolgo / relation_cache.rb
Last active January 28, 2022 18:24
Cached ActiveRecord Connection
require "bundler/inline"
gemfile do
gem "graphql"
gem "graphql-pro"
gem "sqlite3"
gem "rails"
end
require "rails/all"
require "logger"
@rmosolgo
rmosolgo / global_id_changeset.rb
Created January 4, 2022 14:54
Versioning a global ID field in GraphQL-Ruby
require "bundler/inline"
gemfile do
gem "graphql", "1.13.2"
gem "graphql-enterprise", "1.1.0"
end
class BaseField < GraphQL::Schema::Field
include GraphQL::Enterprise::Changeset::FieldIntegration
end
@rmosolgo
rmosolgo / scoping.rb
Created December 17, 2021 14:31
List scoping with GraphQL-Pro Pundit integration
require "bundler/inline"
gemfile do
gem "graphql", "1.13.1"
gem "graphql-pro"
end
class Schema < GraphQL::Schema
class BaseObject < GraphQL::Schema::Object
include GraphQL::Pro::PunditIntegration::ObjectIntegration
@rmosolgo
rmosolgo / example.rb
Last active February 21, 2024 20:32
GraphQL-Ruby in-memory query cache with OperationStore and a custom analyzer
require "bundler/inline"
require "logger"
gemfile do
gem "graphql", "2.2.10"
gem "graphql-pro", "1.26.3"
gem "redis"
end
# In-memory cache: populate the cache after queries are run.
@rmosolgo
rmosolgo / loads_auth.rb
Created December 1, 2021 15:17
Argument auth with loads
require "bundler/inline"
gemfile do
gem "graphql", "1.13.0"
gem "graphql-pro", "1.20.3"
gem "pundit"
end
require "ostruct"
@rmosolgo
rmosolgo / nested_list_test.rb
Last active December 8, 2021 16:13
Preventing access to nested lists in GraphQL-ruby
require "bundler/inline"
gemfile do
gem "graphql", "1.12.20"
end
class PreventNestedCards < GraphQL::Analysis::AST::Analyzer
def initialize(query)
super
@inside_players_selection = false
@rmosolgo
rmosolgo / ar-connections-test.rb
Last active November 23, 2021 14:20
GraphQL Connections With ActiveRecord Connection Switching
require "bundler/inline"
gemfile do
gem "graphql", "1.12.20"
gem "graphql-pro", "1.20.2"
gem "rails"
gem "sqlite3"
end
require "active_record"
require "bundler/inline"
require "logger"
gemfile do
gem "graphql", "1.12.19"
gem "graphql-pro", "1.20.1"
gem "redis"
end
# Here's an example of caching parsed AST documents for persisted queries.