Skip to content

Instantly share code, notes, and snippets.

Avatar
🍄

Robert Mosolgo rmosolgo

🍄
View GitHub Profile
@rmosolgo
rmosolgo / example.js
Last active May 24, 2022
urql subscription exchange from GraphQL-Ruby pusher subscriptions
View example.js
import { Client, defaultExchanges, subscriptionExchange } from 'urql'
import Pusher from "pusher"
const pusherClient = new Pusher("your-app-key", { cluster: "us2" })
const forwardSubscriptionToPusher = (operation) => {
// urql will call `.subscribe` on the returned object:
// https://github.com/FormidableLabs/urql/blob/f89cfd06d9f14ae9cb3be10b21bd5cbd12ca275c/packages/core/src/exchanges/subscription.ts#L68-L73
// https://github.com/FormidableLabs/urql/blob/f89cfd06d9f14ae9cb3be10b21bd5cbd12ca275c/packages/core/src/exchanges/subscription.ts#L82-L97
return {
subscribe: ({next, error, complete}) => {
View inline_fragments.rb
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 Mar 5, 2022
ObjectCache with __typename
View caching_test.rb
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 Jan 28, 2022
Cached ActiveRecord Connection
View relation_cache.rb
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 Jan 4, 2022
Versioning a global ID field in GraphQL-Ruby
View global_id_changeset.rb
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 Dec 17, 2021
List scoping with GraphQL-Pro Pundit integration
View scoping.rb
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 Dec 17, 2021
GraphQL-Ruby in-memory query cache with OperationStore and a custom analyzer
View example.rb
require "bundler/inline"
require "logger"
gemfile do
gem "graphql", "1.13.2"
gem "graphql-pro", "1.20.2"
gem "redis"
end
# In-memory cache: populate the cache after queries are run.
@rmosolgo
rmosolgo / loads_auth.rb
Created Dec 1, 2021
Argument auth with loads
View loads_auth.rb
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 Dec 8, 2021
Preventing access to nested lists in GraphQL-ruby
View nested_list_test.rb
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 Nov 23, 2021
GraphQL Connections With ActiveRecord Connection Switching
View ar-connections-test.rb
require "bundler/inline"
gemfile do
gem "graphql", "1.12.20"
gem "graphql-pro", "1.20.2"
gem "rails"
gem "sqlite3"
end
require "active_record"