Module: GraphQL::Schema::Member::HasDataloader
- Included in:
- Query::Context, Interface::DefinitionMethods, Object, Resolver
- Defined in:
- lib/graphql/schema/member/has_dataloader.rb
Overview
Shared methods for working with Dataloader inside GraphQL runtime objects.
Instance Method Summary collapse
-
#dataload(source_class, *source_args, load_key) ⇒ Object
A shortcut method for loading a key from a source.
-
#dataload_all(source_class, *source_args, load_keys) ⇒ Object
A shortcut method for loading many keys from a source.
-
#dataload_association(record = object, association_name, scope: nil) ⇒ ActiveRecord::Base?
Look up an associated record using a Rails association (via Dataloader::ActiveRecordAssociationSource).
-
#dataload_record(model, find_by_value, find_by: nil) ⇒ ActiveRecord::Base?
Find an object with ActiveRecord via Dataloader::ActiveRecordSource.
-
#dataloader ⇒ GraphQL::Dataloader
The dataloader for the currently-running query.
Instance Method Details
#dataload(source_class, *source_args, load_key) ⇒ Object
A shortcut method for loading a key from a source.
Identical to dataloader.with(source_class, *source_args).load(load_key)
19 20 21 |
# File 'lib/graphql/schema/member/has_dataloader.rb', line 19 def dataload(source_class, *source_args, load_key) dataloader.with(source_class, *source_args).load(load_key) end |
#dataload_all(source_class, *source_args, load_keys) ⇒ Object
A shortcut method for loading many keys from a source.
Identical to dataloader.with(source_class, *source_args).load_all(load_keys)
28 29 30 |
# File 'lib/graphql/schema/member/has_dataloader.rb', line 28 def dataload_all(source_class, *source_args, load_keys) dataloader.with(source_class, *source_args).load_all(load_keys) end |
#dataload_association(record = object, association_name, scope: nil) ⇒ ActiveRecord::Base?
Look up an associated record using a Rails association (via Dataloader::ActiveRecordAssociationSource)
60 61 62 63 64 65 66 67 |
# File 'lib/graphql/schema/member/has_dataloader.rb', line 60 def dataload_association(record = object, association_name, scope: nil) source = if scope dataloader.with(Dataloader::ActiveRecordAssociationSource, association_name, scope) else dataloader.with(Dataloader::ActiveRecordAssociationSource, association_name) end source.load(record) end |
#dataload_record(model, find_by_value, find_by: nil) ⇒ ActiveRecord::Base?
Find an object with ActiveRecord via Dataloader::ActiveRecordSource.
41 42 43 44 45 46 47 48 49 |
# File 'lib/graphql/schema/member/has_dataloader.rb', line 41 def dataload_record(model, find_by_value, find_by: nil) source = if find_by dataloader.with(Dataloader::ActiveRecordSource, model, find_by: find_by) else dataloader.with(Dataloader::ActiveRecordSource, model) end source.load(find_by_value) end |
#dataloader ⇒ GraphQL::Dataloader
Returns The dataloader for the currently-running query.
10 11 12 |
# File 'lib/graphql/schema/member/has_dataloader.rb', line 10 def dataloader context.dataloader end |