module GraphQL::Schema::Printer

def is_defined_type(type)

def is_defined_type(type)
  !is_introspection_type(type) && !BUILTIN_SCALARS.include?(type.name)
end

def is_introspection_type(type)

def is_introspection_type(type)
  type.name.start_with?("__")
end

def print_filtered_schema(schema, type_filter)

def print_filtered_schema(schema, type_filter)
  types = schema.types.values.select{ |type| type_filter.call(type) }.sort_by(&:name)
  type_definitions = types.map{ |type| print_type(type) }
  [print_schema_definition(schema)].concat(type_definitions).join("\n\n")
end

def print_introspection_schema

Return the GraphQL schema string for the introspection type system
def print_introspection_schema
  query_root = ObjectType.define do
    name "Query"
  end
  schema = GraphQL::Schema.define(query: query_root)
  print_filtered_schema(schema, method(:is_introspection_type))
end

def print_schema(schema)

Parameters:
  • schema (GraphQL::Schema) --
def print_schema(schema)
  print_filtered_schema(schema, method(:is_defined_type))
end

def print_schema_definition(schema)

def print_schema_definition(schema)
  operations = [:query, :mutation, :subscription].map do |operation_type|
    object_type = schema.public_send(operation_type)
    "  #{operation_type}: #{object_type.name}\n" if object_type
  end.compact.join
  "schema {\n#{operations}}"
end

def print_type(type)

def print_type(type)
  TypeKindPrinters::STRATEGIES.fetch(type.kind).print(type)
end