@@ -18,6 +18,7 @@ def initialize(
1818 include_built_in_directives : false , include_built_in_scalars : false , always_include_schema : false
1919 )
2020 @schema = schema
21+ @context = context
2122 @always_include_schema = always_include_schema
2223 @include_introspection_types = include_introspection_types
2324 @include_built_in_scalars = include_built_in_scalars
@@ -268,7 +269,33 @@ def build_definition_nodes
268269 end
269270 definitions = build_directive_nodes ( dirs_to_build )
270271 all_types = @types . all_types
271- type_nodes = build_type_definition_nodes ( all_types + schema . extra_types )
272+ type_nodes = build_type_definition_nodes ( all_types )
273+
274+ if ( ex_t = schema . extra_types ) . any?
275+ dummy_query = Class . new ( GraphQL ::Schema ::Object ) do
276+ graphql_name "DummyQuery"
277+ ( all_types + ex_t ) . each_with_index do |type , idx |
278+ if !type . kind . input_object? && !type . introspection?
279+ field "f#{ idx } " , type
280+ end
281+ end
282+ end
283+
284+ extra_types_schema = Class . new ( GraphQL ::Schema ) do
285+ query ( dummy_query )
286+ end
287+
288+ extra_types_types = GraphQL ::Query . new ( extra_types_schema , "{ __typename }" , context : @context ) . types # rubocop:disable Development/ContextIsPassedCop
289+ # Temporarily replace `@types` with something from this example schema.
290+ # It'd be much nicer to pass this in, but that would be a big refactor :S
291+ prev_types = @types
292+ @types = extra_types_types
293+ type_nodes += build_type_definition_nodes ( ex_t )
294+ @types = prev_types
295+ end
296+
297+ type_nodes . sort_by! ( &:name )
298+
272299 if @include_one_of
273300 # This may have been set to true when iterating over all types
274301 definitions . concat ( build_directive_nodes ( [ GraphQL ::Schema ::Directive ::OneOf ] ) )
@@ -291,9 +318,7 @@ def build_type_definition_nodes(types)
291318 types = types . reject { |type | type . kind . scalar? && type . default_scalar? }
292319 end
293320
294- types
295- . map { |type | build_type_definition_node ( type ) }
296- . sort_by ( &:name )
321+ types . map { |type | build_type_definition_node ( type ) }
297322 end
298323
299324 def build_field_nodes ( fields )
0 commit comments