Class: Rails::GraphQL::GlobalID
- Inherits:
-
GlobalID
- Object
- GlobalID
- Rails::GraphQL::GlobalID
- Defined in:
- lib/rails/graphql/global_id.rb
Overview
GraphQL Global ID
GraphQL implementation of the Global ID that adds extended support to how things are located and stored. Mostly used for caching and custom access to the tree and request process.
TODO: Implement signed operations
Defined Under Namespace
Classes: Serializer
Constant Summary collapse
- SERIALIZER_KEY =
"_gql_globalid"
Class Method Summary collapse
-
.create(object, options = nil) ⇒ Object
Create a new GraphQL Global identifier.
-
.scope_of(object) ⇒ Object
Find the scope on which the object is applied to.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #base_class ⇒ Object
- #find(options = {}) ⇒ Object
-
#initialize(gid, options = {}) ⇒ GlobalID
constructor
A new instance of GlobalID.
Constructor Details
Class Method Details
.create(object, options = nil) ⇒ Object
Create a new GraphQL Global identifier
52 53 54 55 |
# File 'lib/rails/graphql/global_id.rb', line 52 def create(object, = nil) scope = &.delete(:scope) || scope_of(object) new(URI::GQL.create(object, scope, ), ) end |
.scope_of(object) ⇒ Object
Find the scope on which the object is applied to
58 59 60 |
# File 'lib/rails/graphql/global_id.rb', line 58 def scope_of(object) object.try(:schema_type) if object.gid_base_class.is_a?(Helpers::WithSchemaFields) end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
82 83 84 |
# File 'lib/rails/graphql/global_id.rb', line 82 def ==(other) other.is_a?(GlobalID) && @uri == other.uri end |
#base_class ⇒ Object
74 75 76 77 78 79 80 |
# File 'lib/rails/graphql/global_id.rb', line 74 def base_class if %w[Schema Directive Type].include?(class_name) GraphQL.const_get(class_name, false) else GraphQL.type_map.fetch(class_name, namespace: namespace) end end |
#find(options = {}) ⇒ Object
70 71 72 |
# File 'lib/rails/graphql/global_id.rb', line 70 def find( = {}) base_class.try(:find_by_gid, self) end |