graphql 1.8.0.pre2 → 1.8.0.pre3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. checksums.yaml +4 -4
  2. data/lib/graphql.rb +1 -1
  3. data/lib/graphql/deprecated_dsl.rb +2 -0
  4. data/lib/graphql/enum_type.rb +1 -1
  5. data/lib/graphql/field.rb +10 -1
  6. data/lib/graphql/input_object_type.rb +3 -1
  7. data/lib/graphql/introspection.rb +3 -10
  8. data/lib/graphql/introspection/base_object.rb +15 -0
  9. data/lib/graphql/introspection/directive_location_enum.rb +11 -7
  10. data/lib/graphql/introspection/directive_type.rb +23 -16
  11. data/lib/graphql/introspection/dynamic_fields.rb +11 -0
  12. data/lib/graphql/introspection/entry_points.rb +29 -0
  13. data/lib/graphql/introspection/enum_value_type.rb +16 -11
  14. data/lib/graphql/introspection/field_type.rb +21 -12
  15. data/lib/graphql/introspection/input_value_type.rb +26 -23
  16. data/lib/graphql/introspection/schema_field.rb +7 -2
  17. data/lib/graphql/introspection/schema_type.rb +36 -22
  18. data/lib/graphql/introspection/type_by_name_field.rb +10 -2
  19. data/lib/graphql/introspection/type_kind_enum.rb +10 -6
  20. data/lib/graphql/introspection/type_type.rb +85 -23
  21. data/lib/graphql/introspection/typename_field.rb +1 -0
  22. data/lib/graphql/language.rb +1 -0
  23. data/lib/graphql/language/document_from_schema_definition.rb +129 -37
  24. data/lib/graphql/language/generation.rb +3 -182
  25. data/lib/graphql/language/nodes.rb +12 -2
  26. data/lib/graphql/language/parser.rb +63 -55
  27. data/lib/graphql/language/parser.y +2 -1
  28. data/lib/graphql/language/printer.rb +351 -0
  29. data/lib/graphql/object_type.rb +1 -1
  30. data/lib/graphql/query.rb +1 -1
  31. data/lib/graphql/query/arguments.rb +24 -8
  32. data/lib/graphql/query/context.rb +3 -0
  33. data/lib/graphql/query/literal_input.rb +4 -1
  34. data/lib/graphql/railtie.rb +28 -6
  35. data/lib/graphql/schema.rb +42 -7
  36. data/lib/graphql/schema/enum.rb +1 -0
  37. data/lib/graphql/schema/field.rb +26 -5
  38. data/lib/graphql/schema/field/dynamic_resolve.rb +18 -9
  39. data/lib/graphql/schema/input_object.rb +2 -2
  40. data/lib/graphql/schema/introspection_system.rb +93 -0
  41. data/lib/graphql/schema/late_bound_type.rb +32 -0
  42. data/lib/graphql/schema/member.rb +21 -1
  43. data/lib/graphql/schema/member/build_type.rb +8 -6
  44. data/lib/graphql/schema/member/has_fields.rb +1 -1
  45. data/lib/graphql/schema/member/instrumentation.rb +3 -1
  46. data/lib/graphql/schema/member/list_type_proxy.rb +4 -0
  47. data/lib/graphql/schema/member/non_null_type_proxy.rb +4 -0
  48. data/lib/graphql/schema/object.rb +2 -1
  49. data/lib/graphql/schema/printer.rb +33 -266
  50. data/lib/graphql/schema/traversal.rb +74 -6
  51. data/lib/graphql/schema/validation.rb +3 -2
  52. data/lib/graphql/static_validation/rules/fields_are_defined_on_type.rb +6 -6
  53. data/lib/graphql/tracing/scout_tracing.rb +2 -2
  54. data/lib/graphql/upgrader/member.rb +463 -63
  55. data/lib/graphql/version.rb +1 -1
  56. data/spec/fixtures/upgrader/blame_range.original.rb +43 -0
  57. data/spec/fixtures/upgrader/blame_range.transformed.rb +31 -0
  58. data/spec/fixtures/upgrader/subscribable.original.rb +51 -0
  59. data/spec/fixtures/upgrader/subscribable.transformed.rb +46 -0
  60. data/spec/fixtures/upgrader/type_x.original.rb +35 -0
  61. data/spec/fixtures/upgrader/type_x.transformed.rb +35 -0
  62. data/spec/graphql/language/document_from_schema_definition_spec.rb +729 -296
  63. data/spec/graphql/language/generation_spec.rb +21 -186
  64. data/spec/graphql/language/nodes_spec.rb +21 -0
  65. data/spec/graphql/language/printer_spec.rb +203 -0
  66. data/spec/graphql/query/arguments_spec.rb +14 -4
  67. data/spec/graphql/query/context_spec.rb +17 -0
  68. data/spec/graphql/schema/build_from_definition_spec.rb +13 -4
  69. data/spec/graphql/schema/field_spec.rb +14 -0
  70. data/spec/graphql/schema/introspection_system_spec.rb +39 -0
  71. data/spec/graphql/schema/object_spec.rb +12 -1
  72. data/spec/graphql/schema/printer_spec.rb +14 -14
  73. data/spec/graphql/tracing/platform_tracing_spec.rb +2 -2
  74. data/spec/graphql/upgrader/member_spec.rb +274 -62
  75. data/spec/support/jazz.rb +75 -3
  76. metadata +38 -9
  77. data/lib/graphql/introspection/arguments_field.rb +0 -7
  78. data/lib/graphql/introspection/enum_values_field.rb +0 -18
  79. data/lib/graphql/introspection/fields_field.rb +0 -13
  80. data/lib/graphql/introspection/input_fields_field.rb +0 -12
  81. data/lib/graphql/introspection/interfaces_field.rb +0 -11
  82. data/lib/graphql/introspection/of_type_field.rb +0 -6
  83. data/lib/graphql/introspection/possible_types_field.rb +0 -11
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cd8b7496d11a982cbb450b60c94ae0cfd2633892
4
- data.tar.gz: ef5dfa73699f3e6536987f5721a609cfbf6f0dfa
3
+ metadata.gz: 2a150383d3c4ffcaf126e675d8e844f93c4d2244
4
+ data.tar.gz: 76b98bf791afc9ca8cd0eb9caf9798005d058169
5
5
  SHA512:
