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
|
# File 'lib/graphoid/definitions/inputs.rb', line 8
def generate(model)
LIST[model] ||= GraphQL::InputObjectType.define do
name = Utils.graphqlize(model.name)
name("#{name}Input")
description("Generated model input for #{name}")
Attribute.fields_of(model).each do |field|
next if field.name.start_with?('_')
type = Graphoid::Mapper.convert(field)
name = Utils.camelize(field.name)
argument(name, type)
end
Relation.relations_of(model).each do |name, relation|
relation_class = relation.class_name.safe_constantize
next unless relation_class
relation_input = LIST[relation_class]
next unless relation_input
name = Utils.camelize(relation.name)
r = Relation.new(relation)
if r.many?
argument(name, -> { types[relation_input] })
else
argument(name, -> { relation_input })
end
end
end
end
|