@@ -330,10 +330,16 @@ def plugins
330330 find_inherited_value ( :plugins , EMPTY_ARRAY ) + own_plugins
331331 end
332332
333+ attr_writer :null_context
334+
335+ def null_context
336+ @null_context || GraphQL ::Query ::NullContext . instance
337+ end
338+
333339 # Build a map of `{ name => type }` and return it
334340 # @return [Hash<String => Class>] A dictionary of type classes by their GraphQL name
335341 # @see get_type Which is more efficient for finding _one type_ by name, because it doesn't merge hashes.
336- def types ( context = GraphQL :: Query :: NullContext . instance )
342+ def types ( context = null_context )
337343 if use_visibility_profile?
338344 types = Visibility ::Profile . from_context ( context , self )
339345 return types . all_types_h
@@ -366,7 +372,7 @@ def types(context = GraphQL::Query::NullContext.instance)
366372 # @param context [GraphQL::Query::Context] Used for filtering definitions at query-time
367373 # @param use_visibility_profile Private, for migration to {Schema::Visibility}
368374 # @return [Module, nil] A type, or nil if there's no type called `type_name`
369- def get_type ( type_name , context = GraphQL :: Query :: NullContext . instance , use_visibility_profile = use_visibility_profile? )
375+ def get_type ( type_name , context = null_context , use_visibility_profile = use_visibility_profile? )
370376 if use_visibility_profile
371377 profile = Visibility ::Profile . from_context ( context , self )
372378 return profile . type ( type_name )
@@ -617,7 +623,7 @@ def use_visibility_profile?
617623 # @param use_visibility_profile Private, for migration to {Schema::Visibility}
618624 # @return [Hash<String, Module>] All possible types, if no `type` is given.
619625 # @return [Array<Module>] Possible types for `type`, if it's given.
620- def possible_types ( type = nil , context = GraphQL :: Query :: NullContext . instance , use_visibility_profile = use_visibility_profile? )
626+ def possible_types ( type = nil , context = null_context , use_visibility_profile = use_visibility_profile? )
621627 if use_visibility_profile
622628 if type
623629 return Visibility ::Profile . from_context ( context , self ) . possible_types ( type )
@@ -701,7 +707,7 @@ def type_from_ast(ast_node, context: self.query_class.new(self, "{ __typename }"
701707 GraphQL ::Schema ::TypeExpression . build_type ( context . query . types , ast_node )
702708 end
703709
704- def get_field ( type_or_name , field_name , context = GraphQL :: Query :: NullContext . instance , use_visibility_profile = use_visibility_profile? )
710+ def get_field ( type_or_name , field_name , context = null_context , use_visibility_profile = use_visibility_profile? )
705711 if use_visibility_profile
706712 profile = Visibility ::Profile . from_context ( context , self )
707713 parent_type = case type_or_name
@@ -738,7 +744,7 @@ def get_field(type_or_name, field_name, context = GraphQL::Query::NullContext.in
738744 end
739745 end
740746
741- def get_fields ( type , context = GraphQL :: Query :: NullContext . instance )
747+ def get_fields ( type , context = null_context )
742748 type . fields ( context )
743749 end
744750
@@ -1228,6 +1234,7 @@ def inherited(child_class)
12281234 vis = self . visibility
12291235 child_class . visibility = vis . dup_for ( child_class )
12301236 end
1237+ child_class . null_context = Query ::NullContext . new ( schema : child_class )
12311238 super
12321239 end
12331240
0 commit comments