module Graphoid::Utils
Public Class Methods
build_update_attributes(data, model, context)
click to toggle source
# File lib/graphoid/utils.rb, line 40 def build_update_attributes(data, model, context) user = context[:current_user] fields = Graphoid::Attribute.fieldnames_of(model) attrs = underscore(data, fields) attrs['updated_by_id'] = user.id if user && fields.include?('updated_by_id') attrs end
camelize(text)
click to toggle source
# File lib/graphoid/utils.rb, line 10 def camelize(text) # we are doing it twice because _id gets translated to Id the first time and to id the second time. graphqlize text.to_s.camelize(:lower).camelize(:lower) end
children_of(selection)
click to toggle source
# File lib/graphoid/utils.rb, line 23 def children_of(selection) selection.scoped_children.values.first end
first_children_of(selection)
click to toggle source
# File lib/graphoid/utils.rb, line 27 def first_children_of(selection) selection.scoped_children.values.first.values.first.scoped_children.values.first end
graphqlize(text)
click to toggle source
# File lib/graphoid/utils.rb, line 15 def graphqlize(text) text.to_s.gsub(/::/, '_') end
modelize(text)
click to toggle source
# File lib/graphoid/utils.rb, line 6 def modelize(text) graphqlize text.to_s.capitalize.camelize end
symbolize(fields)
click to toggle source
# File lib/graphoid/utils.rb, line 19 def symbolize(fields) fields.keys.map { |f| f.underscore.to_sym } end
underscore(props, fields = [])
click to toggle source
# File lib/graphoid/utils.rb, line 31 def underscore(props, fields = []) attrs = {} props.each do |key, value| key = key.underscore if fields.exclude?(key) attrs[key] = value end attrs end