Method: GraphQL::Dataloader::Source.batch_key_for

Defined in:
lib/graphql/dataloader/source.rb

.batch_key_for(*batch_args, **batch_kwargs) ⇒ Object

These arguments are given to dataloader.with(source_class, ...). The object returned from this method is used to de-duplicate batch loads under the hood by using it as a Hash key.

By default, the arguments are all put in an Array. To customize how this source's batches are merged, override this method to return something else.

For example, if you pass ActiveRecord::Relations to .with(...), you could override this method to call .to_sql on them, thus merging .load(...) calls when they apply to equivalent relations.

Parameters:

  • batch_args (Array<Object>)
  • batch_kwargs (Hash)

Returns:

  • (Object)


173
174
175
# File 'lib/graphql/dataloader/source.rb', line 173

def self.batch_key_for(*batch_args, **batch_kwargs)
  [*batch_args, **batch_kwargs]
end