lib/graphql/schema/loader.rb in graphql-0.18.6 vs lib/graphql/schema/loader.rb in graphql-0.18.7

- old
+ new

@@ -20,13 +20,17 @@ next if type.fetch("name").start_with?("__") type_object = define_type(type, type_resolver) types[type_object.name] = type_object end - query = types.fetch(schema.fetch("queryType").fetch("name")) + kargs = { :orphan_types => types.values } + [:query, :mutation, :subscription].each do |root| + type = schema["#{root}Type"] + kargs[root] = types.fetch(type.fetch("name")) if type + end - Schema.new(query: query, types: types.values) + Schema.define(**kargs) end class << self private @@ -59,11 +63,11 @@ }) when "INTERFACE" InterfaceType.define( name: type["name"], description: type["description"], - fields: Hash[type["fields"].map { |field| + fields: Hash[(type["fields"] || []).map { |field| [field["name"], define_type(field.merge("kind" => "FIELD"), type_resolver)] }] ) when "INPUT_OBJECT" InputObjectType.define( @@ -75,9 +79,12 @@ ) when "OBJECT" ObjectType.define( name: type["name"], description: type["description"], + interfaces: (type["interfaces"] || []).map { |interface| + type_resolver.call(interface) + }, fields: Hash[type["fields"].map { |field| [field["name"], define_type(field.merge("kind" => "FIELD"), type_resolver)] }] ) when "FIELD"