graphql 0.4.0 → 0.5.0

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 (42) hide show
  1. checksums.yaml +4 -4
  2. data/lib/graph_ql/argument.rb +38 -4
  3. data/lib/graph_ql/boolean_type.rb +3 -5
  4. data/lib/graph_ql/definition_helpers.rb +1 -0
  5. data/lib/graph_ql/definition_helpers/defined_by_config.rb +20 -0
  6. data/lib/graph_ql/enum_type.rb +52 -16
  7. data/lib/graph_ql/field.rb +79 -14
  8. data/lib/graph_ql/float_type.rb +3 -3
  9. data/lib/graph_ql/id_type.rb +3 -5
  10. data/lib/graph_ql/input_object_type.rb +41 -4
  11. data/lib/graph_ql/int_type.rb +3 -5
  12. data/lib/graph_ql/interface_type.rb +36 -8
  13. data/lib/graph_ql/introspection/arguments_field.rb +4 -4
  14. data/lib/graph_ql/introspection/directive_type.rb +9 -11
  15. data/lib/graph_ql/introspection/enum_value_type.rb +9 -12
  16. data/lib/graph_ql/introspection/enum_values_field.rb +6 -8
  17. data/lib/graph_ql/introspection/field_type.rb +11 -15
  18. data/lib/graph_ql/introspection/fields_field.rb +5 -7
  19. data/lib/graph_ql/introspection/input_fields_field.rb +5 -5
  20. data/lib/graph_ql/introspection/input_value_type.rb +7 -9
  21. data/lib/graph_ql/introspection/interfaces_field.rb +4 -4
  22. data/lib/graph_ql/introspection/of_type_field.rb +5 -5
  23. data/lib/graph_ql/introspection/possible_types_field.rb +4 -4
  24. data/lib/graph_ql/introspection/schema_field.rb +6 -8
  25. data/lib/graph_ql/introspection/schema_type.rb +19 -25
  26. data/lib/graph_ql/introspection/type_by_name_field.rb +7 -1
  27. data/lib/graph_ql/introspection/type_kind_enum.rb +4 -4
  28. data/lib/graph_ql/introspection/type_type.rb +18 -18
  29. data/lib/graph_ql/introspection/typename_field.rb +6 -10
  30. data/lib/graph_ql/object_type.rb +87 -12
  31. data/lib/graph_ql/scalar_type.rb +22 -0
  32. data/lib/graph_ql/schema.rb +1 -1
  33. data/lib/graph_ql/string_type.rb +3 -5
  34. data/lib/graph_ql/union_type.rb +24 -3
  35. data/lib/graph_ql/version.rb +1 -1
  36. data/lib/graphql.rb +1 -1
  37. data/readme.md +66 -64
  38. data/spec/graph_ql/field_spec.rb +3 -3
  39. data/spec/support/dairy_app.rb +119 -133
  40. data/spec/support/dairy_data.rb +1 -1
  41. data/spec/support/star_wars_schema.rb +50 -57
  42. metadata +3 -2
@@ -1,5 +1,5 @@
1
- GraphQL::Introspection::ArgumentsField = GraphQL::Field.new do |f|
2
- f.description "Arguments allowed to this object"
3
- f.type GraphQL::ListType.new(of_type: GraphQL::Introspection::InputValueType)
4
- f.resolve -> (target, a, c) { target.arguments.values }
1
+ GraphQL::Introspection::ArgumentsField = GraphQL::Field.define do
2
+ description "Arguments allowed to this object"
3
+ type GraphQL::ListType.new(of_type: GraphQL::Introspection::InputValueType)
4
+ resolve -> (target, a, c) { target.arguments.values }
5
5
  end
@@ -1,12 +1,10 @@
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
- })
1
+ GraphQL::Introspection::DirectiveType = GraphQL::ObjectType.define do
2
+ name "__Directive"
3
+ description "A query directive in this schema"
4
+ field :name, !types.String, "The name of this directive"
5
+ field :description, types.String, "The description for this type"
6
+ field :args, field: GraphQL::Introspection::ArgumentsField
7
+ field :onOperation, !types.Boolean, "Does this directive apply to operations?", property: :on_operation?
8
+ field :onFragment, !types.Boolean, "Does this directive apply to fragments?", property: :on_fragment?
9
+ field :onField, !types.Boolean, "Does this directive apply to fields?", property: :on_field?
12
10
  end
@@ -1,13 +1,10 @@
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
- },
12
- })
1
+ GraphQL::Introspection::EnumValueType = GraphQL::ObjectType.define do
2
+ name "__EnumValue"
3
+ description "A possible value for an Enum"
4
+ field :name, !types.String
5
+ field :description, types.String
6
+ field :deprecationReason, types.String, property: :deprecation_reason
7
+ field :isDeprecated, !types.Boolean do
8
+ resolve -> (obj, a, c) { !!obj.deprecation_reason }
9
+ end
13
10
  end
@@ -1,15 +1,13 @@
1
- GraphQL::Introspection::EnumValuesField = GraphQL::Field.new do |f, type, field, arg|
2
- f.description "Values for this enum"
3
- f.type type[!GraphQL::Introspection::EnumValueType]
4
- f.arguments({
5
- includeDeprecated: arg.build({type: GraphQL::BOOLEAN_TYPE, default_value: false})
6
- })
7
- f.resolve -> (object, arguments, context) {
1
+ GraphQL::Introspection::EnumValuesField = GraphQL::Field.define do
2
+ description "Values for this enum"
3
+ type types[!GraphQL::Introspection::EnumValueType]
4
+ argument :includeDeprecated, types.Boolean, default_value: false
5
+ resolve -> (object, arguments, context) do
8
6
  return nil if !object.kind.enum?
9
7
  fields = object.values.values
10
8
  if !arguments["includeDeprecated"]
11
9
  fields = fields.select {|f| !f.deprecation_reason }
12
10
  end
13
11
  fields
14
- }
12
+ end
15
13
  end
@@ -1,16 +1,12 @@
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
- args: GraphQL::Introspection::ArgumentsField,
14
- deprecationReason: field.build(type: type.String, property: :deprecation_reason, desc: "Why this field was deprecated"),
15
- })
1
+ GraphQL::Introspection::FieldType = GraphQL::ObjectType.define do
2
+ name "__Field"
3
+ description "Field on a GraphQL type"
4
+ field :name, !types.String, "The name for accessing this field"
5
+ field :description, !types.String, "The description of this field"
6
+ field :type, !GraphQL::Introspection::TypeType, "The return type of this field"
7
+ field :isDeprecated, !types.Boolean, "Is this field deprecated?" do
8
+ resolve -> (obj, a, c) { !!obj.deprecation_reason }
9
+ end
10
+ field :args, field: GraphQL::Introspection::ArgumentsField
11
+ field :deprecationReason, types.String, "Why this field was deprecated", property: :deprecation_reason
16
12
  end
@@ -1,10 +1,8 @@
1
- GraphQL::Introspection::FieldsField = GraphQL::Field.new do |f, type, field, arg|
2
- f.description "List of fields on this object"
3
- f.type -> { type[!GraphQL::Introspection::FieldType] }
4
- f.arguments({
5
- includeDeprecated: arg.build({type: GraphQL::BOOLEAN_TYPE, default_value: false})
6
- })
7
- f.resolve -> (object, arguments, context) {
1
+ GraphQL::Introspection::FieldsField = GraphQL::Field.define do
2
+ description "List of fields on this object"
3
+ type -> { types[!GraphQL::Introspection::FieldType] }
4
+ argument :includeDeprecated, GraphQL::BOOLEAN_TYPE, default_value: false
5
+ resolve -> (object, arguments, context) {
8
6
  return nil if !object.kind.fields?
9
7
  fields = object.fields.values
10
8
  if !arguments["includeDeprecated"]
@@ -1,8 +1,8 @@
1
- GraphQL::Introspection::InputFieldsField = GraphQL::Field.new do |f, type|
2
- f.name "inputFields"
3
- f.description "fields on this input object"
4
- f.type type[GraphQL::Introspection::InputValueType]
5
- f.resolve -> (target, a, c) {
1
+ GraphQL::Introspection::InputFieldsField = GraphQL::Field.define do
2
+ name "inputFields"
3
+ description "fields on this input object"
4
+ type types[GraphQL::Introspection::InputValueType]
5
+ resolve -> (target, a, c) {
6
6
  if target.kind.input_object?
7
7
  target.input_fields.values
8
8
  else
@@ -1,10 +1,8 @@
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
- })
1
+ GraphQL::Introspection::InputValueType = GraphQL::ObjectType.define do
2
+ name "__InputValue"
3
+ description "An input for a field or InputObject"
4
+ field :name, !types.String, "The key for this value"
5
+ field :description, types.String, "What this value is used for"
6
+ field :type, -> { GraphQL::Introspection::TypeType }, "The expected type for this value"
7
+ field :defaultValue, types.String, "The value applied if no other value is provided", property: :default_value
10
8
  end
@@ -1,5 +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 }
1
+ GraphQL::Introspection::InterfacesField = GraphQL::Field.define do
2
+ description "Interfaces which this object implements"
3
+ type -> { !types[!GraphQL::Introspection::TypeType] }
4
+ resolve -> (target, a, c) { target.kind.object? ? target.interfaces : nil }
5
5
  end
@@ -1,6 +1,6 @@
1
- GraphQL::Introspection::OfTypeField = GraphQL::Field.new do |f|
2
- f.name "ofType"
3
- f.description "The modified type of this type"
4
- f.type -> { GraphQL::Introspection::TypeType }
5
- f.resolve -> (obj, args, ctx) { obj.kind.wraps? ? obj.of_type : nil }
1
+ GraphQL::Introspection::OfTypeField = GraphQL::Field.define do
2
+ name "ofType"
3
+ description "The modified type of this type"
4
+ type -> { GraphQL::Introspection::TypeType }
5
+ resolve -> (obj, args, ctx) { obj.kind.wraps? ? obj.of_type : nil }
6
6
  end
@@ -1,5 +1,5 @@
1
- GraphQL::Introspection::PossibleTypesField = GraphQL::Field.new do |f, type|
2
- f.description "Types which compose this Union or Interface"
3
- f.type -> { type[GraphQL::Introspection::TypeType] }
4
- f.resolve -> (target, a, c) { target.kind.resolves? ? target.possible_types : nil }
1
+ GraphQL::Introspection::PossibleTypesField = GraphQL::Field.define do
2
+ description "Types which compose this Union or Interface"
3
+ type -> { types[GraphQL::Introspection::TypeType] }
4
+ resolve -> (target, a, c) { target.kind.resolves? ? target.possible_types : nil }
5
5
  end
@@ -1,13 +1,11 @@
1
1
  # A wrapper to implement `__schema`
2
2
  class GraphQL::Introspection::SchemaField
3
- DEFINITION = Proc.new { |f, wrapped_type|
4
- f.name("__schema")
5
- f.description("This GraphQL schema")
6
- f.type(!GraphQL::Introspection::SchemaType)
7
- f.resolve -> (o, a, c) { wrapped_type }
8
- }
9
-
10
3
  def self.create(wrapped_type)
11
- GraphQL::Field.new { |f| DEFINITION.call(f, wrapped_type) }
4
+ GraphQL::Field.define do
5
+ name("__schema")
6
+ description("This GraphQL schema")
7
+ type(!GraphQL::Introspection::SchemaType)
8
+ resolve -> (o, a, c) { wrapped_type }
9
+ end
12
10
  end
13
11
  end
@@ -1,26 +1,20 @@
1
- GraphQL::Introspection::SchemaType = GraphQL::ObjectType.new do |t, type|
2
- t.name "__Schema"
3
- t.description "A GraphQL schema"
4
- t.fields({
5
- types: GraphQL::Field.new { |f|
6
- f.type !type[!GraphQL::Introspection::TypeType]
7
- f.description "Types in this schema"
8
- f.resolve -> (obj, arg, ctx) { obj.types.values }
9
- },
10
- directives: GraphQL::Field.new { |f|
11
- f.type !type[!GraphQL::Introspection::DirectiveType]
12
- f.description "Directives in this schema"
13
- f.resolve -> (obj, arg, ctx) { obj.directives.values }
14
- },
15
- queryType: GraphQL::Field.new { |f|
16
- f.type !GraphQL::Introspection::TypeType
17
- f.description "The query root of this schema"
18
- f.resolve -> (obj, arg, ctx) { obj.query }
19
- },
20
- mutationType: GraphQL::Field.new { |f|
21
- f.type GraphQL::Introspection::TypeType
22
- f.description "The mutation root of this schema"
23
- f.resolve -> (obj, arg, ctx) { obj.mutation }
24
- },
25
- })
1
+ GraphQL::Introspection::SchemaType = GraphQL::ObjectType.define do
2
+ name "__Schema"
3
+ description "A GraphQL schema"
4
+
5
+ field :types, !types[!GraphQL::Introspection::TypeType], "Types in this schema" do
6
+ resolve -> (obj, arg, ctx) { obj.types.values }
7
+ end
8
+
9
+ field :directives, !types[!GraphQL::Introspection::DirectiveType], "Directives in this schema" do
10
+ resolve -> (obj, arg, ctx) { obj.directives.values }
11
+ end
12
+
13
+ field :queryType, !GraphQL::Introspection::TypeType, "The query root of this schema" do
14
+ resolve -> (obj, arg, ctx) { obj.query }
15
+ end
16
+
17
+ field :mutationType, GraphQL::Introspection::TypeType, "The mutation root of this schema" do
18
+ resolve -> (obj, arg, ctx) { obj.mutation }
19
+ end
26
20
  end
@@ -9,6 +9,12 @@ class GraphQL::Introspection::TypeByNameField
9
9
  }
10
10
 
11
11
  def self.create(type_hash)
12
- GraphQL::Field.new { |f, type, field, arg| DEFINITION.call(f, type, field, arg, type_hash) }
12
+ GraphQL::Field.define do
13
+ name("__type")
14
+ description("A type in the GraphQL system")
15
+ type(!GraphQL::Introspection::TypeType)
16
+ argument :name, !types.String
17
+ resolve -> (o, args, c) { type_hash[args["name"]] }
18
+ end
13
19
  end
14
20
  end
@@ -1,7 +1,7 @@
1
- GraphQL::Introspection::TypeKindEnum = GraphQL::EnumType.new do |e|
2
- e.name "__TypeKind"
3
- e.description "The kinds of types in this GraphQL system"
1
+ GraphQL::Introspection::TypeKindEnum = GraphQL::EnumType.define do
2
+ name "__TypeKind"
3
+ description "The kinds of types in this GraphQL system"
4
4
  GraphQL::TypeKinds::KIND_NAMES.each do |kind_name|
5
- e.value(kind_name)
5
+ value(kind_name)
6
6
  end
7
7
  end
@@ -1,20 +1,20 @@
1
- GraphQL::Introspection::TypeType = GraphQL::ObjectType.new do |t, type, field|
2
- t.name "__Type"
3
- t.description "A type in the GraphQL schema"
1
+ GraphQL::Introspection::TypeType = GraphQL::ObjectType.define do
2
+ name "__Type"
3
+ description "A type in the GraphQL schema"
4
4
 
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,
19
- }
5
+ field :name, !types.String, "The name of this type"
6
+ field :description, types.String, "What this type represents"
7
+
8
+ field :kind do
9
+ type GraphQL::Introspection::TypeKindEnum
10
+ description "The kind of this type"
11
+ resolve -> (target, a, c) { target.kind.name }
12
+ end
13
+
14
+ field :fields, field: GraphQL::Introspection::FieldsField
15
+ field :ofType, field: GraphQL::Introspection::OfTypeField
16
+ field :inputFields, field: GraphQL::Introspection::InputFieldsField
17
+ field :possibleTypes, field: GraphQL::Introspection::PossibleTypesField
18
+ field :enumValues, field: GraphQL::Introspection::EnumValuesField
19
+ field :interfaces, field: GraphQL::Introspection::InterfacesField
20
20
  end
@@ -1,15 +1,11 @@
1
1
  # A wrapper to create `__typename`.
2
- # Uses `.create` because I couldn't figure out how to
3
- # pass `DEFINITION` via `super` (then I could extend GraphQL::Field)
4
2
  class GraphQL::Introspection::TypenameField
5
- DEFINITION = Proc.new { |f, wrapped_type|
6
- f.name "__typename"
7
- f.description "The name of this type"
8
- f.type -> { !GraphQL::STRING_TYPE }
9
- f.resolve -> (obj, a, c) { wrapped_type.name }
10
- }
11
-
12
3
  def self.create(wrapped_type)
13
- GraphQL::Field.new { |f| DEFINITION.call(f, wrapped_type) }
4
+ GraphQL::Field.define do
5
+ name "__typename"
6
+ description "The name of this type"
7
+ type -> { !GraphQL::STRING_TYPE }
8
+ resolve -> (obj, a, c) { wrapped_type.name }
9
+ end
14
10
  end
15
11
  end
@@ -1,23 +1,92 @@
1
1
  # This type exposes fields on an object.
2
2
  #
3
+ # @example defining a type for your IMDB clone
4
+ # MovieType = GraphQL::ObjectType.define do
5
+ # name "Movie"
6
+ # description "A full-length film or a short film"
7
+ # interfaces [ProductionInterface, DurationInterface]
8
+ #
9
+ # field :runtimeMinutes, !types.Int, property: :runtime_minutes
10
+ # field :director, PersonType
11
+ # field :cast, CastType
12
+ # field :starring, types[PersonType] do
13
+ # arguments :limit, types.Int
14
+ # resolve -> (object, args, ctx) {
15
+ # stars = object.cast.stars
16
+ # args[:limit] && stars = stars.limit(args[:limit])
17
+ # stars
18
+ # }
19
+ # end
20
+ # end
3
21
  #
4
22
  class GraphQL::ObjectType
5
23
  include GraphQL::DefinitionHelpers::NonNullWithBang
6
24
  extend GraphQL::DefinitionHelpers::Definable
25
+ include GraphQL::DefinitionHelpers::DefinedByConfig
7
26
  attr_definable :name, :description, :interfaces, :fields
8
27
 
28
+ class DefinitionConfig
29
+ extend GraphQL::DefinitionHelpers::Definable
30
+ attr_definable :name, :description, :interfaces
31
+ def initialize
32
+ @interfaces = []
33
+ @fields = {}
34
+ end
35
+
36
+ def types
37
+ GraphQL::DefinitionHelpers::TypeDefiner.instance
38
+ end
39
+
40
+ def field(name_or_pair, type = nil, desc = nil, field: nil, property: nil, &block)
41
+ if name_or_pair.is_a?(Hash)
42
+ name = name_or_pair.keys.first
43
+ value = name_or_pair[name]
44
+ if value.is_a?(GraphQL::Field)
45
+ field = value
46
+ else
47
+ property = value
48
+ end
49
+ else
50
+ name = name_or_pair
51
+ end
52
+ field ||= GraphQL::Field.define(&block)
53
+ type && field.type = type
54
+ desc && field.description = desc
55
+ property && field.resolve = -> (t,a,c) { t.public_send(property)}
56
+ field.name ||= name.to_s
57
+ @fields[name.to_s] = field
58
+ end
59
+
60
+ def type_class
61
+ GraphQL::ObjectType
62
+ end
63
+
64
+ def to_instance
65
+ object = type_class.new
66
+ object.name = name
67
+ object.description = description
68
+ object.fields = @fields
69
+ object.interfaces = interfaces
70
+ object
71
+ end
72
+ end
73
+
9
74
  def initialize(&block)
10
- self.fields = []
75
+ self.fields = {}
11
76
  self.interfaces = []
12
- yield(
13
- self,
14
- GraphQL::DefinitionHelpers::TypeDefiner.instance,
15
- GraphQL::DefinitionHelpers::FieldDefiner.instance,
16
- GraphQL::DefinitionHelpers::ArgumentDefiner.instance
17
- )
77
+ if block_given?
78
+ yield(
79
+ self,
80
+ GraphQL::DefinitionHelpers::TypeDefiner.instance,
81
+ GraphQL::DefinitionHelpers::FieldDefiner.instance,
82
+ GraphQL::DefinitionHelpers::ArgumentDefiner.instance
83
+ )
84
+ warn("Initializing with .new is deprecated, use .define instead! (see #{self})")
85
+ end
18
86
  end
19
87
 
20
88
  # @overload fields(new_fields)
89
+ # @deprecated use {.define} API instead
21
90
  # Define `new_fields` as the fields this type exposes, uses {#fields=}
22
91
  #
23
92
  # @overload fields()
@@ -37,10 +106,8 @@ class GraphQL::ObjectType
37
106
  end
38
107
 
39
108
  # @overload interfaces(new_interfaces)
109
+ # @deprecated use {.define} API instead
40
110
  # Declare that this type implements `new_interfaces`.
41
- # Shovel this type into each interface's `possible_types` array.
42
- #
43
- # (There's a bug here: if you define interfaces twice, it won't remove previous definitions.)
44
111
  #
45
112
  # @param new_interfaces [Array<GraphQL::Interface>] interfaces that this type implements
46
113
  #
@@ -49,12 +116,20 @@ class GraphQL::ObjectType
49
116
  #
50
117
  def interfaces(new_interfaces=nil)
51
118
  if !new_interfaces.nil?
52
- @interfaces = new_interfaces
53
- new_interfaces.each {|i| i.possible_types << self }
119
+ self.interfaces = new_interfaces
54
120
  end
55
121
  @interfaces
56
122
  end
57
123
 
124
+ # Shovel this type into each interface's `possible_types` array.
125
+ #
126
+ # (There's a bug here: if you define interfaces twice, it won't remove previous definitions.)
127
+ # @param new_interfaces [Array<GraphQL::Interface>] interfaces that this type implements
128
+ def interfaces=(new_interfaces)
129
+ new_interfaces.each {|i| i.possible_types << self }
130
+ @interfaces = new_interfaces
131
+ end
132
+
58
133
  def kind
59
134
  GraphQL::TypeKinds::OBJECT
60
135
  end