Class: GraphQL::Schema::Printer Private
- Inherits:
-
Language::Printer
- Object
- Language::Printer
- GraphQL::Schema::Printer
- Defined in:
- lib/graphql/schema/printer.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Used to convert your GraphQL::Schema to a GraphQL schema string
Defined Under Namespace
Classes: IntrospectionPrinter
Instance Attribute Summary collapse
-
#schema ⇒ Object
readonly
private
-
#warden ⇒ Object
readonly
private
Class Method Summary collapse
-
.print_introspection_schema ⇒ Object
private
Return the GraphQL schema string for the introspection type system.
-
.print_schema(schema, **args) ⇒ Object
private
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
private
A new instance of Printer.
-
#print_directive(directive) ⇒ Object
private
-
#print_schema ⇒ Object
private
Return a GraphQL schema string for the defined types in the schema.
-
#print_type(type) ⇒ Object
private
Methods inherited from Language::Printer
Constructor Details
#initialize(schema, context: nil, only: nil, except: nil, introspection: false) ⇒ Printer
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Printer
47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/graphql/schema/printer.rb', line 47 def initialize(schema, context: nil, only: nil, except: nil, introspection: false) @document_from_schema = GraphQL::Language::DocumentFromSchemaDefinition.new( schema, context: context, only: only, except: except, include_introspection_types: introspection, ) @document = @document_from_schema.document @schema = schema end |
Instance Attribute Details
#schema ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
40 41 42 |
# File 'lib/graphql/schema/printer.rb', line 40 def schema @schema end |
#warden ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
40 41 42 |
# File 'lib/graphql/schema/printer.rb', line 40 def warden @warden end |
Class Method Details
.print_introspection_schema ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return the GraphQL schema string for the introspection type system
62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/graphql/schema/printer.rb', line 62 def self.print_introspection_schema query_root = ObjectType.define(name: "Root") schema = GraphQL::Schema.define(query: query_root) introspection_schema_ast = GraphQL::Language::DocumentFromSchemaDefinition.new( schema, except: ->(member, _) { member.name == "Root" }, include_introspection_types: true, include_built_in_directives: true, ).document introspection_schema_ast.to_query_string(printer: IntrospectionPrinter.new) end |
.print_schema(schema, **args) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return a GraphQL schema string for the defined types in the schema
81 82 83 84 |
# File 'lib/graphql/schema/printer.rb', line 81 def self.print_schema(schema, **args) printer = new(schema, **args) printer.print_schema end |
Instance Method Details
#print_directive(directive) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/graphql/schema/printer.rb', line 96 def print_directive(directive) if directive.name == "deprecated" reason = directive.arguments.find { |arg| arg.name == "reason" } if reason.value == GraphQL::Directive::DEFAULT_DEPRECATION_REASON "@deprecated" else "@deprecated(reason: #{reason.value.to_s.inspect})" end else super end end |
#print_schema ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return a GraphQL schema string for the defined types in the schema
87 88 89 |
# File 'lib/graphql/schema/printer.rb', line 87 def print_schema print(@document) end |
#print_type(type) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
91 92 93 94 |
# File 'lib/graphql/schema/printer.rb', line 91 def print_type(type) node = @document_from_schema.build_object_type_node(type) print(node) end |