Skip to content

Commit 1dd0adf

Browse files
author
Marc-Andre Giroux
committed
start refactoring Schema::Printer
1 parent 975f50c commit 1dd0adf

File tree

2 files changed

+11
-18
lines changed

2 files changed

+11
-18
lines changed

lib/graphql/language/document_from_schema_definition.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ def document
3838
)
3939
end
4040

41-
protected
42-
4341
def build_schema_node
4442
schema_node = GraphQL::Language::Nodes::SchemaDefinition.new
4543

lib/graphql/schema/printer.rb

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,16 @@ class Printer
4545
# @param except [<#call(member, ctx)>]
4646
# @param introspection [Boolean] Should include the introspection types in the string?
4747
def initialize(schema, context: nil, only: nil, except: nil, introspection: false)
48-
@schema = schema
49-
@context = context
48+
@document_generator = GraphQL::Language::DocumentFromSchemaDefinition.new(
49+
schema,
50+
context: context,
51+
only: only,
52+
except: except,
53+
include_introspection_types: introspection,
54+
include_built_ins: false,
55+
)
5056

51-
blacklist = build_blacklist(only, except, introspection: introspection)
52-
filter = GraphQL::Filter.new(except: blacklist)
53-
@warden = GraphQL::Schema::Warden.new(filter, schema: @schema, context: @context)
57+
@schema = schema
5458
end
5559

5660
# Return the GraphQL schema string for the introspection type system
@@ -74,17 +78,8 @@ def self.print_schema(schema, **args)
7478

7579
# Return a GraphQL schema string for the defined types in the schema
7680
def print_schema
77-
directive_definitions = warden.directives.map { |directive| print_directive(directive) }
78-
79-
printable_types = warden.types.reject(&:default_scalar?)
80-
81-
type_definitions = printable_types
82-
.sort_by(&:name)
83-
.map { |type| print_type(type) }
84-
85-
[print_schema_definition].compact
86-
.concat(directive_definitions)
87-
.concat(type_definitions).join("\n\n")
81+
document = @document_generator.document
82+
document.to_query_string
8883
end
8984

9085
def print_type(type)

0 commit comments

Comments
 (0)