class GraphQL::Schema::Printer

Used to convert your {GraphQL::Schema} to a GraphQL schema string

@example print your schema to standard output (via helper)

puts GraphQL::Schema::Printer.print_schema(MySchema)

@example print your schema to standard output

puts GraphQL::Schema::Printer.new(MySchema).print_schema

@example print a single type to standard output

class Types::Query < GraphQL::Schema::Object
  description "The query root of this schema"

  field :post, Types::Post, null: true
end

class Types::Post < GraphQL::Schema::Object
  description "A blog post"

  field :id, ID, null: false
  field :title, String, null: false
  field :body, String, null: false
end

class MySchema < GraphQL::Schema
  query(Types::Query)
end

printer = GraphQL::Schema::Printer.new(MySchema)
puts printer.print_type(Types::Post)

Attributes

schema[R]
warden[R]

Public Class Methods

new(schema, context: nil, only: nil, except: nil, introspection: false) click to toggle source

@param schema [GraphQL::Schema] @param context [Hash] @param only [<#call(member, ctx)>] @param except [<#call(member, ctx)>] @param introspection [Boolean] Should include the introspection types in the string?

# 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
print_introspection_schema() click to toggle source

Return the GraphQL schema string for the introspection type system

print_schema(schema, **args) click to toggle source

Return a GraphQL schema string for the defined types in the schema @param schema [GraphQL::Schema] @param context [Hash] @param only [<#call(member, ctx)>] @param except [<#call(member, ctx)>]

Public Instance Methods

print_schema() click to toggle source

Return a GraphQL schema string for the defined types in the schema

print_type(type) click to toggle source