class GraphQL::Schema::Printer
puts printer.print_type(Types::Post)
printer = GraphQL::Schema::Printer.new(MySchema)
end
query(Types::Query)
class MySchema < GraphQL::Schema
end
field :body, String, null: false
field :title, String, null: false
field :id, ID, null: false
description “A blog post”
class Types::Post < GraphQL::Schema::Object
end
field :post, Types::Post, null: true
description “The query root of this schema”
class Types::Query < GraphQL::Schema::Object
@example print a single type to standard output
puts GraphQL::Schema::Printer.new(MySchema).print_schema
@example print your schema to standard output
puts GraphQL::Schema::Printer.print_schema(MySchema)
@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
def self.print_introspection_schema query_root = Class.new(GraphQL::Schema::Object) do graphql_name "Root" field :throwaway_field, String def self.visible?(ctx) false end end schema = Class.new(GraphQL::Schema) { query(query_root) def self.visible?(member, _ctx) member.graphql_name != "Root" end } introspection_schema_ast = GraphQL::Language::DocumentFromSchemaDefinition.new( schema, 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)
-
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 self.visible?(ctx)
def self.visible?(ctx) false end
def self.visible?(member, _ctx)
def self.visible?(member, _ctx) member.graphql_name != "Root" end
def initialize(schema, context: nil, introspection: false)
-
introspection
(Boolean
) -- Should include the introspection types in the string? -
context
(Hash
) -- -
schema
(GraphQL::Schema
) --
def initialize(schema, context: nil, introspection: false) @document_from_schema = GraphQL::Language::DocumentFromSchemaDefinition.new( schema, context: context, include_introspection_types: introspection, ) @document = @document_from_schema.document @schema = schema end
def print_schema
def print_schema print(@document) + "\n" end
def print_type(type)
def print_type(type) node = @document_from_schema.build_type_definition_node(type) print(node) end