@@ -9,9 +9,9 @@ module Language
9
9
# @param context [Hash]
10
10
# @param only [<#call(member, ctx)>]
11
11
# @param except [<#call(member, ctx)>]
12
- # @param include_introspection_types [Boolean] Wether or not to include introspection types in the AST
13
- # @param include_built_in_scalars [Boolean] Wether or not to include built in scalars in the AST
14
- # @param include_built_in_directives [Boolean] Wether or not to include built in diirectives in the AST
12
+ # @param include_introspection_types [Boolean] Whether or not to include introspection types in the AST
13
+ # @param include_built_in_scalars [Boolean] Whether or not to include built in scalars in the AST
14
+ # @param include_built_in_directives [Boolean] Whether or not to include built in diirectives in the AST
15
15
class DocumentFromSchemaDefinition
16
16
def initialize (
17
17
schema , context : nil , only : nil , except : nil , include_introspection_types : false ,
@@ -39,16 +39,12 @@ def document
39
39
def build_schema_node
40
40
schema_node = GraphQL ::Language ::Nodes ::SchemaDefinition . new
41
41
42
- if schema . query && warden . get_type ( schema . query . name )
43
- schema_node . query = schema . query . name
44
- end
45
-
46
- if schema . mutation && warden . get_type ( schema . mutation . name )
47
- schema_node . mutation = schema . mutation . name
48
- end
42
+ [ "query" , "mutation" , "subscription" ] . each do |operation_name |
43
+ root_type = schema . root_type_for_operation ( operation_name )
49
44
50
- if schema . subscription && warden . get_type ( schema . subscription . name )
51
- schema_node . subscription = schema . subscription . name
45
+ if root_type
46
+ schema_node . public_send ( "#{ operation_name } =" , warden . get_type ( root_type . name ) )
47
+ end
52
48
end
53
49
54
50
schema_node
@@ -271,7 +267,13 @@ def build_field_nodes(fields)
271
267
private
272
268
273
269
def include_schema_node?
274
- always_include_schema || !schema . respects_root_name_conventions?
270
+ always_include_schema || !schema_respects_root_name_conventions? ( schema )
271
+ end
272
+
273
+ def schema_respects_root_name_conventions? ( schema )
274
+ ( schema . query . nil? || schema . query . name == 'Query' ) &&
275
+ ( schema . mutation . nil? || schema . mutation . name == 'Mutation' ) &&
276
+ ( schema . subscription . nil? || schema . subscription . name == 'Subscription' )
275
277
end
276
278
277
279
attr_reader :schema , :warden , :always_include_schema ,
0 commit comments