Class: BulkImports::Common::Extractors::GraphqlExtractor

Inherits:
Object
  • Object
show all
Defined in:
lib/bulk_imports/common/extractors/graphql_extractor.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ GraphqlExtractor

Returns a new instance of GraphqlExtractor.



7
8
9
# File 'lib/bulk_imports/common/extractors/graphql_extractor.rb', line 7

def initialize(options = {})
  @query_klass = options[:query]
end

Instance Method Details

#extract(context) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/bulk_imports/common/extractors/graphql_extractor.rb', line 11

def extract(context)
  client = graphql_client(context)
  query = query_klass.new(context: context)

  response = client.execute(
    client.parse(query.to_s),
    query.variables
  ).original_hash.deep_dup

  BulkImports::Pipeline::ExtractedData.new(
    data: response.dig(*query.data_path),
    page_info: response.dig(*query.page_info_path)
  )
end