blob: 9e53b525fe3a4aedf5f462a9a431815a1fe8cf07 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# frozen_string_literal: true
module BulkImports
module Common
module Extractors
class GraphqlExtractor
def initialize(options = {})
@query = options[:query]
end
def extract(context)
client = graphql_client(context)
response = client.execute(
client.parse(query.to_s),
query.variables(context.entity)
).original_hash.deep_dup
BulkImports::Pipeline::ExtractedData.new(
data: response.dig(*query.data_path),
page_info: response.dig(*query.page_info_path)
)
end
private
attr_reader :query
def graphql_client(context)
@graphql_client ||= BulkImports::Clients::Graphql.new(
url: context.configuration.url,
token: context.configuration.access_token
)
end
end
end
end
end
|