6
- metadata.gz: e31127a8a336fd40f787b9369330a6a2bc1b347ef4f7f6c83bd56cabe6290520fbd67c314023d8d95052817bd2b6668f5d094612928bada3fd9898a87f50ccf9
7
- data.tar.gz: e0d167e65ce91ba9d19550fd9dd3b8a97150df1b9f5fec6a1b6463f00c88b30110cd982f8a3edaff4226ba3dc81d6f281f5bf5f5d9d71c1bfe4d9fa79342325e
6
+ metadata.gz: 4850a2d2c7872936c2ef09e016e6da4d6afba9bc554f76f08cc7f747d38e336e183ce201f184053364c468241b25442483ac83eab4e9bb63da2a74f19a67a202
7
+ data.tar.gz: 853775ca411cab71eae69b917071ebb0c03c61d1a4557d38ff8fb4410b05da3e34dad381098ba41417b03e39114d6e1ba36aab441fc3297fffb356d0222d1b73
@@ -90,7 +90,6 @@ require "graphql/string_type"
90
90
  require "graphql/directive"
91
91
  require "graphql/name_validator"
92
92
 
93
- require "graphql/introspection"
94
93
  require "graphql/language"
95
94
  require "graphql/analysis"
96
95
  require "graphql/tracing"
@@ -99,6 +98,7 @@ require "graphql/relay"
99
98
  require "graphql/schema"
100
99
  require "graphql/schema/loader"
101
100
  require "graphql/schema/printer"
