1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
|
# frozen_string_literal: true
module GraphQL
module Introspection
class TypeType < Introspection::BaseObject
graphql_name "__Type"
description "The fundamental unit of any GraphQL Schema is the type. There are many kinds of types in "\
"GraphQL as represented by the `__TypeKind` enum.\n\n"\
"Depending on the kind of a type, certain fields describe information about that type. "\
"Scalar types provide no information beyond a name and description, while "\
"Enum types provide their values. Object and Interface types provide the fields "\
"they describe. Abstract types, Union and Interface, provide the Object types "\
"possible at runtime. List and NonNull types compose other types."
field :kind, GraphQL::Schema::LateBoundType.new("__TypeKind"), null: false
field :name, String, method: :graphql_name
field :description, String
field :fields, [GraphQL::Schema::LateBoundType.new("__Field")], scope: false do
argument :include_deprecated, Boolean, required: false, default_value: false
end
field :interfaces, [GraphQL::Schema::LateBoundType.new("__Type")], scope: false
field :possible_types, [GraphQL::Schema::LateBoundType.new("__Type")], scope: false
field :enum_values, [GraphQL::Schema::LateBoundType.new("__EnumValue")], scope: false do
argument :include_deprecated, Boolean, required: false, default_value: false
end
field :input_fields, [GraphQL::Schema::LateBoundType.new("__InputValue")], scope: false do
argument :include_deprecated, Boolean, required: false, default_value: false
end
field :of_type, GraphQL::Schema::LateBoundType.new("__Type")
field :specifiedByURL, String, resolver_method: :specified_by_url
field :is_one_of, Boolean, null: false
def is_one_of
object.kind.input_object? &&
object.directives.any? { |d| d.graphql_name == "oneOf" }
end
def specified_by_url
if object.kind.scalar?
object.specified_by_url
else
nil
end
end
def kind
@object.kind.name
end
def enum_values(include_deprecated:)
if !@object.kind.enum?
nil
else
enum_values = @context.warden.enum_values(@object)
if !include_deprecated
enum_values = enum_values.select {|f| !f.deprecation_reason }
end
enum_values
end
end
def interfaces
if @object.kind.object? || @object.kind.interface?
@context.warden.interfaces(@object).sort_by(&:graphql_name)
else
nil
end
end
def input_fields(include_deprecated:)
if @object.kind.input_object?
args = @context.warden.arguments(@object)
args = args.reject(&:deprecation_reason) unless include_deprecated
args
else
nil
end
end
def possible_types
if @object.kind.abstract?
@context.warden.possible_types(@object).sort_by(&:graphql_name)
else
nil
end
end
def fields(include_deprecated:)
if !@object.kind.fields?
nil
else
fields = @context.warden.fields(@object)
if !include_deprecated
fields = fields.select {|f| !f.deprecation_reason }
end
fields.sort_by(&:name)
end
end
def of_type
@object.kind.wraps? ? @object.of_type : nil
end
end
end
end
|