graphql 0.3.0 → 0.4.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.
- checksums.yaml +4 -4
- data/lib/graph_ql/{types/input_value.rb → argument.rb} +4 -1
- data/lib/graph_ql/{scalars/boolean_type.rb → boolean_type.rb} +0 -0
- data/lib/graph_ql/definition_helpers.rb +10 -0
- data/lib/graph_ql/definition_helpers/argument_definer.rb +5 -2
- data/lib/graph_ql/definition_helpers/definable.rb +1 -1
- data/lib/graph_ql/definition_helpers/field_definer.rb +4 -1
- data/lib/graph_ql/definition_helpers/non_null_with_bang.rb +3 -1
- data/lib/graph_ql/definition_helpers/string_named_hash.rb +7 -1
- data/lib/graph_ql/definition_helpers/type_definer.rb +13 -1
- data/lib/graph_ql/directive.rb +14 -6
- data/lib/graph_ql/{directives → directive}/include_directive.rb +1 -1
- data/lib/graph_ql/{directives → directive}/skip_directive.rb +1 -1
- data/lib/graph_ql/enum_type.rb +66 -0
- data/lib/graph_ql/field.rb +49 -13
- data/lib/graph_ql/{scalars/float_type.rb → float_type.rb} +0 -0
- data/lib/graph_ql/{scalars/id_type.rb → id_type.rb} +0 -0
- data/lib/graph_ql/input_object_type.rb +33 -0
- data/lib/graph_ql/{scalars/int_type.rb → int_type.rb} +0 -0
- data/lib/graph_ql/interface_type.rb +33 -0
- data/lib/graph_ql/introspection/field_type.rb +1 -0
- data/lib/graph_ql/introspection/fields_field.rb +1 -0
- data/lib/graph_ql/introspection/input_value_type.rb +1 -1
- data/lib/graph_ql/introspection/introspection_query.rb +77 -0
- data/lib/graph_ql/introspection/schema_field.rb +13 -0
- data/lib/graph_ql/introspection/type_by_name_field.rb +14 -0
- data/lib/graph_ql/introspection/type_kind_enum.rb +1 -1
- data/lib/graph_ql/{types/list_type.rb → list_type.rb} +3 -0
- data/lib/graph_ql/{parser/nodes.rb → nodes.rb} +8 -1
- data/lib/graph_ql/{types/non_null_type.rb → non_null_type.rb} +3 -0
- data/lib/graph_ql/object_type.rb +92 -0
- data/lib/graph_ql/parser.rb +107 -6
- data/lib/graph_ql/query.rb +8 -0
- data/lib/graph_ql/query/arguments.rb +13 -4
- data/lib/graph_ql/{directives → query}/directive_chain.rb +2 -2
- data/lib/graph_ql/query/field_resolution_strategy.rb +2 -2
- data/lib/graph_ql/query/operation_resolver.rb +3 -3
- data/lib/graph_ql/query/selection_resolver.rb +1 -1
- data/lib/graph_ql/scalar_type.rb +9 -0
- data/lib/graph_ql/schema.rb +26 -17
- data/lib/graph_ql/schema/type_reducer.rb +7 -0
- data/lib/graph_ql/static_validation/arguments_validator.rb +1 -0
- data/lib/graph_ql/static_validation/message.rb +4 -1
- data/lib/graph_ql/static_validation/rules/fields_are_defined_on_type.rb +1 -0
- data/lib/graph_ql/static_validation/rules/fields_have_appropriate_selections.rb +1 -0
- data/lib/graph_ql/static_validation/type_stack.rb +24 -4
- data/lib/graph_ql/static_validation/validator.rb +27 -0
- data/lib/graph_ql/{scalars/string_type.rb → string_type.rb} +0 -0
- data/lib/graph_ql/transform.rb +87 -0
- data/lib/graph_ql/type_kinds.rb +9 -0
- data/lib/graph_ql/{types/union.rb → union_type.rb} +8 -4
- data/lib/graph_ql/version.rb +1 -1
- data/lib/graph_ql/{parser/visitor.rb → visitor.rb} +29 -4
- data/lib/graphql.rb +28 -11
- data/readme.md +11 -1
- data/spec/graph_ql/{types/enum_spec.rb → enum_type_spec.rb} +1 -1
- data/spec/graph_ql/{fields/field_spec.rb → field_spec.rb} +0 -0
- data/spec/graph_ql/{scalars/id_type_spec.rb → id_type_spec.rb} +0 -0
- data/spec/graph_ql/{types/input_object_type_spec.rb → input_object_type_spec.rb} +0 -0
- data/spec/graph_ql/{types/interface_spec.rb → interface_type_spec.rb} +1 -1
- data/spec/graph_ql/introspection/introspection_query_spec.rb +10 -0
- data/spec/graph_ql/introspection/schema_type_spec.rb +0 -4
- data/spec/graph_ql/introspection/type_type_spec.rb +1 -5
- data/spec/graph_ql/{types/object_type_spec.rb → object_type_spec.rb} +0 -0
- data/spec/graph_ql/{parser/parser_spec.rb → parser_spec.rb} +0 -0
- data/spec/graph_ql/query/operation_resolver_spec.rb +1 -1
- data/spec/graph_ql/query_spec.rb +6 -2
- data/spec/graph_ql/schema/type_validator_spec.rb +1 -1
- data/spec/graph_ql/{parser/transform_spec.rb → transform_spec.rb} +0 -0
- data/spec/graph_ql/{types/union_spec.rb → union_type_spec.rb} +2 -2
- data/spec/graph_ql/{parser/visitor_spec.rb → visitor_spec.rb} +0 -0
- data/spec/support/{dummy_app.rb → dairy_app.rb} +8 -8
- data/spec/support/{dummy_data.rb → dairy_data.rb} +0 -0
- data/spec/support/star_wars_data.rb +71 -0
- data/spec/support/star_wars_schema.rb +87 -0
- metadata +59 -50
- data/lib/graph_ql/definition_helpers/forwardable.rb +0 -10
- data/lib/graph_ql/parser/parser.rb +0 -108
- data/lib/graph_ql/parser/transform.rb +0 -87
- data/lib/graph_ql/scalars/scalar_type.rb +0 -5
- data/lib/graph_ql/types/enum.rb +0 -32
- data/lib/graph_ql/types/input_object_type.rb +0 -14
- data/lib/graph_ql/types/interface.rb +0 -14
- data/lib/graph_ql/types/object_type.rb +0 -66
data/readme.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# graphql
|
1
|
+
# graphql <img src="https://cloud.githubusercontent.com/assets/2231765/9094460/cb43861e-3b66-11e5-9fbf-71066ff3ab13.png" height=40 alt="graphql-ruby"/>
|
2
2
|
|
3
3
|
[](https://travis-ci.org/rmosolgo/graphql-ruby)
|
4
4
|
[](https://rubygems.org/gems/graphql)
|
@@ -6,6 +6,9 @@
|
|
6
6
|
[](https://codeclimate.com/github/rmosolgo/graphql-ruby)
|
7
7
|
[](http://rmosolgo.github.io/react-badges/)
|
8
8
|
|
9
|
+
- [Introduction](https://github.com/rmosolgo/graphql-ruby/blob/master/guides/introduction.md)
|
10
|
+
- [API Documentation](http://www.rubydoc.info/github/rmosolgo/graphql-ruby)
|
11
|
+
|
9
12
|
## Overview
|
10
13
|
|
11
14
|
- __Install the gem__:
|
@@ -87,7 +90,10 @@
|
|
87
90
|
- https://github.com/graphql/graphql-js/issues/19#issuecomment-118515077
|
88
91
|
- Code clean-up
|
89
92
|
- Unify unwrapping types (It's on `TypeKind` but it's still not right)
|
93
|
+
- Better definition API
|
90
94
|
- Cook up some path other than "n+1s everywhere"
|
95
|
+
- See Sangria's `project` approach ([in progress](https://github.com/rmosolgo/graphql-ruby/pull/15))
|
96
|
+
|
91
97
|
|
92
98
|
## Goals
|
93
99
|
|
@@ -108,3 +114,7 @@
|
|
108
114
|
- Other implementations: [graphql-links](https://github.com/emmenko/graphql-links)
|
109
115
|
- `graphql-ruby` + Rails demo ([src](https://github.com/rmosolgo/graphql-ruby-demo) / [heroku](http://graphql-ruby-demo.herokuapp.com))
|
110
116
|
- [GraphQL Slack](https://graphql-slack.herokuapp.com/)
|
117
|
+
|
118
|
+
## P.S.
|
119
|
+
|
120
|
+
Thanks to @sgwilym for the great logo!
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "GraphQL::Introspection::INTROSPECTION_QUERY" do
|
4
|
+
let(:query_string) { GraphQL::Introspection::INTROSPECTION_QUERY }
|
5
|
+
let(:result) { GraphQL::Query.new(DummySchema, query_string).result }
|
6
|
+
|
7
|
+
it 'runs' do
|
8
|
+
assert(result["data"])
|
9
|
+
end
|
10
|
+
end
|
@@ -23,15 +23,11 @@ describe GraphQL::Introspection::SchemaType do
|
|
23
23
|
{"name"=>"favoriteEdible"},
|
24
24
|
{"name"=>"searchDairy"},
|
25
25
|
{"name"=>"error"},
|
26
|
-
{"name"=>"__typename"},
|
27
|
-
{"name"=>"__type"},
|
28
|
-
{"name"=>"__schema"},
|
29
26
|
]
|
30
27
|
},
|
31
28
|
"mutationType"=> {
|
32
29
|
"fields"=>[
|
33
30
|
{"name"=>"pushValue"},
|
34
|
-
{"name"=>"__typename"}
|
35
31
|
]
|
36
32
|
},
|
37
33
|
}
|
@@ -16,7 +16,6 @@ describe GraphQL::Introspection::TypeType do
|
|
16
16
|
{"name"=>"flavor", "isDeprecated" => false, "type" => { "name" => "Non-Null", "ofType" => { "name" => "String"}}},
|
17
17
|
{"name"=>"source", "isDeprecated" => false, "type" => { "name" => "Non-Null", "ofType" => { "name" => "DairyAnimal"}}},
|
18
18
|
{"name"=>"similarCheeses", "isDeprecated"=>false, "type"=>{"name"=>"Cheese", "ofType"=>nil}},
|
19
|
-
{"name"=>"__typename", "isDeprecated"=>false, "type"=> { "name" => "Non-Null", "ofType" => { "name" => "String"}}},
|
20
19
|
]}
|
21
20
|
|
22
21
|
let(:dairy_animals) {[
|
@@ -41,7 +40,6 @@ describe GraphQL::Introspection::TypeType do
|
|
41
40
|
{"type"=>{"name"=>"DairyAnimal", "ofType"=>nil}},
|
42
41
|
{"type"=>{"name"=>"Non-Null", "ofType"=>{"name"=>"Float"}}},
|
43
42
|
{"type"=>{"name"=>"List", "ofType"=>{"name"=>"String"}}},
|
44
|
-
{"type"=>{"name"=>"Non-Null", "ofType"=>{"name"=>"String"}}}
|
45
43
|
]
|
46
44
|
},
|
47
45
|
"dairyAnimal"=>{
|
@@ -60,7 +58,6 @@ describe GraphQL::Introspection::TypeType do
|
|
60
58
|
"possibleTypes"=>[{"name"=>"Cheese"}, {"name"=>"Milk"}],
|
61
59
|
"fields"=>[
|
62
60
|
{"name"=>"source"},
|
63
|
-
{"name"=>"__typename"},
|
64
61
|
]
|
65
62
|
}
|
66
63
|
}}
|
@@ -76,8 +73,7 @@ describe GraphQL::Introspection::TypeType do
|
|
76
73
|
|}
|
77
74
|
let(:deprecated_fields) { {"name"=>"fatContent", "isDeprecated"=>true, "type"=>{"name"=>"Non-Null", "ofType"=>{"name"=>"Float"}}} }
|
78
75
|
it 'can expose deprecated fields' do
|
79
|
-
|
80
|
-
new_cheese_fields = cheese_fields + [deprecated_fields, typename]
|
76
|
+
new_cheese_fields = cheese_fields + [deprecated_fields]
|
81
77
|
expected = { "data" => {
|
82
78
|
"cheeseType" => {
|
83
79
|
"name"=> "Cheese",
|
File without changes
|
File without changes
|
@@ -3,7 +3,7 @@ require 'spec_helper'
|
|
3
3
|
describe GraphQL::Query::OperationResolver do
|
4
4
|
let(:operation) { GraphQL.parse("query getCheese($cheeseId: Int!) { cheese(id: $cheeseId) { name }}", as: :operation_definition) }
|
5
5
|
let(:params) { {"cheeseId" => 1}}
|
6
|
-
let(:query) {
|
6
|
+
let(:query) { OpenStruct.new(params: params, context: nil) }
|
7
7
|
let(:resolver) { GraphQL::Query::OperationResolver.new(operation, query)}
|
8
8
|
|
9
9
|
describe "variables" do
|
data/spec/graph_ql/query_spec.rb
CHANGED
@@ -14,7 +14,11 @@ describe GraphQL::Query do
|
|
14
14
|
}
|
15
15
|
fromSource(source: COW) { id }
|
16
16
|
fromSheep: fromSource(source: SHEEP) { id }
|
17
|
-
firstSheep: searchDairy(product: {source: SHEEP}) {
|
17
|
+
firstSheep: searchDairy(product: {source: SHEEP}) {
|
18
|
+
__typename,
|
19
|
+
... dairyFields,
|
20
|
+
... milkFields
|
21
|
+
}
|
18
22
|
favoriteEdible { __typename, fatContent }
|
19
23
|
}
|
20
24
|
fragment cheeseFields on Cheese { flavor }
|
@@ -41,7 +45,7 @@ describe GraphQL::Query do
|
|
41
45
|
},
|
42
46
|
"fromSource" => [{ "id" => 1 }, {"id" => 2}],
|
43
47
|
"fromSheep"=>[{"id"=>3}],
|
44
|
-
"firstSheep" => { "flavor" => "Manchego" },
|
48
|
+
"firstSheep" => { "__typename" => "Cheese", "flavor" => "Manchego" },
|
45
49
|
"favoriteEdible"=>{"__typename"=>"Milk", "fatContent"=>0.04},
|
46
50
|
}}
|
47
51
|
assert_equal(expected, result)
|
@@ -40,7 +40,7 @@ describe GraphQL::Schema::TypeValidator do
|
|
40
40
|
|
41
41
|
describe "when a Union isnt valid" do
|
42
42
|
let(:object) {
|
43
|
-
GraphQL::
|
43
|
+
GraphQL::UnionType.new("Something", "some union", [DairyProductInputType])
|
44
44
|
}
|
45
45
|
let(:errors) { e = []; GraphQL::Schema::TypeValidator.new.validate(object, e); e;}
|
46
46
|
it 'must be 2+ types, must be only object types' do
|
File without changes
|
@@ -1,9 +1,9 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe GraphQL::
|
3
|
+
describe GraphQL::UnionType do
|
4
4
|
let(:type_1) { OpenStruct.new(kind: GraphQL::TypeKinds::OBJECT)}
|
5
5
|
let(:type_2) { OpenStruct.new(kind: GraphQL::TypeKinds::OBJECT)}
|
6
|
-
let(:union) { GraphQL::
|
6
|
+
let(:union) { GraphQL::UnionType.new("MyUnion", "Some items", [type_1, type_2]) }
|
7
7
|
it 'has a name' do
|
8
8
|
assert_equal("MyUnion", union.name)
|
9
9
|
end
|
File without changes
|
@@ -1,6 +1,6 @@
|
|
1
|
-
require_relative './
|
1
|
+
require_relative './dairy_data'
|
2
2
|
|
3
|
-
EdibleInterface = GraphQL::
|
3
|
+
EdibleInterface = GraphQL::InterfaceType.new do |i, type, field|
|
4
4
|
i.name "Edible"
|
5
5
|
i.description "Something you can eat, yum"
|
6
6
|
i.fields({
|
@@ -11,7 +11,7 @@ EdibleInterface = GraphQL::Interface.new do |i, type, field|
|
|
11
11
|
})
|
12
12
|
end
|
13
13
|
|
14
|
-
AnimalProductInterface = GraphQL::
|
14
|
+
AnimalProductInterface = GraphQL::InterfaceType.new do |i, type, field|
|
15
15
|
i.name "AnimalProduct"
|
16
16
|
i.description "Comes from an animal, no joke"
|
17
17
|
i.fields({
|
@@ -19,7 +19,7 @@ AnimalProductInterface = GraphQL::Interface.new do |i, type, field|
|
|
19
19
|
})
|
20
20
|
end
|
21
21
|
|
22
|
-
DairyAnimalEnum = GraphQL::
|
22
|
+
DairyAnimalEnum = GraphQL::EnumType.new do |e|
|
23
23
|
e.name "DairyAnimal"
|
24
24
|
e.description "An animal which can yield milk"
|
25
25
|
e.value("COW", "Animal with black and white spots", value: 1)
|
@@ -62,7 +62,7 @@ MilkType = GraphQL::ObjectType.new do |t, type, field, arg|
|
|
62
62
|
}
|
63
63
|
end
|
64
64
|
|
65
|
-
DairyProductUnion = GraphQL::
|
65
|
+
DairyProductUnion = GraphQL::UnionType.new(
|
66
66
|
"DairyProduct",
|
67
67
|
"Kinds of food made from milk",
|
68
68
|
[MilkType, CheeseType]
|
@@ -84,7 +84,7 @@ class FetchField
|
|
84
84
|
def initialize(type:, data:, id_type: !GraphQL::INT_TYPE)
|
85
85
|
@type = type
|
86
86
|
@data = data
|
87
|
-
@arguments = {"id" => GraphQL::
|
87
|
+
@arguments = {"id" => GraphQL::Argument.new(type: id_type, name: "id")}
|
88
88
|
@deprecation_reason = nil
|
89
89
|
end
|
90
90
|
|
@@ -128,7 +128,7 @@ QueryType = GraphQL::ObjectType.new do |t, types, field, arg|
|
|
128
128
|
f.arguments({product: arg.build({type: DairyProductInputType})})
|
129
129
|
f.resolve -> (t, a, c) {
|
130
130
|
products = CHEESES.values + MILKS.values
|
131
|
-
source = a["product"][
|
131
|
+
source = a["product"][:source] # String or sym is ok
|
132
132
|
if !source.nil?
|
133
133
|
products = products.select { |p| p.source == source }
|
134
134
|
end
|
@@ -154,7 +154,7 @@ MutationType = GraphQL::ObjectType.new do |t, type, field, arg|
|
|
154
154
|
f.type(!type[!type.Int])
|
155
155
|
f.arguments(value: arg.build(type: !type.Int))
|
156
156
|
f.resolve -> (o, args, ctx) {
|
157
|
-
GLOBAL_VALUES << args[
|
157
|
+
GLOBAL_VALUES << args[:value]
|
158
158
|
GLOBAL_VALUES
|
159
159
|
}
|
160
160
|
}
|
File without changes
|
@@ -0,0 +1,71 @@
|
|
1
|
+
luke = OpenStruct.new({
|
2
|
+
id: '1000',
|
3
|
+
name: 'Luke Skywalker',
|
4
|
+
friends: ['1002', '1003', '2000', '2001'],
|
5
|
+
appearsIn: [4, 5, 6],
|
6
|
+
homePlanet: 'Tatooine',
|
7
|
+
})
|
8
|
+
|
9
|
+
vader = OpenStruct.new({
|
10
|
+
id: '1001',
|
11
|
+
name: 'Darth Vader',
|
12
|
+
friends: ['1004'],
|
13
|
+
appearsIn: [4, 5, 6],
|
14
|
+
homePlanet: 'Tatooine',
|
15
|
+
})
|
16
|
+
|
17
|
+
han = OpenStruct.new({
|
18
|
+
id: '1002',
|
19
|
+
name: 'Han Solo',
|
20
|
+
friends: ['1000', '1003', '2001'],
|
21
|
+
appearsIn: [4, 5, 6],
|
22
|
+
})
|
23
|
+
|
24
|
+
leia = OpenStruct.new({
|
25
|
+
id: '1003',
|
26
|
+
name: 'Leia Organa',
|
27
|
+
friends: ['1000', '1002', '2000', '2001'],
|
28
|
+
appearsIn: [4, 5, 6],
|
29
|
+
homePlanet: 'Alderaan',
|
30
|
+
})
|
31
|
+
|
32
|
+
tarkin = OpenStruct.new({
|
33
|
+
id: '1004',
|
34
|
+
name: 'Wilhuff Tarkin',
|
35
|
+
friends: ['1001'],
|
36
|
+
appearsIn: [4],
|
37
|
+
})
|
38
|
+
|
39
|
+
HUMAN_DATA = {
|
40
|
+
"1000" => luke,
|
41
|
+
"1001" => vader,
|
42
|
+
"1002" => han,
|
43
|
+
"1003" => leia,
|
44
|
+
"1004" => tarkin,
|
45
|
+
}
|
46
|
+
|
47
|
+
threepio = OpenStruct.new({
|
48
|
+
id: '2000',
|
49
|
+
name: 'C-3PO',
|
50
|
+
friends: ['1000', '1002', '1003', '2001'],
|
51
|
+
appearsIn: [4, 5, 6],
|
52
|
+
primaryFunction: 'Protocol',
|
53
|
+
})
|
54
|
+
|
55
|
+
artoo = OpenStruct.new({
|
56
|
+
id: '2001',
|
57
|
+
name: 'R2-D2',
|
58
|
+
friends: ['1000', '1002', '1003'],
|
59
|
+
appearsIn: [4, 5, 6],
|
60
|
+
primaryFunction: 'Astromech',
|
61
|
+
})
|
62
|
+
|
63
|
+
DROID_DATA = {
|
64
|
+
"2000" => threepio,
|
65
|
+
"2001" => artoo,
|
66
|
+
}
|
67
|
+
|
68
|
+
# Get friends from IDs
|
69
|
+
GET_FRIENDS = -> (obj, args, ctx) do
|
70
|
+
obj.friends.map { |id| HUMAN_DATA[id] || DROID_DATA[id]}
|
71
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
# Based on the graphql-js example
|
2
|
+
# https://github.com/graphql/graphql-js/blob/master/src/__tests__/starWarsSchema.js
|
3
|
+
require_relative './star_wars_data'
|
4
|
+
|
5
|
+
EpisodeEnum = GraphQL::EnumType.new do |e|
|
6
|
+
e.name("Episode")
|
7
|
+
e.description("One of the films in the Star Wars Trilogy.")
|
8
|
+
|
9
|
+
e.value("NEWHOPE", "Released in 1977", value: 4)
|
10
|
+
e.value("EMPIRE", "Released in 1980", value: 5)
|
11
|
+
e.value("JEDI", "Released in 1983", value: 6)
|
12
|
+
end
|
13
|
+
|
14
|
+
CharacterInterface = GraphQL::InterfaceType.new do |i, types, field|
|
15
|
+
i.name("Character")
|
16
|
+
i.description("A character in the Star Wars Trilogy.")
|
17
|
+
|
18
|
+
i.fields({
|
19
|
+
id: field.build(type: !types.String, desc: "The id of the character."),
|
20
|
+
name: field.build(type: types.String, desc: "The name of the Character."),
|
21
|
+
friends: field.build(type: types[i], desc: "The friends of the character, or an empty list if they have none."),
|
22
|
+
appearsIn: field.build(type: types[EpisodeEnum], desc: "Which movies they appear in."),
|
23
|
+
})
|
24
|
+
end
|
25
|
+
|
26
|
+
HumanType = GraphQL::ObjectType.new do |t, types, field|
|
27
|
+
t.name("Human")
|
28
|
+
t.description("A humanoid creature in the Star Wars universe.")
|
29
|
+
t.fields({
|
30
|
+
id: field.build(type: !types.String, desc: "The id of the human."),
|
31
|
+
name: field.build(type: types.String, desc: "The name of the human."),
|
32
|
+
friends: GraphQL::Field.new { |f|
|
33
|
+
f.type(types[CharacterInterface])
|
34
|
+
f.description("The friends of the human, or an empty list if they have none.")
|
35
|
+
f.resolve(GET_FRIENDS)
|
36
|
+
},
|
37
|
+
appearsIn: field.build(type: types[EpisodeEnum], desc: "Which movies they appear in."),
|
38
|
+
homePlanet: field.build(type: types.String, desc: "The home planet of the human, or null if unknown."),
|
39
|
+
})
|
40
|
+
t.interfaces([CharacterInterface])
|
41
|
+
end
|
42
|
+
|
43
|
+
DroidType = GraphQL::ObjectType.new do |t, types, field|
|
44
|
+
t.name("Droid")
|
45
|
+
t.description("A mechanical creature in the Star Wars universe.")
|
46
|
+
t.fields({
|
47
|
+
id: field.build(type: !types.String, desc: "The id of the droid."),
|
48
|
+
name: field.build(type: types.String, desc: "The name of the droid."),
|
49
|
+
friends: GraphQL::Field.new { |f|
|
50
|
+
f.type(types[CharacterInterface])
|
51
|
+
f.description("The friends of the droid, or an empty list if they have none.")
|
52
|
+
f.resolve(GET_FRIENDS)
|
53
|
+
},
|
54
|
+
appearsIn: field.build(type: types[EpisodeEnum], desc: "Which movies they appear in."),
|
55
|
+
primaryFunction: field.build(type: types.String, desc: "The primary function of the droid."),
|
56
|
+
})
|
57
|
+
t.interfaces([CharacterInterface])
|
58
|
+
end
|
59
|
+
|
60
|
+
class FindRecordField < GraphQL::Field
|
61
|
+
def initialize(type, data)
|
62
|
+
@data = data
|
63
|
+
self.type = type
|
64
|
+
self.arguments = {
|
65
|
+
id: GraphQL::Argument.new(type: !GraphQL::STRING_TYPE, description: "The id of the #{type.name}.")
|
66
|
+
}
|
67
|
+
end
|
68
|
+
|
69
|
+
def resolve(obj, args, ctx)
|
70
|
+
@data[args["id"]]
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
|
75
|
+
StarWarsQueryType = GraphQL::ObjectType.new do |t, types, field, arg|
|
76
|
+
t.name("Query")
|
77
|
+
t.fields({
|
78
|
+
hero: GraphQL::Field.new { |f|
|
79
|
+
f.arguments({
|
80
|
+
episode: arg.build(type: EpisodeEnum, desc: "If omitted, returns the hero of the whole saga. If provided, returns the hero of that particular episode"),
|
81
|
+
})
|
82
|
+
f.resolve -> (obj, args, ctx) { args["episode"] == 5 ? luke : artoo }
|
83
|
+
},
|
84
|
+
human: FindRecordField.new(HumanType, HUMAN_DATA),
|
85
|
+
droid: FindRecordField.new(DroidType, DROID_DATA),
|
86
|
+
})
|
87
|
+
end
|
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.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Mosolgo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-08-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: parslet
|
@@ -150,7 +150,8 @@ dependencies:
|
|
150
150
|
- - "~>"
|
151
151
|
- !ruby/object:Gem::Version
|
152
152
|
version: '10.4'
|
153
|
-
description:
|
153
|
+
description: "\n Full-fledged implementation of the GraphQL spec.\n Includes
|
154
|
+
query parsing, static validation, type definition, and query execution.\n "
|
154
155
|
email:
|
155
156
|
- rdmosolgo@gmail.com
|
156
157
|
executables: []
|
@@ -158,18 +159,25 @@ extensions: []
|
|
158
159
|
extra_rdoc_files: []
|
159
160
|
files:
|
160
161
|
- MIT-LICENSE
|
162
|
+
- lib/graph_ql/argument.rb
|
163
|
+
- lib/graph_ql/boolean_type.rb
|
164
|
+
- lib/graph_ql/definition_helpers.rb
|
161
165
|
- lib/graph_ql/definition_helpers/argument_definer.rb
|
162
166
|
- lib/graph_ql/definition_helpers/definable.rb
|
163
167
|
- lib/graph_ql/definition_helpers/field_definer.rb
|
164
|
-
- lib/graph_ql/definition_helpers/forwardable.rb
|
165
168
|
- lib/graph_ql/definition_helpers/non_null_with_bang.rb
|
166
169
|
- lib/graph_ql/definition_helpers/string_named_hash.rb
|
167
170
|
- lib/graph_ql/definition_helpers/type_definer.rb
|
168
171
|
- lib/graph_ql/directive.rb
|
169
|
-
- lib/graph_ql/
|
170
|
-
- lib/graph_ql/
|
171
|
-
- lib/graph_ql/
|
172
|
+
- lib/graph_ql/directive/include_directive.rb
|
173
|
+
- lib/graph_ql/directive/skip_directive.rb
|
174
|
+
- lib/graph_ql/enum_type.rb
|
172
175
|
- lib/graph_ql/field.rb
|
176
|
+
- lib/graph_ql/float_type.rb
|
177
|
+
- lib/graph_ql/id_type.rb
|
178
|
+
- lib/graph_ql/input_object_type.rb
|
179
|
+
- lib/graph_ql/int_type.rb
|
180
|
+
- lib/graph_ql/interface_type.rb
|
173
181
|
- lib/graph_ql/introspection/arguments_field.rb
|
174
182
|
- lib/graph_ql/introspection/directive_type.rb
|
175
183
|
- lib/graph_ql/introspection/enum_value_type.rb
|
@@ -179,19 +187,23 @@ files:
|
|
179
187
|
- lib/graph_ql/introspection/input_fields_field.rb
|
180
188
|
- lib/graph_ql/introspection/input_value_type.rb
|
181
189
|
- lib/graph_ql/introspection/interfaces_field.rb
|
190
|
+
- lib/graph_ql/introspection/introspection_query.rb
|
182
191
|
- lib/graph_ql/introspection/of_type_field.rb
|
183
192
|
- lib/graph_ql/introspection/possible_types_field.rb
|
193
|
+
- lib/graph_ql/introspection/schema_field.rb
|
184
194
|
- lib/graph_ql/introspection/schema_type.rb
|
195
|
+
- lib/graph_ql/introspection/type_by_name_field.rb
|
185
196
|
- lib/graph_ql/introspection/type_kind_enum.rb
|
186
197
|
- lib/graph_ql/introspection/type_type.rb
|
187
198
|
- lib/graph_ql/introspection/typename_field.rb
|
199
|
+
- lib/graph_ql/list_type.rb
|
200
|
+
- lib/graph_ql/nodes.rb
|
201
|
+
- lib/graph_ql/non_null_type.rb
|
202
|
+
- lib/graph_ql/object_type.rb
|
188
203
|
- lib/graph_ql/parser.rb
|
189
|
-
- lib/graph_ql/parser/nodes.rb
|
190
|
-
- lib/graph_ql/parser/parser.rb
|
191
|
-
- lib/graph_ql/parser/transform.rb
|
192
|
-
- lib/graph_ql/parser/visitor.rb
|
193
204
|
- lib/graph_ql/query.rb
|
194
205
|
- lib/graph_ql/query/arguments.rb
|
206
|
+
- lib/graph_ql/query/directive_chain.rb
|
195
207
|
- lib/graph_ql/query/field_resolution_strategy.rb
|
196
208
|
- lib/graph_ql/query/fragment_spread_resolution_strategy.rb
|
197
209
|
- lib/graph_ql/query/inline_fragment_resolution_strategy.rb
|
@@ -199,12 +211,7 @@ files:
|
|
199
211
|
- lib/graph_ql/query/selection_resolver.rb
|
200
212
|
- lib/graph_ql/query/type_resolver.rb
|
201
213
|
- lib/graph_ql/repl.rb
|
202
|
-
- lib/graph_ql/
|
203
|
-
- lib/graph_ql/scalars/float_type.rb
|
204
|
-
- lib/graph_ql/scalars/id_type.rb
|
205
|
-
- lib/graph_ql/scalars/int_type.rb
|
206
|
-
- lib/graph_ql/scalars/scalar_type.rb
|
207
|
-
- lib/graph_ql/scalars/string_type.rb
|
214
|
+
- lib/graph_ql/scalar_type.rb
|
208
215
|
- lib/graph_ql/schema.rb
|
209
216
|
- lib/graph_ql/schema/each_item_validator.rb
|
210
217
|
- lib/graph_ql/schema/field_validator.rb
|
@@ -235,29 +242,28 @@ files:
|
|
235
242
|
- lib/graph_ql/static_validation/rules/variables_are_used_and_defined.rb
|
236
243
|
- lib/graph_ql/static_validation/type_stack.rb
|
237
244
|
- lib/graph_ql/static_validation/validator.rb
|
245
|
+
- lib/graph_ql/string_type.rb
|
246
|
+
- lib/graph_ql/transform.rb
|
238
247
|
- lib/graph_ql/type_kinds.rb
|
239
|
-
- lib/graph_ql/
|
240
|
-
- lib/graph_ql/types/input_object_type.rb
|
241
|
-
- lib/graph_ql/types/input_value.rb
|
242
|
-
- lib/graph_ql/types/interface.rb
|
243
|
-
- lib/graph_ql/types/list_type.rb
|
244
|
-
- lib/graph_ql/types/non_null_type.rb
|
245
|
-
- lib/graph_ql/types/object_type.rb
|
246
|
-
- lib/graph_ql/types/union.rb
|
248
|
+
- lib/graph_ql/union_type.rb
|
247
249
|
- lib/graph_ql/version.rb
|
250
|
+
- lib/graph_ql/visitor.rb
|
248
251
|
- lib/graphql.rb
|
249
252
|
- readme.md
|
250
253
|
- spec/graph_ql/directive_spec.rb
|
251
|
-
- spec/graph_ql/
|
254
|
+
- spec/graph_ql/enum_type_spec.rb
|
255
|
+
- spec/graph_ql/field_spec.rb
|
256
|
+
- spec/graph_ql/id_type_spec.rb
|
257
|
+
- spec/graph_ql/input_object_type_spec.rb
|
258
|
+
- spec/graph_ql/interface_type_spec.rb
|
252
259
|
- spec/graph_ql/introspection/directive_type_spec.rb
|
260
|
+
- spec/graph_ql/introspection/introspection_query_spec.rb
|
253
261
|
- spec/graph_ql/introspection/schema_type_spec.rb
|
254
262
|
- spec/graph_ql/introspection/type_type_spec.rb
|
255
|
-
- spec/graph_ql/
|
256
|
-
- spec/graph_ql/
|
257
|
-
- spec/graph_ql/parser/visitor_spec.rb
|
263
|
+
- spec/graph_ql/object_type_spec.rb
|
264
|
+
- spec/graph_ql/parser_spec.rb
|
258
265
|
- spec/graph_ql/query/operation_resolver_spec.rb
|
259
266
|
- spec/graph_ql/query_spec.rb
|
260
|
-
- spec/graph_ql/scalars/id_type_spec.rb
|
261
267
|
- spec/graph_ql/schema/field_validator_spec.rb
|
262
268
|
- spec/graph_ql/schema/type_reducer_spec.rb
|
263
269
|
- spec/graph_ql/schema/type_validator_spec.rb
|
@@ -279,14 +285,14 @@ files:
|
|
279
285
|
- spec/graph_ql/static_validation/rules/variables_are_used_and_defined_spec.rb
|
280
286
|
- spec/graph_ql/static_validation/type_stack_spec.rb
|
281
287
|
- spec/graph_ql/static_validation/validator_spec.rb
|
282
|
-
- spec/graph_ql/
|
283
|
-
- spec/graph_ql/
|
284
|
-
- spec/graph_ql/
|
285
|
-
- spec/graph_ql/types/object_type_spec.rb
|
286
|
-
- spec/graph_ql/types/union_spec.rb
|
288
|
+
- spec/graph_ql/transform_spec.rb
|
289
|
+
- spec/graph_ql/union_type_spec.rb
|
290
|
+
- spec/graph_ql/visitor_spec.rb
|
287
291
|
- spec/spec_helper.rb
|
288
|
-
- spec/support/
|
289
|
-
- spec/support/
|
292
|
+
- spec/support/dairy_app.rb
|
293
|
+
- spec/support/dairy_data.rb
|
294
|
+
- spec/support/star_wars_data.rb
|
295
|
+
- spec/support/star_wars_schema.rb
|
290
296
|
homepage: http://github.com/rmosolgo/graphql-ruby
|
291
297
|
licenses:
|
292
298
|
- MIT
|
@@ -310,19 +316,22 @@ rubyforge_project:
|
|
310
316
|
rubygems_version: 2.4.5
|
311
317
|
signing_key:
|
312
318
|
specification_version: 4
|
313
|
-
summary: GraphQL
|
319
|
+
summary: A GraphQL implementation for Ruby
|
314
320
|
test_files:
|
315
321
|
- spec/graph_ql/directive_spec.rb
|
316
|
-
- spec/graph_ql/
|
322
|
+
- spec/graph_ql/enum_type_spec.rb
|
323
|
+
- spec/graph_ql/field_spec.rb
|
324
|
+
- spec/graph_ql/id_type_spec.rb
|
325
|
+
- spec/graph_ql/input_object_type_spec.rb
|
326
|
+
- spec/graph_ql/interface_type_spec.rb
|
317
327
|
- spec/graph_ql/introspection/directive_type_spec.rb
|
328
|
+
- spec/graph_ql/introspection/introspection_query_spec.rb
|
318
329
|
- spec/graph_ql/introspection/schema_type_spec.rb
|
319
330
|
- spec/graph_ql/introspection/type_type_spec.rb
|
320
|
-
- spec/graph_ql/
|
321
|
-
- spec/graph_ql/
|
322
|
-
- spec/graph_ql/parser/visitor_spec.rb
|
331
|
+
- spec/graph_ql/object_type_spec.rb
|
332
|
+
- spec/graph_ql/parser_spec.rb
|
323
333
|
- spec/graph_ql/query/operation_resolver_spec.rb
|
324
334
|
- spec/graph_ql/query_spec.rb
|
325
|
-
- spec/graph_ql/scalars/id_type_spec.rb
|
326
335
|
- spec/graph_ql/schema/field_validator_spec.rb
|
327
336
|
- spec/graph_ql/schema/type_reducer_spec.rb
|
328
337
|
- spec/graph_ql/schema/type_validator_spec.rb
|
@@ -344,11 +353,11 @@ test_files:
|
|
344
353
|
- spec/graph_ql/static_validation/rules/variables_are_used_and_defined_spec.rb
|
345
354
|
- spec/graph_ql/static_validation/type_stack_spec.rb
|
346
355
|
- spec/graph_ql/static_validation/validator_spec.rb
|
347
|
-
- spec/graph_ql/
|
348
|
-
- spec/graph_ql/
|
349
|
-
- spec/graph_ql/
|
350
|
-
- spec/graph_ql/types/object_type_spec.rb
|
351
|
-
- spec/graph_ql/types/union_spec.rb
|
356
|
+
- spec/graph_ql/transform_spec.rb
|
357
|
+
- spec/graph_ql/union_type_spec.rb
|
358
|
+
- spec/graph_ql/visitor_spec.rb
|
352
359
|
- spec/spec_helper.rb
|
353
|
-
- spec/support/
|
354
|
-
- spec/support/
|
360
|
+
- spec/support/dairy_app.rb
|
361
|
+
- spec/support/dairy_data.rb
|
362
|
+
- spec/support/star_wars_data.rb
|
363
|
+
- spec/support/star_wars_schema.rb
|