lib/graphql/schema/build_from_definition.rb in graphql-2.0.20 vs lib/graphql/schema/build_from_definition.rb in graphql-2.0.21

- old
+ new

@@ -19,10 +19,11 @@ end end # @api private module Builder + include GraphQL::EmptyObjects extend self def build(schema_superclass, document, default_resolve:, using: {}, relay:) raise InvalidDocumentError.new('Must provide a document ast.') if !document || !document.is_a?(GraphQL::Language::Nodes::Document) @@ -97,18 +98,30 @@ if schema_definition.subscription raise InvalidDocumentError.new("Specified subscription type \"#{schema_definition.subscription}\" not found in document.") unless types[schema_definition.subscription] subscription_root_type = types[schema_definition.subscription] end + + if schema_definition.query.nil? && + schema_definition.mutation.nil? && + schema_definition.subscription.nil? + # This schema may have been given with directives only, + # check for defaults: + query_root_type = types['Query'] + mutation_root_type = types['Mutation'] + subscription_root_type = types['Subscription'] + end else query_root_type = types['Query'] mutation_root_type = types['Mutation'] subscription_root_type = types['Subscription'] end raise InvalidDocumentError.new('Must provide schema definition with query type or a type named Query.') unless query_root_type + builder = self + schema_class = Class.new(schema_superclass) do begin # Add these first so that there's some chance of resolving late-bound types orphan_types types.values query query_root_type @@ -132,10 +145,11 @@ directives directives.values if schema_definition ast_node(schema_definition) + builder.build_directives(self, schema_definition, type_resolver) end using.each do |plugin, options| if options use(plugin, **options) @@ -359,19 +373,17 @@ else default_value end end - NO_DEFAULT_VALUE = {}.freeze - def build_arguments(type_class, arguments, type_resolver) builder = self arguments.each do |argument_defn| default_value_kwargs = if !argument_defn.default_value.nil? { default_value: builder.build_default_value(argument_defn.default_value) } else - NO_DEFAULT_VALUE + EMPTY_HASH end type_class.argument( argument_defn.name, type: type_resolver.call(argument_defn.type),