lib/graphql/schema/loader.rb in graphql-1.11.1 vs lib/graphql/schema/loader.rb in graphql-1.11.2
- old
+ new
@@ -23,12 +23,19 @@
next if type.fetch("name").start_with?("__")
type_object = define_type(type, type_resolver)
types[type["name"]] = type_object
end
+ directives = []
+ schema.fetch("directives", []).each do |directive|
+ next if GraphQL::Schema.default_directives.include?(directive.fetch("name"))
+ directives << define_directive(directive, type_resolver)
+ end
+
Class.new(GraphQL::Schema) do
orphan_types(types.values)
+ directives(directives)
def self.resolve_type(*)
raise(GraphQL::RequiredImplementationMissingError, "This schema was loaded from string, so it can't resolve types for objects")
end
@@ -96,11 +103,11 @@
description(type["description"])
type["enumValues"].each do |enum_value|
value(
enum_value["name"],
description: enum_value["description"],
- deprecation_reason: enum_value["deprecation_reason"],
+ deprecation_reason: enum_value["deprecationReason"],
)
end
end
when "INTERFACE"
Module.new do
@@ -145,18 +152,29 @@
else
fail GraphQL::RequiredImplementationMissingError, "#{type["kind"]} not implemented"
end
end
+ def define_directive(directive, type_resolver)
+ loader = self
+ Class.new(GraphQL::Schema::Directive) do
+ graphql_name(directive["name"])
+ description(directive["description"])
+ locations(*directive["locations"].map(&:to_sym))
+ loader.build_arguments(self, directive["args"], type_resolver)
+ end
+ end
+
public
def build_fields(type_defn, fields, type_resolver)
loader = self
fields.each do |field_hash|
type_defn.field(
field_hash["name"],
type: type_resolver.call(field_hash["type"]),
description: field_hash["description"],
+ deprecation_reason: field_hash["deprecationReason"],
null: true,
camelize: false,
) do
if field_hash["args"].any?
loader.build_arguments(self, field_hash["args"], type_resolver)