This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# GraphQL-Ruby's connection system automatically adds first, last, after and before arguments. | |
# If you don't want all of those, you have to disable the system with `connection: false` | |
# in the field definition, then re-enable it manually. | |
# | |
# In this case, to create a field without the `last` argument, I created a custom subclass of `ConnectionExtension` | |
# which doesn't add any arguments. Then I add the specific arguments I want in the field definition. | |
# (I could also add those arguments in `def apply` using `field.argument ...`.) | |
require "bundler/inline" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "bundler/inline" | |
gemfile do | |
gem "graphql", "2.3.7" | |
gem "sqlite3", "~>1.4" | |
gem "activerecord", require: "active_record" | |
end | |
ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:") | |
ActiveRecord::Schema.define do |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "bundler/inline" | |
gemfile do | |
gem "graphql", "2.3.7" | |
gem "sqlite3", "~>1.4" | |
gem "activerecord", require: "active_record" | |
end | |
ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:") | |
ActiveRecord::Schema.define do |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "bundler/inline" | |
gemfile do | |
gem "racc" | |
# gem "graphql", "2.0.16" | |
gem "graphql", "2.2.3" | |
end | |
class MySchema < GraphQL::Schema | |
class Query < GraphQL::Schema::Object |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "bundler/inline" | |
gemfile do | |
gem "graphql", "2.3.4" | |
gem "graphql-pro", "1.27.5" | |
gem "cancancan", "3.5.0" | |
end | |
class Ability | |
include CanCan::Ability |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "bundler/inline" | |
gemfile do | |
gem "graphql", "~>2.2.0" | |
# or: gem "graphql", "~>1.13.0" | |
gem "graphql-batch", "0.6.0" | |
gem "graphql-pro", "~>1.27.0" | |
end | |
class Schema < GraphQL::Schema |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This module will add a method | |
# to clean up empty topics: | |
module RemoveEmptyTopicsStorageExtension | |
def remove_empty_topics | |
all_topics, _topics_count = topics(limit: nil, offset: nil) | |
topics_to_remove = all_topics.select { |t| t.subscriptions_count == 0 } | |
if topics_to_remove.any? | |
topic_names = topics_to_remove.map(&:name) | |
fingerprint_key = topic_names.map { |t| fingerprints_key(t) } | |
with_redis do |r| |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "bundler/inline" | |
gemfile do | |
gem "graphql", path: "./" # "2.3.0" | |
end | |
class MySchema < GraphQL::Schema | |
class SubThing < GraphQL::Schema::Object | |
field :name, String, broadcastable: true | |
field :viewer_can_edit, Boolean # not broadcastable |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# In this approach `nodes` are removed from a connection _after_ pagination has been applied. | |
# | |
# This approach has some downsides: | |
# - It may leak data about unauthorized nodes. hasNextPage and hasPrevPage will | |
# indicate that items were removed from the list; depending on sort and filter options, | |
# a client could learn about the attributes of the removed nodes. | |
# - pagination metadata may be wrong, since the list of nodes was modified after it was calculated. | |
# (some pagination info may be calculated _while_ the list of nodes is prepared.) | |
# | |
# The best alternative approach is to use `scope_items` instead, but I share this |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "bundler/inline" | |
gemfile do | |
gem "graphql", "1.12.17" | |
# gem "graphql", "1.12.18" | |
end | |
class MySchema < GraphQL::Schema | |
class Model < GraphQL::Schema::Object | |
field :name, String, null: false |
NewerOlder