101
+ require "graphql/introspection"
102
102
 
103
103
  require "graphql/analysis_error"
104
104
  require "graphql/coercion_error"
@@ -15,6 +15,8 @@ module GraphQL
15
15
  module DeprecatedDSL
16
16
  def self.activate
17
17
  GraphQL::Schema::Member.extend(Methods)
18
+ GraphQL::Schema::Member::ListTypeProxy.include(Methods)
19
+ GraphQL::Schema::Member::NonNullTypeProxy.include(Methods)
18
20
  end
19
21
  module Methods
20
22
  def !
@@ -121,7 +121,7 @@ module GraphQL
121
121
  if enum_value
122
122
  enum_value.name
123
123
  else
124
- raise(UnresolvedValueError, "Can't resolve enum #{name} for #{value}")
124
+ raise(UnresolvedValueError, "Can't resolve enum #{name} for #{value.inspect}")
125
125
  end
126
126
  end
127
127
 
@@ -131,6 +131,7 @@ module GraphQL
131
131
  :relay_nodes_field,
132
132
  :subscription_scope,
133
133
  :trace,
134
+ :introspection,
134
135
  argument: GraphQL::Define::AssignArgument
135
136
 
136
137
  ensure_defined(
@@ -138,7 +139,8 @@ module GraphQL
138
139
  :mutation, :arguments, :complexity, :function,
139
140
  :resolve, :resolve=, :lazy_resolve, :lazy_resolve=, :lazy_resolve_proc, :resolve_proc,
140
141
  :type, :type=, :name=, :property=, :hash_key=,
141
- :relay_node_field, :relay_nodes_field, :edges?, :edge_class, :subscription_scope
142
+ :relay_node_field, :relay_nodes_field, :edges?, :edge_class, :subscription_scope,
143
+ :introspection?
142
144
  )
143
145
 
144
146
  # @return [Boolean] True if this is the Relay find-by-id field
@@ -183,6 +185,7 @@ module GraphQL
183
185
  attr_accessor :arguments_class
184
186
 
185
187
  attr_writer :connection
188
+ attr_writer :introspection
186
189
 
187
190
  # @return [nil, String] Prefix for subscription names from this field
188
191
  attr_accessor :subscription_scope
@@ -217,6 +220,7 @@ module GraphQL
217
220
  @connection_max_page_size = nil
218
221
  @edge_class = nil
219
222
  @trace = nil
223
+ @introspection = false
220
224
  end
221
225
 
222
226
  def initialize_copy(other)
@@ -225,6 +229,11 @@ module GraphQL
225
229
  @arguments = other.arguments.dup
226
230
  end
227
231
 
232
+ # @return [Boolean] Is this field a predefined introspection field?
233
+ def introspection?
234
+ @introspection
235
+ end
236
+
228
237
  # Get a value for this field
229
238
  # @example resolving a field value
230
239
  # field.resolve(obj, args, ctx)
@@ -84,6 +84,7 @@ module GraphQL
84
84
 
85
85
  def coerce_non_null_input(value, ctx)
86
86
  input_values = {}
87
+ defaults_used = Set.new
87
88
 
88
89
  arguments.each do |input_key, input_field_defn|
89
90
  field_value = value[input_key]
@@ -93,10 +94,11 @@ module GraphQL
93
94
  input_values[input_key] = input_field_defn.prepare(coerced_value, ctx)
94
95
  elsif input_field_defn.default_value?
95
96
  input_values[input_key] = input_field_defn.default_value
97
+ defaults_used << input_key
96
98
  end
97
99
  end
98
100
 
99
- arguments_class.new(input_values, context: ctx)
101
+ arguments_class.new(input_values, context: ctx, defaults_used: defaults_used)
100
102
  end
101
103
 
102
104
  # @api private
@@ -4,25 +4,18 @@ module GraphQL
4
4
  end
5
5
  end
6
6
 
7
+ require "graphql/introspection/base_object"
7
8
  require "graphql/introspection/typename_field"
