Class: GraphQL::Schema::Printer
- Inherits:
- 
      Language::Printer
      
        - Object
- Language::Printer
- GraphQL::Schema::Printer
 
- Defined in:
- lib/graphql/schema/printer.rb
Overview
Used to convert your GraphQL::Schema to a GraphQL schema string
Defined Under Namespace
Classes: IntrospectionPrinter
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 
    
    
  
  
  
  
  
  
  
  
  
    
Methods inherited from Language::Printer
Constructor Details
#initialize(schema, context: nil, only: nil, except: nil, introspection: false) ⇒ Printer
Returns a new instance of Printer.
| 42 43 44 45 46 47 48 49 50 51 52 53 | # File 'lib/graphql/schema/printer.rb', line 42 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)
Returns the value of attribute schema.
| 35 36 37 | # File 'lib/graphql/schema/printer.rb', line 35 def schema @schema end | 
#warden ⇒ Object (readonly)
Returns the value of attribute warden.
| 35 36 37 | # File 'lib/graphql/schema/printer.rb', line 35 def warden @warden end | 
Class Method Details
.print_introspection_schema ⇒ Object
Return the GraphQL schema string for the introspection type system
| 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | # File 'lib/graphql/schema/printer.rb', line 56 def self.print_introspection_schema query_root = Class.new(GraphQL::Schema::Object) do graphql_name "Root" field :throwaway_field, String end schema = Class.new(GraphQL::Schema) { query(query_root) } introspection_schema_ast = GraphQL::Language::DocumentFromSchemaDefinition.new( schema, except: ->(member, _) { member.graphql_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
Return a GraphQL schema string for the defined types in the schema
| 78 79 80 81 | # File 'lib/graphql/schema/printer.rb', line 78 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
| 84 85 86 | # File 'lib/graphql/schema/printer.rb', line 84 def print_schema print(@document) + "\n" end | 
#print_type(type) ⇒ Object
| 88 89 90 91 | # File 'lib/graphql/schema/printer.rb', line 88 def print_type(type) node = @document_from_schema.build_type_definition_node(type) print(node) end |