Group methods related to text generation for GraphQL documentation into a module

This commit is contained in:
Alberto Miedes Garcés
2017-01-26 10:47:12 +01:00
parent e7f55b10e2
commit 83267330a7
10 changed files with 51 additions and 6 deletions

View File

@@ -0,0 +1,32 @@
module Graphqlable
extend ActiveSupport::Concern
class_methods do
def graphql_field_name
self.name.gsub('::', '_').underscore.to_sym
end
def graphql_pluralized_field_name
self.name.gsub('::', '_').underscore.pluralize.to_sym
end
def graphql_field_description
"Find one #{self.model_name.human} by ID"
end
def graphql_pluralized_field_description
"Find all #{self.model_name.human.pluralize}"
end
def graphql_type_name
self.name.gsub('::', '_')
end
def graphql_type_description
"#{self.model_name.human}"
end
end
end