8
9
  require "graphql/introspection/input_value_type"
9
10
  require "graphql/introspection/enum_value_type"
10
11
  require "graphql/introspection/type_kind_enum"
11
-
12
- require "graphql/introspection/fields_field"
13
- require "graphql/introspection/of_type_field"
14
- require "graphql/introspection/input_fields_field"
15
- require "graphql/introspection/possible_types_field"
16
- require "graphql/introspection/enum_values_field"
17
- require "graphql/introspection/interfaces_field"
18
-
19
12
  require "graphql/introspection/type_type"
20
- require "graphql/introspection/arguments_field"
21
13
  require "graphql/introspection/field_type"
22
-
23
14
  require "graphql/introspection/directive_location_enum"
24
15
  require "graphql/introspection/directive_type"
25
16
  require "graphql/introspection/schema_type"
26
17
  require "graphql/introspection/schema_field"
27
18
  require "graphql/introspection/type_by_name_field"
28
19
  require "graphql/introspection/introspection_query"
20
+ require "graphql/introspection/dynamic_fields"
21
+ require "graphql/introspection/entry_points"
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+ module GraphQL
3
+ module Introspection
4
+ class BaseObject < GraphQL::Schema::Object
5
+ def self.field(*args, **kwargs, &block)
6
+ kwargs[:introspection] = true
7
+ super(*args, **kwargs, &block)
8
+ end
9
+
10
+ def self.inherited(child_class)
11
+ child_class.introspection(true)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -1,11 +1,15 @@
1
1
  # frozen_string_literal: true
2
- GraphQL::Introspection::DirectiveLocationEnum = GraphQL::EnumType.define do
3
- name "__DirectiveLocation"
4
- description "A Directive can be adjacent to many parts of the GraphQL language, a "\
5
- "__DirectiveLocation describes one such possible adjacencies."
2
+ module GraphQL
3
+ module Introspection
4
+ class DirectiveLocationEnum < GraphQL::Schema::Enum
5
+ graphql_name "__DirectiveLocation"
6
+ description "A Directive can be adjacent to many parts of the GraphQL language, "\
7
+ "a __DirectiveLocation describes one such possible adjacencies."
6
8
 
7
- GraphQL::Directive::LOCATIONS.each do |location|
8
- value(location.to_s, GraphQL::Directive::LOCATION_DESCRIPTIONS[location], value: location)
9
+ GraphQL::Directive::LOCATIONS.each do |location|
10
+ value(location.to_s, GraphQL::Directive::LOCATION_DESCRIPTIONS[location], value: location)
11
+ end
12
+ introspection true
13
+ end
9
14
  end
10
- introspection true
11
15
  end
@@ -1,18 +1,25 @@
1
1
  # frozen_string_literal: true
