Sha256: aa78d7404cbf1b9bb89f45ed34ee8fe5d8b320420c39bd03a4bd9b16641646d5

Contents?: true

Size: 665 Bytes

Versions: 15

Compression:

Stored size: 665 Bytes

Contents

module GraphitiGraphQL
  module Federation
    module Loaders
      class BelongsTo < GraphQL::Batch::Loader
        def initialize(resource_class, fields)
          @resource_class = resource_class
          @fields = fields
        end

        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
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
graphiti_graphql-0.1.17 lib/graphiti_graphql/federation/loaders/belongs_to.rb
graphiti_graphql-0.1.16 lib/graphiti_graphql/federation/loaders/belongs_to.rb
graphiti_graphql-0.1.15 lib/graphiti_graphql/federation/loaders/belongs_to.rb
graphiti_graphql-0.1.14 lib/graphiti_graphql/federation/loaders/belongs_to.rb
graphiti_graphql-0.1.12 lib/graphiti_graphql/federation/loaders/belongs_to.rb
graphiti_graphql-0.1.11 lib/graphiti_graphql/federation/loaders/belongs_to.rb
graphiti_graphql-0.1.10 lib/graphiti_graphql/federation/loaders/belongs_to.rb
graphiti_graphql-0.1.9 lib/graphiti_graphql/federation/loaders/belongs_to.rb
graphiti_graphql-0.1.8 lib/graphiti_graphql/federation/loaders/belongs_to.rb
graphiti_graphql-0.1.7 lib/graphiti_graphql/federation/loaders/belongs_to.rb
graphiti_graphql-0.1.6 lib/graphiti_graphql/federation/loaders/belongs_to.rb
graphiti_graphql-0.1.5 lib/graphiti_graphql/federation/loaders/belongs_to.rb
graphiti_graphql-0.1.4 lib/graphiti_graphql/federation/loaders/belongs_to.rb
graphiti_graphql-0.1.3 lib/graphiti_graphql/federation/loaders/belongs_to.rb
graphiti_graphql-0.1.2 lib/graphiti_graphql/federation/loaders/belongs_to.rb