Class: GraphQL::Schema::Printer
- Inherits:
-
Object
- Object
- GraphQL::Schema::Printer
- Defined in:
- lib/graphql/schema/printer.rb
Overview
Used to convert your GraphQL::Schema to a GraphQL schema string
Instance Attribute Summary collapse
-
#schema ⇒ Object
readonly
Returns the value of attribute schema.
-
#warden ⇒ Object
readonly
Returns the value of attribute warden.
Class Method Summary collapse
-
.print_introspection_schema ⇒ Object
Return the GraphQL schema string for the introspection type system.
-
.print_schema(schema, **args) ⇒ Object
Return a GraphQL schema string for the defined types in the schema.
Instance Method Summary collapse
-
#initialize(schema, context: nil, only: nil, except: nil, introspection: false) ⇒ Printer
constructor
A new instance of Printer.
-
#print_schema ⇒ Object
Return a GraphQL schema string for the defined types in the schema.
- #print_type(type) ⇒ Object
Constructor Details
#initialize(schema, context: nil, only: nil, except: nil, introspection: false) ⇒ Printer
Returns a new instance of Printer.
47 48 49 50 51 52 53 54 |
# File 'lib/graphql/schema/printer.rb', line 47 def initialize(schema, context: nil, only: nil, except: nil, introspection: false) @schema = schema @context = context blacklist = build_blacklist(only, except, introspection: introspection) filter = GraphQL::Filter.new(except: blacklist) @warden = GraphQL::Schema::Warden.new(filter, schema: @schema, context: @context) end |
Instance Attribute Details
#schema ⇒ Object (readonly)
Returns the value of attribute schema.
40 41 42 |
# File 'lib/graphql/schema/printer.rb', line 40 def schema @schema end |
#warden ⇒ Object (readonly)
Returns the value of attribute warden.
40 41 42 |
# File 'lib/graphql/schema/printer.rb', line 40 def warden @warden end |
Class Method Details
.print_introspection_schema ⇒ Object
Return the GraphQL schema string for the introspection type system
57 58 59 60 61 62 63 |
# File 'lib/graphql/schema/printer.rb', line 57 def self.print_introspection_schema query_root = ObjectType.define(name: "Root") schema = GraphQL::Schema.define(query: query_root) blacklist = ->(m, ctx) { m == query_root } printer = new(schema, except: blacklist, introspection: true) printer.print_schema end |
.print_schema(schema, **args) ⇒ Object
Return a GraphQL schema string for the defined types in the schema
70 71 72 73 |
# File 'lib/graphql/schema/printer.rb', line 70 def self.print_schema(schema, **args) printer = new(schema, **args) printer.print_schema end |
Instance Method Details
#print_schema ⇒ Object
Return a GraphQL schema string for the defined types in the schema
76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/graphql/schema/printer.rb', line 76 def print_schema directive_definitions = warden.directives.map { |directive| print_directive(directive) } printable_types = warden.types.reject(&:default_scalar?) type_definitions = printable_types .sort_by(&:name) .map { |type| print_type(type) } [print_schema_definition].compact .concat(directive_definitions) .concat(type_definitions).join("\n\n") end |
#print_type(type) ⇒ Object
90 91 92 |
# File 'lib/graphql/schema/printer.rb', line 90 def print_type(type) TypeKindPrinters::STRATEGIES.fetch(type.kind).print(warden, type) end |