graphql 0.10.8 → 0.10.9
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 +4 -4
- data/lib/graphql/object_type.rb +3 -2
- data/lib/graphql/query/serial_execution/selection_resolution.rb +1 -1
- data/lib/graphql/version.rb +1 -1
- data/readme.md +0 -12
- data/spec/graphql/interface_type_spec.rb +32 -0
- data/spec/graphql/introspection/type_type_spec.rb +2 -0
- data/spec/spec_helper.rb +2 -0
- data/spec/support/dairy_app.rb +3 -0
- data/spec/support/dairy_data.rb +6 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f073abd68886cc4042f66cff4457c9adcae153f7
|
4
|
+
data.tar.gz: 895ea36770f92665af805b9181c8641fb5614567
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ce609e9c9523281b908378697e48344ffdc4e8c0597b69b30ddcea15f51468fa971805e4346f6aad5c36536f760bfefccd6449abcaf1825e80f925af149682c1
|
7
|
+
data.tar.gz: 78611caafff37f1b1a142aa74af6eadac62b5cfdd35c0099f5afda063a95142ed1d036004e6eb7d2904762459b2c38cb97e36944af2b636f33fe7ef8ef15e69d
|
data/lib/graphql/object_type.rb
CHANGED
@@ -31,10 +31,11 @@ class GraphQL::ObjectType < GraphQL::BaseType
|
|
31
31
|
|
32
32
|
# Shovel this type into each interface's `possible_types` array.
|
33
33
|
#
|
34
|
-
# (There's a bug here: if you define interfaces twice, it won't remove previous definitions.)
|
35
34
|
# @param new_interfaces [Array<GraphQL::Interface>] interfaces that this type implements
|
36
35
|
def interfaces=(new_interfaces)
|
37
|
-
|
36
|
+
@interfaces ||= []
|
37
|
+
(@interfaces - new_interfaces).each { |i| i.possible_types.delete(self) }
|
38
|
+
(new_interfaces - @interfaces).each { |i| i.possible_types << self }
|
38
39
|
@interfaces = new_interfaces
|
39
40
|
end
|
40
41
|
|
@@ -88,7 +88,7 @@ module GraphQL
|
|
88
88
|
def merge_fields(field1, field2)
|
89
89
|
field_type = query.schema.get_field(type, field2.name).type.unwrap
|
90
90
|
|
91
|
-
if field_type.
|
91
|
+
if field_type.kind.fields?
|
92
92
|
# create a new ast field node merging selections from each field.
|
93
93
|
# Because of static validation, we can assume that name, alias,
|
94
94
|
# arguments, and directives are exactly the same for fields 1 and 2.
|
data/lib/graphql/version.rb
CHANGED
data/readme.md
CHANGED
@@ -112,17 +112,6 @@ https://medium.com/@gauravtiwari/graphql-and-relay-on-rails-first-relay-powered-
|
|
112
112
|
- Code clean-up
|
113
113
|
- Raise if you try to configure an attribute which doesn't suit the type (ie, if you try to define `resolve` on an ObjectType, it should somehow raise)
|
114
114
|
- Clean up file structure in `lib/query` (don't need serial_execution namespace anymore)
|
115
|
-
- Overriding `!` on types breaks ActiveSupport `.blank?`
|
116
|
-
|
117
|
-
```ruby
|
118
|
-
my_type = GraphQL::ObjectType.define { name("MyType") }
|
119
|
-
# => MyType
|
120
|
-
my_type.present?
|
121
|
-
# => MyType!!
|
122
|
-
my_type.blank?
|
123
|
-
# => MyType!
|
124
|
-
```
|
125
|
-
|
126
115
|
- Accept strings for circular type references
|
127
116
|
- Interface's possible types should be a property of the schema, not the interface
|
128
117
|
- Statically validate type of variables (see early return in LiteralValidator)
|
@@ -132,7 +121,6 @@ https://medium.com/@gauravtiwari/graphql-and-relay-on-rails-first-relay-powered-
|
|
132
121
|
- __Subscriptions__
|
133
122
|
- This is a good chance to make an `Operation` abstraction of which `query`, `mutation` and `subscription` are members
|
134
123
|
- 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)
|
135
|
-
- Documentation
|
136
124
|
|
137
125
|
## Goals
|
138
126
|
|
@@ -11,6 +11,24 @@ describe GraphQL::InterfaceType do
|
|
11
11
|
assert_equal(MilkType, interface.resolve_type(MILKS.values.first))
|
12
12
|
end
|
13
13
|
|
14
|
+
it 'handles when interfaces are re-assigned' do
|
15
|
+
iface = GraphQL::InterfaceType.define do
|
16
|
+
end
|
17
|
+
type = GraphQL::ObjectType.define do
|
18
|
+
interfaces [iface]
|
19
|
+
end
|
20
|
+
assert_equal([type], iface.possible_types)
|
21
|
+
|
22
|
+
type.interfaces = []
|
23
|
+
assert_equal([], iface.possible_types)
|
24
|
+
|
25
|
+
type.interfaces = [iface]
|
26
|
+
assert_equal([type], iface.possible_types)
|
27
|
+
|
28
|
+
type.interfaces = [iface]
|
29
|
+
assert_equal([type], iface.possible_types)
|
30
|
+
end
|
31
|
+
|
14
32
|
describe 'query evaluation' do
|
15
33
|
let(:result) { DummySchema.execute(query_string, context: {}, variables: {"cheeseId" => 2})}
|
16
34
|
let(:query_string) {%|
|
@@ -24,6 +42,20 @@ describe GraphQL::InterfaceType do
|
|
24
42
|
end
|
25
43
|
end
|
26
44
|
|
45
|
+
describe 'mergable query evaluation' do
|
46
|
+
let(:result) { DummySchema.execute(query_string, context: {}, variables: {"cheeseId" => 2})}
|
47
|
+
let(:query_string) {%|
|
48
|
+
query fav {
|
49
|
+
favoriteEdible { fatContent }
|
50
|
+
favoriteEdible { origin }
|
51
|
+
}
|
52
|
+
|}
|
53
|
+
it 'gets fields from the type for the given object' do
|
54
|
+
expected = {"data"=>{"favoriteEdible"=>{"fatContent"=>0.04, "origin"=>"Antiquity"}}}
|
55
|
+
assert_equal(expected, result)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
27
59
|
describe '#resolve_type' do
|
28
60
|
let(:interface) {
|
29
61
|
GraphQL::InterfaceType.define do
|
@@ -14,6 +14,7 @@ describe GraphQL::Introspection::TypeType do
|
|
14
14
|
let(:cheese_fields) {[
|
15
15
|
{"name"=>"id", "isDeprecated" => false, "type" => { "name" => "Non-Null", "ofType" => { "name" => "Int"}}},
|
16
16
|
{"name"=>"flavor", "isDeprecated" => false, "type" => { "name" => "Non-Null", "ofType" => { "name" => "String"}}},
|
17
|
+
{"name"=>"origin", "isDeprecated" => false, "type" => { "name" => "Non-Null", "ofType" => { "name" => "String"}}},
|
17
18
|
{"name"=>"source", "isDeprecated" => false, "type" => { "name" => "Non-Null", "ofType" => { "name" => "DairyAnimal"}}},
|
18
19
|
{"name"=>"similarCheese", "isDeprecated"=>false, "type"=>{"name"=>"Cheese", "ofType"=>nil}},
|
19
20
|
]}
|
@@ -38,6 +39,7 @@ describe GraphQL::Introspection::TypeType do
|
|
38
39
|
"fields"=>[
|
39
40
|
{"type"=>{"name"=>"Non-Null", "ofType"=>{"name"=>"ID"}}},
|
40
41
|
{"type"=>{"name"=>"DairyAnimal", "ofType"=>nil}},
|
42
|
+
{"type"=>{"name"=>"Non-Null", "ofType"=>{"name"=>"String"}}},
|
41
43
|
{"type"=>{"name"=>"Non-Null", "ofType"=>{"name"=>"Float"}}},
|
42
44
|
{"type"=>{"name"=>"List", "ofType"=>{"name"=>"String"}}},
|
43
45
|
]
|
data/spec/spec_helper.rb
CHANGED
@@ -8,6 +8,8 @@ require "minitest/reporters"
|
|
8
8
|
require 'pry'
|
9
9
|
Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new
|
10
10
|
|
11
|
+
Minitest::Spec.make_my_diffs_pretty!
|
12
|
+
|
11
13
|
# Filter out Minitest backtrace while allowing backtrace from other libraries
|
12
14
|
# to be shown.
|
13
15
|
Minitest.backtrace_filter = Minitest::BacktraceFilter.new
|
data/spec/support/dairy_app.rb
CHANGED
@@ -6,6 +6,7 @@ EdibleInterface = GraphQL::InterfaceType.define do
|
|
6
6
|
name "Edible"
|
7
7
|
description "Something you can eat, yum"
|
8
8
|
field :fatContent, !types.Float, "Percentage which is fat", property: :bogus_property
|
9
|
+
field :origin, !types.String, "Place the edible comes from"
|
9
10
|
end
|
10
11
|
|
11
12
|
AnimalProductInterface = GraphQL::InterfaceType.define do
|
@@ -31,6 +32,7 @@ CheeseType = GraphQL::ObjectType.define do
|
|
31
32
|
# Can have (name, type, desc)
|
32
33
|
field :id, !types.Int, "Unique identifier"
|
33
34
|
field :flavor, !types.String, "Kind of Cheese"
|
35
|
+
field :origin, !types.String, "Place the cheese comes from"
|
34
36
|
|
35
37
|
field :source, !DairyAnimalEnum,
|
36
38
|
"Animal which produced the milk for this cheese"
|
@@ -62,6 +64,7 @@ MilkType = GraphQL::ObjectType.define do
|
|
62
64
|
interfaces [EdibleInterface, AnimalProductInterface]
|
63
65
|
field :id, !types.ID
|
64
66
|
field :source, DairyAnimalEnum, "Animal which produced this milk"
|
67
|
+
field :origin, !types.String, "Place the milk comes from"
|
65
68
|
field :fatContent, !types.Float, "Percentage which is milkfat"
|
66
69
|
field :flavors, types[types.String], "Chocolate, Strawberry, etc" do
|
67
70
|
argument :limit, types.Int
|
data/spec/support/dairy_data.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
|
-
Cheese = Struct.new(:id, :flavor, :fat_content, :source)
|
1
|
+
Cheese = Struct.new(:id, :flavor, :origin, :fat_content, :source)
|
2
2
|
CHEESES = {
|
3
|
-
1 => Cheese.new(1, "Brie", 0.19, 1),
|
4
|
-
2 => Cheese.new(2, "Gouda", 0.3, 1),
|
5
|
-
3 => Cheese.new(3, "Manchego", 0.065, "SHEEP")
|
3
|
+
1 => Cheese.new(1, "Brie", "France", 0.19, 1),
|
4
|
+
2 => Cheese.new(2, "Gouda", "Netherlands", 0.3, 1),
|
5
|
+
3 => Cheese.new(3, "Manchego", "Spain", 0.065, "SHEEP")
|
6
6
|
}
|
7
7
|
|
8
|
-
Milk = Struct.new(:id, :fatContent, :source, :flavors)
|
8
|
+
Milk = Struct.new(:id, :fatContent, :origin, :source, :flavors)
|
9
9
|
MILKS = {
|
10
|
-
1 => Milk.new(1, 0.04, 1, ["Natural", "Chocolate", "Strawberry"]),
|
10
|
+
1 => Milk.new(1, 0.04, "Antiquity", 1, ["Natural", "Chocolate", "Strawberry"]),
|
11
11
|
}
|
12
12
|
|
13
13
|
DAIRY = OpenStruct.new(
|
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.10.
|
4
|
+
version: 0.10.9
|
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-01-
|
11
|
+
date: 2016-01-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: parslet
|