Module: HQ::GraphQL::Resource::ClassMethods
- Includes:
- AutoMutation
- Defined in:
- lib/hq/graphql/resource.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
#build_copy, #build_create, #build_destroy, #build_mutation, #build_update
Instance Attribute Details
#graphql_name ⇒ Object
42
43
44
|
# File 'lib/hq/graphql/resource.rb', line 42
def graphql_name
@graphql_name || model_name.demodulize
end
|
#model_name ⇒ Object
46
47
48
|
# File 'lib/hq/graphql/resource.rb', line 46
def model_name
@model_name || ::HQ::GraphQL.(self)
end
|
Instance Method Details
#find_record(attrs, context) ⇒ Object
32
33
34
35
36
|
# File 'lib/hq/graphql/resource.rb', line 32
def find_record(attrs, context)
primary_key = model_klass.primary_key.to_sym
primary_key_value = attrs[primary_key]
scope(context).find_by(primary_key => primary_key_value)
end
|
58
59
60
|
# File 'lib/hq/graphql/resource.rb', line 58
def input_klass
@input_klass ||= build_input_object
end
|
#model_klass ⇒ Object
50
51
52
|
# File 'lib/hq/graphql/resource.rb', line 50
def model_klass
@model_klass ||= model_name&.safe_constantize
end
|
#mutation_klasses ⇒ Object
54
55
56
|
# File 'lib/hq/graphql/resource.rb', line 54
def mutation_klasses
@mutation_klasses ||= {}.with_indifferent_access
end
|
#new_record(context) ⇒ Object
38
39
40
|
# File 'lib/hq/graphql/resource.rb', line 38
def new_record(context)
scope(context).new
end
|
#nil_query_klass ⇒ Object
62
63
64
|
# File 'lib/hq/graphql/resource.rb', line 62
def nil_query_klass
@nil_query_klass ||= build_graphql_object(name: "#{graphql_name}Copy", auto_nil: false)
end
|
#query_klass ⇒ Object
66
67
68
|
# File 'lib/hq/graphql/resource.rb', line 66
def query_klass
@query_klass ||= build_graphql_object
end
|
#scope(context) ⇒ Object
26
27
28
29
30
|
# File 'lib/hq/graphql/resource.rb', line 26
def scope(context)
scope = model_klass
scope = ::HQ::GraphQL.default_scope(scope, context)
@default_scope&.call(scope, context) || scope
end
|
#sort_fields_enum ⇒ Object
70
71
72
|
# File 'lib/hq/graphql/resource.rb', line 70
def sort_fields_enum
@sort_fields_enum || ::HQ::GraphQL::Enum::SortBy
end
|