graphql 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (108) hide show
  1. checksums.yaml +4 -4
  2. data/lib/graph_ql/directive.rb +9 -5
  3. data/lib/graph_ql/directives/include_directive.rb +2 -2
  4. data/lib/graph_ql/directives/skip_directive.rb +2 -2
  5. data/lib/graph_ql/enum.rb +5 -8
  6. data/lib/graph_ql/field.rb +50 -0
  7. data/lib/graph_ql/interface.rb +4 -0
  8. data/lib/graph_ql/introspection/arguments_field.rb +2 -2
  9. data/lib/graph_ql/introspection/directive_type.rb +10 -10
  10. data/lib/graph_ql/introspection/enum_value_type.rb +11 -8
  11. data/lib/graph_ql/introspection/enum_values_field.rb +5 -5
  12. data/lib/graph_ql/introspection/field_type.rb +14 -10
  13. data/lib/graph_ql/introspection/fields_field.rb +4 -4
  14. data/lib/graph_ql/introspection/input_fields_field.rb +3 -3
  15. data/lib/graph_ql/introspection/input_value_type.rb +8 -8
  16. data/lib/graph_ql/introspection/interfaces_field.rb +5 -0
  17. data/lib/graph_ql/introspection/of_type_field.rb +3 -9
  18. data/lib/graph_ql/introspection/possible_types_field.rb +3 -10
  19. data/lib/graph_ql/introspection/schema_type.rb +8 -14
  20. data/lib/graph_ql/introspection/type_kind_enum.rb +1 -1
  21. data/lib/graph_ql/introspection/type_type.rb +17 -19
  22. data/lib/graph_ql/introspection/typename_field.rb +15 -0
  23. data/lib/graph_ql/parser.rb +9 -0
  24. data/lib/graph_ql/parser/nodes.rb +17 -7
  25. data/lib/graph_ql/parser/parser.rb +7 -7
  26. data/lib/graph_ql/parser/transform.rb +23 -20
  27. data/lib/graph_ql/parser/visitor.rb +29 -13
  28. data/lib/graph_ql/query.rb +39 -16
  29. data/lib/graph_ql/query/field_resolution_strategy.rb +15 -11
  30. data/lib/graph_ql/query/type_resolver.rb +4 -2
  31. data/lib/graph_ql/repl.rb +1 -1
  32. data/lib/graph_ql/schema.rb +19 -7
  33. data/lib/graph_ql/schema/each_item_validator.rb +12 -0
  34. data/lib/graph_ql/schema/field_validator.rb +13 -0
  35. data/lib/graph_ql/schema/implementation_validator.rb +21 -0
  36. data/lib/graph_ql/schema/schema_validator.rb +10 -0
  37. data/lib/graph_ql/schema/type_reducer.rb +6 -6
  38. data/lib/graph_ql/schema/type_validator.rb +47 -0
  39. data/lib/graph_ql/static_validation.rb +18 -0
  40. data/lib/graph_ql/static_validation/argument_literals_are_compatible.rb +13 -0
  41. data/lib/graph_ql/static_validation/arguments_are_defined.rb +10 -0
  42. data/lib/graph_ql/static_validation/arguments_validator.rb +16 -0
  43. data/lib/graph_ql/static_validation/directives_are_defined.rb +18 -0
  44. data/lib/graph_ql/static_validation/fields_are_defined_on_type.rb +29 -0
  45. data/lib/graph_ql/static_validation/fields_have_appropriate_selections.rb +31 -0
  46. data/lib/graph_ql/static_validation/fields_will_merge.rb +93 -0
  47. data/lib/graph_ql/static_validation/fragment_types_exist.rb +24 -0
  48. data/lib/graph_ql/static_validation/fragments_are_used.rb +30 -0
  49. data/lib/graph_ql/static_validation/literal_validator.rb +27 -0
  50. data/lib/graph_ql/static_validation/message.rb +29 -0
  51. data/lib/graph_ql/static_validation/required_arguments_are_present.rb +13 -0
  52. data/lib/graph_ql/static_validation/type_stack.rb +87 -0
  53. data/lib/graph_ql/static_validation/validator.rb +48 -0
  54. data/lib/graph_ql/type_kinds.rb +50 -12
  55. data/lib/graph_ql/types/argument_definer.rb +7 -0
  56. data/lib/graph_ql/types/boolean_type.rb +3 -3
  57. data/lib/graph_ql/types/field_definer.rb +19 -0
  58. data/lib/graph_ql/types/float_type.rb +3 -3
  59. data/lib/graph_ql/types/input_object_type.rb +4 -0
  60. data/lib/graph_ql/types/input_value.rb +1 -1
  61. data/lib/graph_ql/types/int_type.rb +4 -4
  62. data/lib/graph_ql/types/list_type.rb +5 -1
  63. data/lib/graph_ql/types/non_null_type.rb +4 -0
  64. data/lib/graph_ql/types/object_type.rb +9 -20
  65. data/lib/graph_ql/types/scalar_type.rb +4 -0
  66. data/lib/graph_ql/types/string_type.rb +3 -3
  67. data/lib/graph_ql/types/type_definer.rb +5 -9
  68. data/lib/graph_ql/union.rb +6 -17
  69. data/lib/graph_ql/version.rb +1 -1
  70. data/lib/graphql.rb +58 -78
  71. data/readme.md +80 -7
  72. data/spec/graph_ql/interface_spec.rb +15 -1
  73. data/spec/graph_ql/introspection/directive_type_spec.rb +2 -2
  74. data/spec/graph_ql/introspection/schema_type_spec.rb +2 -1
  75. data/spec/graph_ql/introspection/type_type_spec.rb +16 -1
  76. data/spec/graph_ql/parser/parser_spec.rb +3 -1
  77. data/spec/graph_ql/parser/transform_spec.rb +12 -2
  78. data/spec/graph_ql/parser/visitor_spec.rb +13 -5
  79. data/spec/graph_ql/query_spec.rb +25 -13
  80. data/spec/graph_ql/schema/field_validator_spec.rb +21 -0
  81. data/spec/graph_ql/schema/type_reducer_spec.rb +2 -2
  82. data/spec/graph_ql/schema/type_validator_spec.rb +54 -0
  83. data/spec/graph_ql/static_validation/argument_literals_are_compatible_spec.rb +41 -0
  84. data/spec/graph_ql/static_validation/arguments_are_defined_spec.rb +40 -0
  85. data/spec/graph_ql/static_validation/directives_are_defined_spec.rb +33 -0
  86. data/spec/graph_ql/static_validation/fields_are_defined_on_type_spec.rb +59 -0
  87. data/spec/graph_ql/static_validation/fields_have_appropriate_selections_spec.rb +30 -0
  88. data/spec/graph_ql/{validations → static_validation}/fields_will_merge_spec.rb +24 -17
  89. data/spec/graph_ql/static_validation/fragment_types_exist_spec.rb +38 -0
  90. data/spec/graph_ql/static_validation/fragments_are_used_spec.rb +24 -0
  91. data/spec/graph_ql/static_validation/required_arguments_are_present_spec.rb +41 -0
  92. data/spec/graph_ql/static_validation/type_stack_spec.rb +35 -0
  93. data/spec/graph_ql/static_validation/validator_spec.rb +28 -0
  94. data/spec/graph_ql/types/object_type_spec.rb +1 -1
  95. data/spec/graph_ql/union_spec.rb +1 -14
  96. data/spec/support/dummy_app.rb +75 -53
  97. metadata +53 -31
  98. data/lib/graph_ql/fields/abstract_field.rb +0 -37
  99. data/lib/graph_ql/fields/access_field.rb +0 -24
  100. data/lib/graph_ql/fields/field.rb +0 -34
  101. data/lib/graph_ql/types/abstract_type.rb +0 -14
  102. data/lib/graph_ql/validations/fields_are_defined_on_type.rb +0 -44
  103. data/lib/graph_ql/validations/fields_will_merge.rb +0 -80
  104. data/lib/graph_ql/validations/fragments_are_used.rb +0 -24
  105. data/lib/graph_ql/validator.rb +0 -29
  106. data/spec/graph_ql/validations/fields_are_defined_on_type_spec.rb +0 -28
  107. data/spec/graph_ql/validations/fragments_are_used_spec.rb +0 -28
  108. data/spec/graph_ql/validator_spec.rb +0 -24
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7b1fdc7f41a30030c670d131b5725c04e6a19090
4
- data.tar.gz: 5a6326377c36595c319f710c2f2e429188589266
3
+ metadata.gz: 45c3f35aae5e941e7bad2109eb9405e6afc081cc
4
+ data.tar.gz: 3cd3d8dd85a88e341552d0709aff11361937d157
5
5
  SHA512:
6
- metadata.gz: 12d6d135cde8e87dc9ba32dab2c5e02bb418dd76922c086de95223f62fa544b87049dc15845a5f03818492324cc963715259a926e234263fd00e0ae336970fb4
7
- data.tar.gz: 25e46e69f7210ace996eb2c2d93c52a03ae75944c58d269709e61200a6a872479edbe5ede7b7e446f30f3dd458abbbf736881da13b4969c8daaa1c3be99da1d5
6
+ metadata.gz: 274f08f78112de84f94dcb9fcdcc62da63a36a29000aad2055cf5e353327bb9ba3f673fe3e83c3a3c6405b360847f17104ab97c66a08323400f6df3f27f6044a
7
+ data.tar.gz: 82f47b290d9779b1214bb59857edb079369932d08686a8ac1af47c15ab1f3e549e4c8f9f269947836fe2093fc49badc6986e397466cb2d1010520bc3a765e7ff
@@ -10,14 +10,15 @@ class GraphQL::Directive < GraphQL::ObjectType
10
10
 
11
11
  attr_definable :on, :arguments
12
12
 
13
- def initialize(&block)
13
+ def initialize
14
14
  @arguments = {}
15
15
  @on = []
16
- yield(self) if block_given?
16
+ yield(self, GraphQL::TypeDefiner.instance, GraphQL::FieldDefiner.instance, GraphQL::ArgumentDefiner.instance)
17
17
  end
18
18
 
19
19
  def resolve(proc_or_arguments, proc=nil)
20
20
  if proc.nil?
21
+ # resolve is being defined, just set it
21
22
  @resolve_proc = proc_or_arguments
22
23
  else
23
24
  @resolve_proc.call(proc_or_arguments, proc)
@@ -25,12 +26,15 @@ class GraphQL::Directive < GraphQL::ObjectType
25
26
  end
26
27
 
27
28
  def arguments(new_arguments=nil)
28
- if new_arguments.nil?
29
- @arguments
30
- else
29
+ if !new_arguments.nil?
31
30
  @arguments = new_arguments
32
31
  .reduce({}) {|memo, (k, v)| memo[k.to_s] = v; memo}
33
32
  .each { |k, v| v.respond_to?("name=") && v.name = k}
34
33
  end
34
+ @arguments
35
35
  end
36
36
  end
37
+
38
+ require 'graph_ql/directives/directive_chain'
39
+ require 'graph_ql/directives/include_directive'
40
+ require 'graph_ql/directives/skip_directive'
@@ -1,9 +1,9 @@
1
- GraphQL::IncludeDirective = GraphQL::Directive.new do |d|
1
+ GraphQL::IncludeDirective = GraphQL::Directive.new do |d, type, field, arg|
2
2
  d.name "include"
3
3
  d.description "Include this part of the query if `if` is true"
4
4
  d.on([GraphQL::Directive::ON_FIELD, GraphQL::Directive::ON_FRAGMENT])
5
5
  d.arguments({
6
- if: d.arg({type: !GraphQL::BOOLEAN_TYPE})
6
+ if: arg.build({type: !GraphQL::BOOLEAN_TYPE})
7
7
  })
8
8
  d.resolve -> (arguments, proc) {
9
9
  if arguments["if"]
@@ -1,9 +1,9 @@
1
- GraphQL::SkipDirective = GraphQL::Directive.new do |d|
1
+ GraphQL::SkipDirective = GraphQL::Directive.new do |d, type, field, arg|
2
2
  d.name "skip"
3
3
  d.description "Ignore this part of the query if `if` is true"
4
4
  d.on([GraphQL::Directive::ON_FIELD, GraphQL::Directive::ON_FRAGMENT])
5
5
  d.arguments({
6
- if: d.arg({type: !GraphQL::BOOLEAN_TYPE})
6
+ if: arg.build({type: !GraphQL::BOOLEAN_TYPE})
7
7
  })
8
8
  d.resolve -> (arguments, proc) {
9
9
  if !arguments["if"]
@@ -5,21 +5,21 @@ class GraphQL::Enum
5
5
  attr_reader :values
6
6
  def initialize
7
7
  @values = {}
8
- yield(self) if block_given?
8
+ yield(self, GraphQL::TypeDefiner.instance, GraphQL::FieldDefiner.instance, GraphQL::ArgumentDefiner.instance)
9
9
  end
10
10
 
11
11
  def value(name, description=nil, deprecation_reason: nil)
12
12
  @values[name] = EnumValue.new(name: name, description: description, deprecation_reason: deprecation_reason)
13
13
  end
14
14
 
15
- def [](val)
16
- @values[val]
17
- end
18
-
19
15
  def kind
20
16
  GraphQL::TypeKinds::ENUM
21
17
  end
22
18
 
19
+ def coerce(value)
20
+ @values[value]
21
+ end
22
+
23
23
  class EnumValue
24
24
  attr_reader :name, :description, :deprecation_reason
25
25
  def initialize(name:, description:, deprecation_reason:)
@@ -27,8 +27,5 @@ class GraphQL::Enum
27
27
  @description = description
28
28
  @deprecation_reason = deprecation_reason
29
29
  end
30
- def deprecated?
31
- !!deprecation_reason
32
- end
33
30
  end
34
31
  end
@@ -0,0 +1,50 @@
1
+ class GraphQL::Field
2
+ extend GraphQL::Definable
3
+ attr_definable(:arguments, :deprecation_reason, :name, :description, :type)
4
+
5
+ def initialize
6
+ @arguments = {}
7
+ @resolve_proc = -> (o, a, c) { GraphQL::Query::DEFAULT_RESOLVE }
8
+ yield(self, GraphQL::TypeDefiner.instance, GraphQL::FieldDefiner.instance, GraphQL::ArgumentDefiner.instance)
9
+ end
10
+
11
+ def arguments(new_arguments=nil)
12
+ if !new_arguments.nil?
13
+ self.arguments=(new_arguments)
14
+ end
15
+ @arguments
16
+ end
17
+
18
+ def arguments=(new_arguments)
19
+ stringified_arguments = new_arguments
20
+ .reduce({}) { |memo, (key, value)| memo[key.to_s] = value; memo }
21
+ # Set the name from its context on this type:
22
+ stringified_arguments.each {|k, v| v.respond_to?("name=") && v.name = k }
23
+ @arguments = stringified_arguments
24
+ end
25
+
26
+
27
+ # Used when defining:
28
+ # resolve -> (obj, args, ctx) { obj.get_value }
29
+ # Also used when executing queries:
30
+ # field.resolve(obj, args, ctx)
31
+ def resolve(proc_or_object, arguments=nil, ctx=nil)
32
+ if arguments.nil? && ctx.nil?
33
+ @resolve_proc = proc_or_object
34
+ else
35
+ @resolve_proc.call(proc_or_object, arguments, ctx)
36
+ end
37
+ end
38
+
39
+ # You can pass a proc which will cause the type to be lazy-evaled,
40
+ # That's nice if you have load-order issues
41
+ def type(type_or_proc=nil)
42
+ if !type_or_proc.nil?
43
+ @type = type_or_proc
44
+ elsif @type.is_a?(Proc)
45
+ # lazy-eval it
46
+ @type = @type.call
47
+ end
48
+ @type
49
+ end
50
+ end
@@ -11,4 +11,8 @@ class GraphQL::Interface < GraphQL::ObjectType
11
11
  def resolve_type(object)
12
12
  @possible_types.find {|t| t.name == object.class.name }
13
13
  end
14
+
15
+ def to_s
16
+ "<GraphQL::Interface #{name}>"
17
+ end
14
18
  end
@@ -1,5 +1,5 @@
1
- GraphQL::ArgumentsField = GraphQL::Field.new do |f|
1
+ GraphQL::Introspection::ArgumentsField = GraphQL::Field.new do |f|
2
2
  f.description "Arguments allowed to this object"
3
- f.type GraphQL::ListType.new(of_type: GraphQL::InputValueType)
3
+ f.type GraphQL::ListType.new(of_type: GraphQL::Introspection::InputValueType)
4
4
  f.resolve -> (target, a, c) { target.arguments.values }
5
5
  end
@@ -1,12 +1,12 @@
1
- GraphQL::DirectiveType = GraphQL::ObjectType.new do
2
- name "__Directive"
3
- description "A query directive in this schema"
4
- fields({
5
- name: field(type: !type.String, desc: "The name of this directive"),
6
- description: field(type: type.String, desc: "The description for this type"),
7
- args: GraphQL::ArgumentsField,
8
- onOperation: field(type: !type.Boolean, property: :on_operation?, desc: "Does this directive apply to operations?"),
9
- onFragment: field(type: !type.Boolean, property: :on_fragment?, desc: "Does this directive apply to fragments?"),
10
- onField: field(type: !type.Boolean, property: :on_field?, desc: "Does this directive apply to fields?"),
1
+ GraphQL::Introspection::DirectiveType = GraphQL::ObjectType.new do |t, type, field|
2
+ t.name "__Directive"
3
+ t.description "A query directive in this schema"
4
+ t.fields({
5
+ name: field.build(type: !type.String, desc: "The name of this directive"),
6
+ description: field.build(type: type.String, desc: "The description for this type"),
7
+ args: GraphQL::Introspection::ArgumentsField,
8
+ onOperation: field.build(type: !type.Boolean, property: :on_operation?, desc: "Does this directive apply to operations?"),
9
+ onFragment: field.build(type: !type.Boolean, property: :on_fragment?, desc: "Does this directive apply to fragments?"),
10
+ onField: field.build(type: !type.Boolean, property: :on_field?, desc: "Does this directive apply to fields?"),
11
11
  })
12
12
  end
@@ -1,10 +1,13 @@
1
- GraphQL::EnumValueType = GraphQL::ObjectType.new do
2
- name "__EnumValue"
3
- description "A possible value for an Enum"
4
- fields({
5
- name: field(type: !type.String),
6
- description: field(type: !type.String),
7
- deprecationReason: field(type: !type.String, property: :deprecation_reason),
8
- isDeprecated: field(type: !type.Boolean, property: :deprecated?),
1
+ GraphQL::Introspection::EnumValueType = GraphQL::ObjectType.new do |t, type, field|
2
+ t.name "__EnumValue"
3
+ t.description "A possible value for an Enum"
4
+ t.fields({
5
+ name: field.build(type: !type.String),
6
+ description: field.build(type: !type.String),
7
+ deprecationReason: field.build(type: !type.String, property: :deprecation_reason),
8
+ isDeprecated: GraphQL::Field.new { |f|
9
+ f.type !type.Boolean
10
+ f.resolve -> (obj, a, c) { !!obj.deprecation_reason }
11
+ },
9
12
  })
10
13
  end
@@ -1,14 +1,14 @@
1
- GraphQL::EnumValuesField = GraphQL::Field.new do |f|
1
+ GraphQL::Introspection::EnumValuesField = GraphQL::Field.new do |f, type, field, arg|
2
2
  f.description "Values for this enum"
3
- f.type GraphQL::ListType.new(of_type: GraphQL::NonNullType.new(of_type: GraphQL::EnumValueType))
3
+ f.type type[!GraphQL::Introspection::EnumValueType]
4
4
  f.arguments({
5
- includeDeprecated: {type: GraphQL::BOOLEAN_TYPE, default_value: false}
5
+ includeDeprecated: arg.build({type: GraphQL::BOOLEAN_TYPE, default_value: false})
6
6
  })
7
7
  f.resolve -> (object, arguments, context) {
8
- return nil if object.kind != GraphQL::TypeKinds::ENUM
8
+ return nil if !object.kind.enum?
9
9
  fields = object.values.values
10
10
  if !arguments["includeDeprecated"]
11
- fields = fields.select {|f| !f.deprecated? }
11
+ fields = fields.select {|f| !f.deprecation_reason }
12
12
  end
13
13
  fields
14
14
  }
@@ -1,11 +1,15 @@
1
- GraphQL::FieldType = GraphQL::ObjectType.new do
2
- name "__Field"
3
- description "Field on a GraphQL type"
4
- self.fields = {
5
- name: field(type: !type.String, desc: "The name for accessing this field"),
6
- description: field(type: !type.String, desc: "The description of this field"),
7
- type: field(type: !GraphQL::TypeType, desc: "The return type of this field"),
8
- isDeprecated: field(type: !type.Boolean, property: :deprecated?, desc: "Is this field deprecated?"),
9
- deprecationReason: field(type: type.String, property: :deprecation_reason, desc: "Why this field was deprecated"),
10
- }
1
+ GraphQL::Introspection::FieldType = GraphQL::ObjectType.new do |t, type, field|
2
+ t.name "__Field"
3
+ t.description "Field on a GraphQL type"
4
+ t.fields({
5
+ name: field.build(type: !type.String, desc: "The name for accessing this field"),
6
+ description: field.build(type: !type.String, desc: "The description of this field"),
7
+ type: field.build(type: !GraphQL::Introspection::TypeType, desc: "The return type of this field"),
8
+ isDeprecated: GraphQL::Field.new { |f|
9
+ f.type !type.Boolean
10
+ f.description "Is this field deprecated?"
11
+ f.resolve -> (obj, a, c) { !!obj.deprecation_reason }
12
+ },
13
+ deprecationReason: field.build(type: type.String, property: :deprecation_reason, desc: "Why this field was deprecated"),
14
+ })
11
15
  end
@@ -1,13 +1,13 @@
1
- GraphQL::FieldsField = GraphQL::Field.new do |f|
1
+ GraphQL::Introspection::FieldsField = GraphQL::Field.new do |f, type, field, arg|
2
2
  f.description "List of fields on this object"
3
- f.type -> { GraphQL::ListType.new(of_type: GraphQL::NonNullType.new(of_type: GraphQL::FieldType)) }
3
+ f.type -> { type[!GraphQL::Introspection::FieldType] }
4
4
  f.arguments({
5
- includeDeprecated: {type: GraphQL::BOOLEAN_TYPE, default_value: false}
5
+ includeDeprecated: arg.build({type: GraphQL::BOOLEAN_TYPE, default_value: false})
6
6
  })
7
7
  f.resolve -> (object, arguments, context) {
8
8
  fields = object.fields.values
9
9
  if !arguments["includeDeprecated"]
10
- fields = fields.select {|f| !f.deprecated? }
10
+ fields = fields.select {|f| !f.deprecation_reason }
11
11
  end
12
12
  fields
13
13
  }
@@ -1,9 +1,9 @@
1
- GraphQL::InputFieldsField = GraphQL::Field.new do |f|
1
+ GraphQL::Introspection::InputFieldsField = GraphQL::Field.new do |f, type|
2
2
  f.name "inputFields"
3
3
  f.description "fields on this input object"
4
- f.type GraphQL::ListType.new(of_type: GraphQL::InputValueType)
4
+ f.type type[GraphQL::Introspection::InputValueType]
5
5
  f.resolve -> (target, a, c) {
6
- if target.kind == GraphQL::TypeKinds::INPUT_OBJECT
6
+ if target.kind.input_object?
7
7
  target.input_fields.values
8
8
  else
9
9
  nil
@@ -1,10 +1,10 @@
1
- GraphQL::InputValueType = GraphQL::ObjectType.new do
2
- name "InputValue"
3
- description "An input for a field or InputObject"
4
- fields({
5
- name: field(type: !type.String, desc: "The key for this value"),
6
- description: field(type: type.String, desc: "What this value is used for"),
7
- type: field(type: -> { GraphQL::TypeType }, desc: "The expected type for this value"),
8
- defaultValue: field(type: type.String, property: :default_value, desc: "The value applied if no other value is provided")
1
+ GraphQL::Introspection::InputValueType = GraphQL::ObjectType.new do |t, type, field|
2
+ t.name "InputValue"
3
+ t.description "An input for a field or InputObject"
4
+ t.fields({
5
+ name: field.build(type: !type.String, desc: "The key for this value"),
6
+ description: field.build(type: type.String, desc: "What this value is used for"),
7
+ type: field.build(type: -> { GraphQL::Introspection::TypeType }, desc: "The expected type for this value"),
8
+ defaultValue: field.build(type: type.String, property: :default_value, desc: "The value applied if no other value is provided")
9
9
  })
10
10
  end
@@ -0,0 +1,5 @@
1
+ GraphQL::Introspection::InterfacesField = GraphQL::Field.new do |f, type|
2
+ f.description "Interfaces which this object implements"
3
+ f.type -> { !type[!GraphQL::Introspection::TypeType] }
4
+ f.resolve -> (target, a, c) { target.kind.object? ? target.interfaces : nil }
5
+ end
@@ -1,12 +1,6 @@
1
- GraphQL::OfTypeField = GraphQL::Field.new do |f|
1
+ GraphQL::Introspection::OfTypeField = GraphQL::Field.new do |f|
2
2
  f.name "ofType"
3
3
  f.description "The modified type of this type"
4
- f.type -> { GraphQL::TypeType }
5
- f.resolve -> (obj, args, ctx) {
6
- if [GraphQL::TypeKinds::LIST, GraphQL::TypeKinds::NON_NULL].include?(obj.kind)
7
- obj.of_type
8
- else
9
- nil
10
- end
11
- }
4
+ f.type -> { GraphQL::Introspection::TypeType }
5
+ f.resolve -> (obj, args, ctx) { obj.kind.wraps? ? obj.of_type : nil }
12
6
  end
@@ -1,12 +1,5 @@
1
- GraphQL::PossibleTypesField = GraphQL::Field.new do |f|
2
- POSSIBLE_TYPE_KINDS = [GraphQL::TypeKinds::UNION, GraphQL::TypeKinds::INTERFACE]
1
+ GraphQL::Introspection::PossibleTypesField = GraphQL::Field.new do |f, type|
3
2
  f.description "Types which compose this Union or Interface"
4
- f.type -> { GraphQL::ListType.new(of_type: GraphQL::TypeType) }
5
- f.resolve -> (target, a, c) {
6
- if POSSIBLE_TYPE_KINDS.include?(target.kind)
7
- target.possible_types
8
- else
9
- nil
10
- end
11
- }
3
+ f.type -> { type[GraphQL::Introspection::TypeType] }
4
+ f.resolve -> (target, a, c) { target.kind.resolves? ? target.possible_types : nil }
12
5
  end
@@ -1,32 +1,26 @@
1
- GraphQL::SchemaType = GraphQL::ObjectType.new do
2
- name "__Schema"
3
- description "A GraphQL schema"
4
- fields({
1
+ GraphQL::Introspection::SchemaType = GraphQL::ObjectType.new do |t, type|
2
+ t.name "__Schema"
3
+ t.description "A GraphQL schema"
4
+ t.fields({
5
5
  types: GraphQL::Field.new { |f|
6
- f.type !type[!GraphQL::TypeType]
6
+ f.type !type[!GraphQL::Introspection::TypeType]
7
7
  f.description "Types in this schema"
8
8
  f.resolve -> (obj, arg, ctx) { obj.types.values }
9
9
  },
10
10
  directives: GraphQL::Field.new { |f|
11
- f.type !type[!GraphQL::DirectiveType]
11
+ f.type !type[!GraphQL::Introspection::DirectiveType]
12
12
  f.description "Directives in this schema"
13
13
  f.resolve -> (obj, arg, ctx) { obj.directives.values }
14
14
  },
15
15
  queryType: GraphQL::Field.new { |f|
16
- f.type !GraphQL::TypeType
16
+ f.type !GraphQL::Introspection::TypeType
17
17
  f.description "The query root of this schema"
18
18
  f.resolve -> (obj, arg, ctx) { obj.query }
19
19
  },
20
20
  mutationType: GraphQL::Field.new { |f|
21
- f.type GraphQL::TypeType
21
+ f.type GraphQL::Introspection::TypeType
22
22
  f.description "The mutation root of this schema"
23
23
  f.resolve -> (obj, arg, ctx) { obj.mutation }
24
24
  },
25
25
  })
26
26
  end
27
- # type __Schema {
28
- # types: [__Type!]!
29
- # queryType: __Type!
30
- # mutationType: __Type
31
- # directives: [__Directive!]!
32
- # }
@@ -1,4 +1,4 @@
1
- GraphQL::TypeKindEnum = GraphQL::Enum.new do |e|
1
+ GraphQL::Introspection::TypeKindEnum = GraphQL::Enum.new do |e|
2
2
  e.name "__TypeKind"
3
3
  e.description "The kinds of types in this GraphQL system"
4
4
  GraphQL::TypeKinds::KIND_NAMES.each do |kind_name|
@@ -1,22 +1,20 @@
1
- GraphQL::TypeType = GraphQL::ObjectType.new do
2
- name "__Type"
3
- description "A type in the GraphQL schema"
1
+ GraphQL::Introspection::TypeType = GraphQL::ObjectType.new do |t, type, field|
2
+ t.name "__Type"
3
+ t.description "A type in the GraphQL schema"
4
4
 
5
- self.fields = {
6
- name: field(type: !type.String, desc: "The name of this type"),
7
- kind: field(type: GraphQL::TypeKindEnum, desc: "The kind of this type"),
8
- description: field(type: type.String, desc: "The description for this type"),
9
- fields: GraphQL::FieldsField,
10
- ofType: GraphQL::OfTypeField,
11
- inputFields: GraphQL::InputFieldsField,
12
- possibleTypes: GraphQL::PossibleTypesField,
13
- enumValues: GraphQL::EnumValuesField
5
+ t.fields = {
6
+ name: field.build(type: !type.String, desc: "The name of this type"),
7
+ kind: GraphQL::Field.new { |f|
8
+ f.type GraphQL::Introspection::TypeKindEnum
9
+ f.description "The kind of this type"
10
+ f.resolve -> (target, a, c) { target.kind.name }
11
+ },
12
+ description: field.build(type: type.String, desc: "The description for this type"),
13
+ fields: GraphQL::Introspection::FieldsField,
14
+ ofType: GraphQL::Introspection::OfTypeField,
15
+ inputFields: GraphQL::Introspection::InputFieldsField,
16
+ possibleTypes: GraphQL::Introspection::PossibleTypesField,
17
+ enumValues: GraphQL::Introspection::EnumValuesField,
18
+ interfaces: GraphQL::Introspection::InterfacesField,
14
19
  }
15
20
  end
16
- # type __Type {
17
- # # OBJECT only
18
- # interfaces: [__Type!]
19
- #
20
- # # ENUM only
21
- # enumValues(includeDeprecated: Boolean = false): [__EnumValue!]
22
- # }