Class: GraphitiGraphQL::Federation::Loaders::BelongsTo
- Inherits:
-
GraphQL::Batch::Loader
- Object
- GraphQL::Batch::Loader
- GraphitiGraphQL::Federation::Loaders::BelongsTo
- Defined in:
- lib/graphiti_graphql/federation/loaders/belongs_to.rb
Instance Method Summary collapse
-
#initialize(resource_class, fields) ⇒ BelongsTo
constructor
A new instance of BelongsTo.
- #perform(ids) ⇒ Object
Constructor Details
#initialize(resource_class, fields) ⇒ BelongsTo
Returns a new instance of BelongsTo.
5 6 7 8 |
# File 'lib/graphiti_graphql/federation/loaders/belongs_to.rb', line 5 def initialize(resource_class, fields) @resource_class = resource_class @fields = fields end |
Instance Method Details
#perform(ids) ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'lib/graphiti_graphql/federation/loaders/belongs_to.rb', line 10 def perform(ids) Util.with_gql_context do params = {filter: {id: {eq: ids.join(",")}}} params[:fields] = {@resource_class.type => @fields.join(",")} records = @resource_class.all(params).as_json[:data] map = records.index_by { |record| record[:id].to_s } ids.each { |id| fulfill(id, map[id]) } end end |