2
- GraphQL::Introspection::DirectiveType = GraphQL::ObjectType.define do
3
- name "__Directive"
4
- description "A Directive provides a way to describe alternate runtime execution and type validation behavior in a GraphQL document."\
5
- "\n\n"\
6
- "In some cases, you need to provide options to alter GraphQL's execution behavior "\
7
- "in ways field arguments will not suffice, such as conditionally including or "\
8
- "skipping a field. Directives provide this by describing additional information "\
9
- "to the executor."
10
- field :name, !types.String
11
- field :description, types.String
12
- field :locations, !types[!GraphQL::Introspection::DirectiveLocationEnum]
13
- field :args, field: GraphQL::Introspection::ArgumentsField
14
- field :onOperation, !types.Boolean, deprecation_reason: "Use `locations`.", property: :on_operation?
15
- field :onFragment, !types.Boolean, deprecation_reason: "Use `locations`.", property: :on_fragment?
16
- field :onField, !types.Boolean, deprecation_reason: "Use `locations`.", property: :on_field?
17
- introspection true
2
+ module GraphQL
3
+ module Introspection
4
+ class DirectiveType < Introspection::BaseObject
5
+ graphql_name "__Directive"
6
+ description "A Directive provides a way to describe alternate runtime execution and type validation behavior in a GraphQL document."\
7
+ "\n\n"\
8
+ "In some cases, you need to provide options to alter GraphQL's execution behavior "\
9
+ "in ways field arguments will not suffice, such as conditionally including or "\
10
+ "skipping a field. Directives provide this by describing additional information "\
11
+ "to the executor."
12
+ field :name, String, null: false
13
+ field :description, String, null: true
14
+ field :locations, [GraphQL::Schema::LateBoundType.new("__DirectiveLocation")], null: false
15
+ field :args, [GraphQL::Schema::LateBoundType.new("__InputValue")], null: false
16
+ field :on_operation, Boolean, null: false, deprecation_reason: "Use `locations`.", method: :on_operation?
17
+ field :on_fragment, Boolean, null: false, deprecation_reason: "Use `locations`.", method: :on_fragment?
18
+ field :on_field, Boolean, null: false, deprecation_reason: "Use `locations`.", method: :on_field?
19
+
20
+ def args
21
+ @context.warden.arguments(@object)
22
+ end
23
+ end
24
+ end
18
25
  end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+ module GraphQL
3
+ module Introspection
4
+ class DynamicFields < GraphQL::Schema::Object
5
+ field :__typename, String, "The name of this type", null: false, extras: [:irep_node]
6
+ def __typename(irep_node:)
7
+ irep_node.owner_type.name
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+ module GraphQL
3
+ module Introspection
4
+ class EntryPoints < GraphQL::Schema::Object
5
+ field :__schema, GraphQL::Schema::LateBoundType.new("__Schema"), "This GraphQL schema", null: false
6
+ field :__type, GraphQL::Schema::LateBoundType.new("__Type"), "A type in the GraphQL system", null: true do
7
+ argument :name, String, required: true
8
+ end
9
+
10
+ def __schema
11
+ # Apply wrapping manually since this field isn't wrapped by instrumentation
12
+ schema = @context.query.schema
13
+ schema_type = schema.introspection_system.schema_type
14
+ schema_type.metadata[:object_class].new(schema, @context)
15
+ end
16
+
17
+ def __type(name:)
18
+ type = @context.warden.get_type(name)
19
+ if type
20
+ # Apply wrapping manually since this field isn't wrapped by instrumentation
21
+ type_type = @context.schema.introspection_system.type_type
22
+ type_type.metadata[:object_class].new(type, @context)
23
+ else
24
+ nil
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -1,14 +1,19 @@
1
1
  # frozen_string_literal: true
2
- GraphQL::Introspection::EnumValueType = GraphQL::ObjectType.define do
3
- name "__EnumValue"
4
- description "One possible value for a given Enum. Enum values are unique values, not a "\
5
- "placeholder for a string or numeric value. However an Enum value is returned in "\
6
- "a JSON response as a string."
7
- field :name, !types.String
8
- field :description, types.String
9
- field :isDeprecated, !types.Boolean do
10
- resolve ->(obj, a, c) { !!obj.deprecation_reason }
2
+ module GraphQL
3
+ module Introspection
4
+ class EnumValueType < Introspection::BaseObject
5
+ graphql_name "__EnumValue"
6
+ description "One possible value for a given Enum. Enum values are unique values, not a "\
7
+ "placeholder for a string or numeric value. However an Enum value is returned in "\
8
+ "a JSON response as a string."
9
+ field :name, String, null: false
10
+ field :description, String, null: true
11
+ field :is_deprecated, Boolean, null: false
12
+ field :deprecation_reason, String, null: true
13
+
14
+ def is_deprecated
15
+ !!@object.deprecation_reason
16
+ end
17
+ end
11
18
  end
12
- field :deprecationReason, types.String, property: :deprecation_reason
13
- introspection true
14
19
  end
@@ -1,15 +1,24 @@
1
1
  # frozen_string_literal: true
