lib/graph_ql/directive.rb in graphql-0.2.0 vs lib/graph_ql/directive.rb in graphql-0.3.0
- old
+ new
@@ -1,16 +1,18 @@
-class GraphQL::Directive < GraphQL::ObjectType
+class GraphQL::Directive
+ extend GraphQL::Definable
+ attr_definable :on, :arguments, :name, :description
+
LOCATIONS = [
ON_OPERATION = :on_operation?,
ON_FRAGMENT = :on_fragment?,
ON_FIELD = :on_field?,
]
LOCATIONS.each do |location|
define_method(location) { self.on.include?(location) }
end
- attr_definable :on, :arguments
def initialize
@arguments = {}
@on = []
yield(self, GraphQL::TypeDefiner.instance, GraphQL::FieldDefiner.instance, GraphQL::ArgumentDefiner.instance)
@@ -25,14 +27,16 @@
end
end
def arguments(new_arguments=nil)
if !new_arguments.nil?
- @arguments = new_arguments
- .reduce({}) {|memo, (k, v)| memo[k.to_s] = v; memo}
- .each { |k, v| v.respond_to?("name=") && v.name = k}
+ @arguments = GraphQL::StringNamedHash.new(new_arguments).to_h
end
@arguments
+ end
+
+ def to_s
+ "<GraphQL::Directive #{name}>"
end
end
require 'graph_ql/directives/directive_chain'
require 'graph_ql/directives/include_directive'