lib/graph_ql/query.rb in graphql-0.2.0 vs lib/graph_ql/query.rb in graphql-0.3.0
- old
+ new
@@ -7,11 +7,11 @@
def initialize(schema, query_string, context: nil, params: {}, debug: true, validate: true)
@schema = schema
@debug = debug
@query_string = query_string
- @context = context
+ @context = Context.new(context)
@params = params
@validate = validate
@fragments = {}
@operations = {}
@@ -46,21 +46,32 @@
private
def execute
@operations.reduce({}) do |memo, (name, operation)|
resolver = OperationResolver.new(operation, self)
- memo[name] = resolver.result
- memo
+ memo.merge(resolver.result)
end
end
def validation_errors
@validation_errors ||= begin
if @validate
@schema.static_validator.validate(@document)
else
[]
end
+ end
+ end
+
+ # Expose some query-specific info to field resolve functions.
+ # It delegates `[]` to the hash that's passed to `GraphQL::Query#initialize`.
+ class Context
+ def initialize(arbitrary_hash)
+ @arbitrary_hash = arbitrary_hash
+ end
+
+ def [](key)
+ @arbitrary_hash[key]
end
end
end
require 'graph_ql/query/arguments'