2
- GraphQL::Introspection::FieldType = GraphQL::ObjectType.define do
3
- name "__Field"
4
- description "Object and Interface types are described by a list of Fields, each of which has "\
5
- "a name, potentially a list of arguments, and a return type."
6
- field :name, !types.String
7
- field :description, types.String
8
- field :args, GraphQL::Introspection::ArgumentsField
9
- field :type, !GraphQL::Introspection::TypeType
10
- field :isDeprecated, !types.Boolean do
11
- resolve ->(obj, a, c) { !!obj.deprecation_reason }
2
+ module GraphQL
3
+ module Introspection
4
+ class FieldType < Introspection::BaseObject
5
+ graphql_name "__Field"
6
+ description "Object and Interface types are described by a list of Fields, each of which has "\
7
+ "a name, potentially a list of arguments, and a return type."
8
+ field :name, String, null: false
9
+ field :description, String, null: true
10
+ field :args, [GraphQL::Schema::LateBoundType.new("__InputValue")], null: false
11
+ field :type, GraphQL::Schema::LateBoundType.new("__Type"), null: false
12
+ field :is_deprecated, Boolean, null: false
13
+ field :deprecation_reason, String, null: true
14
+
15
+ def is_deprecated
16
+ !!@object.deprecation_reason
17
+ end
18
+
19
+ def args
20
+ @context.warden.arguments(@object)
21
+ end
22
+ end
12
23
  end
13
- field :deprecationReason, types.String, property: :deprecation_reason
14
- introspection true
15
24
  end
@@ -1,30 +1,33 @@
1
1
  # frozen_string_literal: true
2
- GraphQL::Introspection::InputValueType = GraphQL::ObjectType.define do
3
- name "__InputValue"
4
- description "Arguments provided to Fields or Directives and the input fields of an "\
5
- "InputObject are represented as Input Values which describe their type and "\
6
- "optionally a default value."
7
- field :name, !types.String
8
- field :description, types.String
9
- field :type, !GraphQL::Introspection::TypeType
10
- field :defaultValue, types.String, "A GraphQL-formatted string representing the default value for this input value." do
11
- resolve ->(obj, args, ctx) {
12
- if obj.default_value?
13
- value = obj.default_value
14
- if value.nil?
15
- 'null'
16
- else
17
- coerced_default_value = obj.type.coerce_result(value, ctx)
18
- if obj.type.unwrap.is_a?(GraphQL::EnumType)
19
- coerced_default_value
2
+ module GraphQL
3
+ module Introspection
4
+ class InputValueType < Introspection::BaseObject
5
+ graphql_name "__InputValue"
6
+ description "Arguments provided to Fields or Directives and the input fields of an "\
7
+ "InputObject are represented as Input Values which describe their type and "\
8
+ "optionally a default value."
9
+ field :name, String, null: false
10
+ field :description, String, null: true
11
+ field :type, GraphQL::Schema::LateBoundType.new("__Type"), null: false
12
+ field :default_value, String, "A GraphQL-formatted string representing the default value for this input value.", null: true
13
+
14
+ def default_value
15
+ if @object.default_value?
16
+ value = @object.default_value
17
+ if value.nil?
18
+ 'null'
20
19
  else
21
- GraphQL::Language.serialize(coerced_default_value)
20
+ coerced_default_value = @object.type.coerce_result(value, @context)
21
+ if @object.type.unwrap.is_a?(GraphQL::EnumType)
22
+ coerced_default_value
23
+ else
24
+ GraphQL::Language.serialize(coerced_default_value)
25
+ end
22
26
  end
27
+ else
28
+ nil
23
29
  end
24
- else
25
- nil
26
30
  end
27
- }
31
+ end
28
32
  end
29
- introspection true
30
33
  end
@@ -4,8 +4,13 @@ module GraphQL
4
4
  SchemaField = GraphQL::Field.define do
5
5
  name("__schema")
