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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/graphiti_gql/schema/util.rb', line 4
def self.params_from_args(arguments)
lookahead = arguments.delete(:lookahead)
params = arguments.as_json.deep_transform_keys { |key| key.to_s.underscore.to_sym }
if params[:sort]
params[:sort] = Util.transform_sort_param(params[:sort])
end
if (first = params.delete(:first))
params[:page] ||= {}
params[:page][:size] = first
end
if (last = params.delete(:last))
params[:page] ||= {}
params[:page][:size] = last
params[:reverse] = true
end
if (after = params.delete(:after))
params[:page] ||= {}
params[:page][:after] = after
end
if (before = params.delete(:before))
params[:page] ||= {}
params[:page][:before] = before
end
if (id = params.delete(:id))
params[:filter] ||= {}
params[:filter][:id] = { eq: id }
end
if lookahead.selects?(:stats)
stats = lookahead.selection(:stats)
payload = {}
stats.selections.map(&:name).each do |name|
payload[name] = stats.selection(name).selections.map(&:name)
end
params[:stats] = payload
if lookahead.selections.map(&:name) == [:stats]
params[:page] = { size: 0 }
end
end
params
end
|