class GraphQL::Schema::Printer


puts printer.print_type(post_type)
printer = GraphQL::Schema::Printer.new(MySchema)
MySchema = GraphQL::Schema.define(query: query_root)
end
field :body, !types.String
field :title, !types.String
field :id, !types.ID
description “A blog post”
name “Post”
post_type = GraphQL::ObjectType.define do
end
end
resolve ->(obj, args, ctx) { Post.find(args) }
type post_type
field :post do
description “The query root of this schema”
name “Query”
query_root = GraphQL::ObjectType.define do
@example print a single type to standard output
puts GraphQL::Schema::Printer.new(MySchema).print_schema
MySchema = GraphQL::Schema.define(query: QueryType)
@example print your schema to standard output
puts GraphQL::Schema::Printer.print_schema(MySchema)
MySchema = GraphQL::Schema.define(query: QueryType)
@example print your schema to standard output (via helper)
Used to convert your {GraphQL::Schema} to a GraphQL schema string

def self.print_introspection_schema

Return the GraphQL schema string for the introspection type system
def self.print_introspection_schema
  query_root = ObjectType.define(name: "Root") do
    field :throwaway_field, types.String
  end
  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

def self.print_schema(schema, **args)

Parameters:
  • except (<#call(member, ctx)>) --
  • only (<#call(member, ctx)>) --
  • context (Hash) --
  • schema (GraphQL::Schema) --
def self.print_schema(schema, **args)
  printer = new(schema, **args)
  printer.print_schema
end

def initialize(schema, context: nil, only: nil, except: nil, introspection: false)

Parameters:
  • introspection (Boolean) -- Should include the introspection types in the string?
  • except (<#call(member, ctx)>) --
  • only (<#call(member, ctx)>) --
  • context (Hash) --
  • schema (GraphQL::Schema) --
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

def print_schema

Return a GraphQL schema string for the defined types in the schema
def print_schema
  print(@document)
end

def print_type(type)

def print_type(type)
  node = @document_from_schema.build_type_definition_node(type)
  print(node)
end