Skip to content

Instantly share code, notes, and snippets.

@such
Created July 25, 2022 15:26
Show Gist options
  • Save such/1ae00ba56d160c39120539e11500e18c to your computer and use it in GitHub Desktop.
Save such/1ae00ba56d160c39120539e11500e18c to your computer and use it in GitHub Desktop.
Bad handling of invalid cursor
# frozen_string_literal: true
require 'bundler/inline'
require 'logger'
gemfile do
gem 'graphql', '2.0.12'
gem 'graphql-pro', '1.22.2'
gem 'activerecord', '7.0.2.4'
gem 'sqlite3'
end
require 'active_record'
# This connection will do for database-independent bug reports.
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
ActiveRecord::Schema.define do
create_table :cards, force: true
end
class Card < ActiveRecord::Base
end
# Here's a minimal schema to demonstrate the behavior when valid/invalid:
class Schema < GraphQL::Schema
connections.add(ActiveRecord::Relation, GraphQL::Pro::PostgresStableRelationConnection)
default_max_page_size 50
class Card < GraphQL::Schema::Object
implements GraphQL::Types::Relay::Node
global_id_field :id
end
class Query < GraphQL::Schema::Object
field :cards, Card.connection_type, null: true
def cards
::Card.all
end
end
query(Query)
end
pp Schema.execute(
'
{
cards(after: "test") {
pageInfo {
endCursor
}
edges {
node {
id
}
}
}
}
'
).to_h
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment