graphql 0.15.1 → 0.15.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9d6f90d46a8163e9eff31701c295fc86de974f83
4
- data.tar.gz: 4743996397fb5468ac91b4fffe3d914efd45de6c
3
+ metadata.gz: 06deb0560626e16a3df052a56924a3f541baed38
4
+ data.tar.gz: 2f8d1ffaca328783f129f9c9c031c5794cd629da
5
5
  SHA512:
6
- metadata.gz: e8b722f7490e1bfed0a98dd48d0a09383d2e8358c89ed79b183bf857410bb2a241f610db225b9232cc4b8eca4ac61c4a7197627b5040f4c8448187ea8fd3d715
7
- data.tar.gz: c207a187145c6d681669b2244f89e5c4b637b45c25c4e8d6bb3ebb8adab198b32d1df4728143880304e04d962ef63d08d40605d6691a524a4863adce150fddbf
6
+ metadata.gz: c221077dd7e949a7e021d941f70fb6f7424c3f563ad0c3abdb1473bf94089fb93949ca324bc20d610a3217e18cc8c9e2b4b9dc21e4b490a7b7363de60d7c4d48
7
+ data.tar.gz: a8b0880ef7498bc53168ba8864857c877d151825aeccfd50e07e1f58ad299c558a8bbda9b0ee0496ec35de274ac301fceef69996b1d99466c568358ef82ac53b
@@ -88,5 +88,21 @@ module GraphQL
88
88
  return nil if value.nil?
89
89
  coerce_non_null_input(value)
90
90
  end
91
+
92
+ # During schema definition, types can be defined inside procs or as strings.
93
+ # This function converts it to a type instance
94
+ # @return [GraphQL::BaseType]
95
+ def self.resolve_related_type(type_arg)
96
+ case type_arg
97
+ when Proc
98
+ # lazy-eval it
99
+ type_arg.call
100
+ when String
101
+ # Get a constant by this name
102
+ Object.const_get(type_arg)
103
+ else
104
+ type_arg
105
+ end
106
+ end
91
107
  end
92
108
  end
data/lib/graphql/field.rb CHANGED
@@ -42,7 +42,7 @@ module GraphQL
42
42
  include GraphQL::Define::InstanceDefinable
43
43
  accepts_definitions :name, :description, :resolve, :type, :property, :deprecation_reason, argument: GraphQL::Define::AssignArgument
44
44
 
45
- attr_accessor :deprecation_reason, :name, :description, :type, :property
45
+ attr_accessor :deprecation_reason, :name, :description, :property
46
46
  attr_reader :resolve_proc
47
47
 
48
48
  # @return [String] The name of this field on its {GraphQL::ObjectType} (or {GraphQL::InterfaceType})
@@ -71,18 +71,14 @@ module GraphQL
71
71
  @resolve_proc = resolve_proc || build_default_resolver
72
72
  end
73
73
 
74
+ def type=(new_return_type)
75
+ @clean_type = nil
76
+ @dirty_type = new_return_type
77
+ end
78
+
74
79
  # Get the return type for this field.
75
80
  def type
76
- case @type
77
- when Proc
78
- # lazy-eval it
79
- @type = @type.call
80
- when String
81
- # Get a constant by this name
82
- @type = Object.const_get(@type)
83
- else
84
- @type
85
- end
81
+ @clean_type ||= GraphQL::BaseType.resolve_related_type(@dirty_type)
86
82
  end
87
83
 
88
84
  # You can only set a field's name _once_ -- this to prevent
@@ -22,19 +22,28 @@ module GraphQL
22
22
  #
23
23
  class ObjectType < GraphQL::BaseType
24
24
  accepts_definitions :interfaces, field: GraphQL::Define::AssignObjectField
25
- attr_accessor :name, :description, :interfaces
25
+ attr_accessor :name, :description
26
26
 
27
27
  # @return [Hash<String, GraphQL::Field>] Map String fieldnames to their {GraphQL::Field} implementations
28
28
  attr_accessor :fields
29
29
 
30
30
  def initialize
31
31
  @fields = {}
32
- @interfaces = []
32
+ @dirty_interfaces = []
33
33
  end
34
34
 
35
35
  # @param new_interfaces [Array<GraphQL::Interface>] interfaces that this type implements
36
36
  def interfaces=(new_interfaces)
37
- @interfaces = new_interfaces
37
+ @clean_interfaces = nil
38
+ @dirty_interfaces = new_interfaces
39
+ end
40
+
41
+ def interfaces
42
+ @clean_interfaces ||= begin
43
+ @dirty_interfaces.map { |i_type| GraphQL::BaseType.resolve_related_type(i_type) }
44
+ rescue
45
+ @dirty_interfaces
46
+ end
38
47
  end
39
48
 
40
49
  def kind
@@ -90,7 +90,7 @@ module GraphQL
90
90
  FIELDS_ARE_VALID = Rules.assert_named_items_are_valid("field", -> (type) { type.all_fields })
91
91
 
92
92
  HAS_ONE_OR_MORE_POSSIBLE_TYPES = -> (type) {
93
- type.possible_types.length > 1 ? nil : "must have at least one possible type"
93
+ type.possible_types.length >= 1 ? nil : "must have at least one possible type"
94
94
  }
95
95
 
96
96
  NAME_IS_STRING = Rules.assert_property(:name, String)
@@ -11,7 +11,7 @@ module GraphQL
11
11
  #
12
12
  class UnionType < GraphQL::BaseType
13
13
  include GraphQL::BaseType::HasPossibleTypes
14
- attr_accessor :name, :description, :possible_types
14
+ attr_accessor :name, :description
15
15
  accepts_definitions :possible_types, :resolve_type
16
16
 
17
17
  def kind
@@ -21,5 +21,18 @@ module GraphQL
21
21
  def include?(child_type_defn)
22
22
  possible_types.include?(child_type_defn)
23
23
  end
24
+
25
+ def possible_types=(new_possible_types)
26
+ @clean_possible_types = nil
27
+ @dirty_possible_types = new_possible_types
28
+ end
29
+
30
+ def possible_types
31
+ @clean_possible_types ||= begin
32
+ @dirty_possible_types.map { |type| GraphQL::BaseType.resolve_related_type(type) }
33
+ rescue
34
+ @dirty_possible_types
35
+ end
36
+ end
24
37
  end
25
38
  end
@@ -1,3 +1,3 @@
1
1
  module GraphQL
2
- VERSION = "0.15.1"
2
+ VERSION = "0.15.2"
3
3
  end
data/readme.md CHANGED
@@ -124,6 +124,7 @@ If you're building a backend for [Relay](http://facebook.github.io/relay/), you'
124
124
  - Add a complexity validator (reject queries if they're too big)
125
125
  - Add docs for shared behaviors & DRY code
126
126
  - Proper error on unknown directive
127
+ - Non-nulls should _propagate_ to the next non-null field (all the way up to data, if need be)
127
128
  - __Subscriptions__
128
129
  - This is a good chance to make an `Operation` abstraction of which `query`, `mutation` and `subscription` are members
129
130
  - For a subscription, `graphql` would send an outbound message to the system (allow the host application to manage its own subscriptions via Pusher, ActionCable, whatever)
@@ -83,7 +83,7 @@ describe GraphQL::Schema::Validation do
83
83
  let(:invalid_interfaces_object) {
84
84
  GraphQL::ObjectType.define do
85
85
  name "InvalidInterfaces"
86
- interfaces({a: 1})
86
+ interfaces(55)
87
87
  end
88
88
  }
89
89
  let(:invalid_interface_member_object) {
@@ -101,7 +101,7 @@ describe GraphQL::Schema::Validation do
101
101
  }
102
102
 
103
103
  it "requires an Array for interfaces" do
104
- assert_error_includes invalid_interfaces_object, "must be an Array of GraphQL::InterfaceType, not a Hash"
104
+ assert_error_includes invalid_interfaces_object, "must be an Array of GraphQL::InterfaceType, not a Fixnum"
105
105
  assert_error_includes invalid_interface_member_object, "must contain GraphQL::InterfaceType, not Symbol"
106
106
  end
107
107
 
@@ -27,7 +27,7 @@ end
27
27
  CheeseType = GraphQL::ObjectType.define do
28
28
  name "Cheese"
29
29
  description "Cultured dairy product"
30
- interfaces [EdibleInterface, AnimalProductInterface]
30
+ interfaces ["EdibleInterface", -> { AnimalProductInterface }]
31
31
 
32
32
  # Can have (name, type, desc)
33
33
  field :id, !types.Int, "Unique identifier"
@@ -107,7 +107,7 @@ end
107
107
  DairyProductUnion = GraphQL::UnionType.define do
108
108
  name "DairyProduct"
109
109
  description "Kinds of food made from milk"
110
- possible_types [MilkType, CheeseType]
110
+ possible_types ["MilkType", -> { CheeseType }]
111
111
  end
112
112
 
113
113
  CowType = GraphQL::ObjectType.define do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: graphql
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.15.1
4
+ version: 0.15.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Mosolgo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-15 00:00:00.000000000 Z
11
+ date: 2016-06-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: codeclimate-test-reporter