6
6
  description("This GraphQL schema")
7
- type(!GraphQL::Introspection::SchemaType)
8
- resolve ->(o, a, ctx) { ctx.query.schema }
7
+ type(GraphQL::Schema::LateBoundType.new("__Schema").to_non_null_type)
8
+ resolve ->(o, a, ctx) {
9
+ # Apply wrapping manually since this field isn't wrapped by instrumentation
10
+ schema = ctx.query.schema
11
+ schema_type = schema.introspection_system.schema_type
12
+ schema_type.metadata[:object_class].new(schema, ctx.query.context)
13
+ }
9
14
  end
10
15
  end
11
16
  end
@@ -1,29 +1,43 @@
1
1
  # frozen_string_literal: true
2
- GraphQL::Introspection::SchemaType = GraphQL::ObjectType.define do
3
- name "__Schema"
4
- description "A GraphQL Schema defines the capabilities of a GraphQL server. It exposes all "\
5
- "available types and directives on the server, as well as the entry points for "\
6
- "query, mutation, and subscription operations."
7
-
8
- field :types, !types[!GraphQL::Introspection::TypeType], "A list of all types supported by this server." do
9
- resolve ->(obj, arg, ctx) { ctx.warden.types }
10
- end
2
+ module GraphQL
3
+ module Introspection
4
+ class SchemaType < Introspection::BaseObject
5
+ graphql_name "__Schema"
6
+ description "A GraphQL Schema defines the capabilities of a GraphQL server. It exposes all "\
7
+ "available types and directives on the server, as well as the entry points for "\
8
+ "query, mutation, and subscription operations."
11
9
 
12
- field :queryType, !GraphQL::Introspection::TypeType, "The type that query operations will be rooted at." do
13
- resolve ->(obj, arg, ctx) { ctx.warden.root_type_for_operation("query") }
14
- end
10
+ field :types, [GraphQL::Schema::LateBoundType.new("__Type")], "A list of all types supported by this server.", null: false
11
+ field :queryType, GraphQL::Schema::LateBoundType.new("__Type"), "The type that query operations will be rooted at.", null: false
12
+ field :mutationType, GraphQL::Schema::LateBoundType.new("__Type"), "If this server supports mutation, the type that mutation operations will be rooted at.", null: true
13
+ field :subscriptionType, GraphQL::Schema::LateBoundType.new("__Type"), "If this server support subscription, the type that subscription operations will be rooted at.", null: true
14
+ field :directives, [GraphQL::Schema::LateBoundType.new("__Directive")], "A list of all directives supported by this server.", null: false
15
15
 
16
- field :mutationType, GraphQL::Introspection::TypeType, "If this server supports mutation, the type that mutation operations will be rooted at." do
17
- resolve ->(obj, arg, ctx) { ctx.warden.root_type_for_operation("mutation") }
18
- end
16
+ def types
17
+ @context.warden.types
18
+ end
19
19
 
20
- field :subscriptionType, GraphQL::Introspection::TypeType, "If this server support subscription, the type that subscription operations will be rooted at." do
21
- resolve ->(obj, arg, ctx) { ctx.warden.root_type_for_operation("subscription") }
22
- end
20
+ def query_type
21
+ permitted_root_type("query")
22
+ end
23
23
 
24
- field :directives, !types[!GraphQL::Introspection::DirectiveType], "A list of all directives supported by this server." do
25
- resolve ->(obj, arg, ctx) { obj.directives.values }
26
- end
24
+ def mutation_type
25
+ permitted_root_type("mutation")
26
+ end
27
27
 
28
- introspection true
28
+ def subscription_type
29
+ permitted_root_type("subscription")
30
+ end
31
+
32
+ def directives
33
+ @object.directives.values
34
+ end
35
+
36
+ private
37
+
38
+ def permitted_root_type(op_type)
39
+ @context.warden.root_type_for_operation(op_type)
40
+ end
41
+ end
42
+ end
29
43
  end