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.
- checksums.yaml +4 -4
- data/lib/graph_ql/argument.rb +38 -4
- data/lib/graph_ql/boolean_type.rb +3 -5
- data/lib/graph_ql/definition_helpers.rb +1 -0
- data/lib/graph_ql/definition_helpers/defined_by_config.rb +20 -0
- data/lib/graph_ql/enum_type.rb +52 -16
- data/lib/graph_ql/field.rb +79 -14
- data/lib/graph_ql/float_type.rb +3 -3
- data/lib/graph_ql/id_type.rb +3 -5
- data/lib/graph_ql/input_object_type.rb +41 -4
- data/lib/graph_ql/int_type.rb +3 -5
- data/lib/graph_ql/interface_type.rb +36 -8
- data/lib/graph_ql/introspection/arguments_field.rb +4 -4
- data/lib/graph_ql/introspection/directive_type.rb +9 -11
- data/lib/graph_ql/introspection/enum_value_type.rb +9 -12
- data/lib/graph_ql/introspection/enum_values_field.rb +6 -8
- data/lib/graph_ql/introspection/field_type.rb +11 -15
- data/lib/graph_ql/introspection/fields_field.rb +5 -7
- data/lib/graph_ql/introspection/input_fields_field.rb +5 -5
- data/lib/graph_ql/introspection/input_value_type.rb +7 -9
- data/lib/graph_ql/introspection/interfaces_field.rb +4 -4
- data/lib/graph_ql/introspection/of_type_field.rb +5 -5
- data/lib/graph_ql/introspection/possible_types_field.rb +4 -4
- data/lib/graph_ql/introspection/schema_field.rb +6 -8
- data/lib/graph_ql/introspection/schema_type.rb +19 -25
- data/lib/graph_ql/introspection/type_by_name_field.rb +7 -1
- data/lib/graph_ql/introspection/type_kind_enum.rb +4 -4
- data/lib/graph_ql/introspection/type_type.rb +18 -18
- data/lib/graph_ql/introspection/typename_field.rb +6 -10
- data/lib/graph_ql/object_type.rb +87 -12
- data/lib/graph_ql/scalar_type.rb +22 -0
- data/lib/graph_ql/schema.rb +1 -1
- data/lib/graph_ql/string_type.rb +3 -5
- data/lib/graph_ql/union_type.rb +24 -3
- data/lib/graph_ql/version.rb +1 -1
- data/lib/graphql.rb +1 -1
- data/readme.md +66 -64
- data/spec/graph_ql/field_spec.rb +3 -3
- data/spec/support/dairy_app.rb +119 -133
- data/spec/support/dairy_data.rb +1 -1
- data/spec/support/star_wars_schema.rb +50 -57
- metadata +3 -2
data/spec/support/dairy_data.rb
CHANGED
@@ -2,59 +2,55 @@
|
|
2
2
|
# https://github.com/graphql/graphql-js/blob/master/src/__tests__/starWarsSchema.js
|
3
3
|
require_relative './star_wars_data'
|
4
4
|
|
5
|
-
EpisodeEnum = GraphQL::EnumType.
|
6
|
-
|
7
|
-
|
5
|
+
EpisodeEnum = GraphQL::EnumType.define do
|
6
|
+
name("Episode")
|
7
|
+
description("One of the films in the Star Wars Trilogy.")
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
value("NEWHOPE", "Released in 1977", value: 4)
|
10
|
+
value("EMPIRE", "Released in 1980", value: 5)
|
11
|
+
value("JEDI", "Released in 1983", value: 6)
|
12
12
|
end
|
13
13
|
|
14
|
-
CharacterInterface = GraphQL::InterfaceType.
|
15
|
-
|
16
|
-
|
14
|
+
CharacterInterface = GraphQL::InterfaceType.define do
|
15
|
+
name("Character")
|
16
|
+
description("A character in the Star Wars Trilogy.")
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
appearsIn: field.build(type: types[EpisodeEnum], desc: "Which movies they appear in."),
|
23
|
-
})
|
18
|
+
field :id, !types.String, "The id of the character."
|
19
|
+
field :name, types.String, "The name of the Character."
|
20
|
+
field :friends, -> { types[CharacterInterface] }, "The friends of the character, or an empty list if they have none."
|
21
|
+
field :appearsIn, types[EpisodeEnum], "Which movies they appear in."
|
24
22
|
end
|
25
23
|
|
26
|
-
HumanType = GraphQL::ObjectType.
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
t.interfaces([CharacterInterface])
|
24
|
+
HumanType = GraphQL::ObjectType.define do
|
25
|
+
name("Human")
|
26
|
+
description("A humanoid creature in the Star Wars universe.")
|
27
|
+
field :id, !types.String, "The id of the human."
|
28
|
+
field :name, types.String, "The name of the human."
|
29
|
+
field :friends do
|
30
|
+
type(types[CharacterInterface])
|
31
|
+
description("The friends of the human, or an empty list if they have none.")
|
32
|
+
resolve(GET_FRIENDS)
|
33
|
+
end
|
34
|
+
field :appearsIn, types[EpisodeEnum], "Which movies they appear in."
|
35
|
+
field :homePlanet, types.String, "The home planet of the human, or null if unknown."
|
36
|
+
|
37
|
+
interfaces([CharacterInterface])
|
41
38
|
end
|
42
39
|
|
43
|
-
DroidType = GraphQL::ObjectType.
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
t.interfaces([CharacterInterface])
|
40
|
+
DroidType = GraphQL::ObjectType.define do
|
41
|
+
name("Droid")
|
42
|
+
description("A mechanical creature in the Star Wars universe.")
|
43
|
+
field :id, !types.String, "The id of the droid."
|
44
|
+
field :name, types.String, "The name of the droid."
|
45
|
+
field :friends do
|
46
|
+
type(types[CharacterInterface])
|
47
|
+
description("The friends of the droid, or an empty list if they have none.")
|
48
|
+
resolve(GET_FRIENDS)
|
49
|
+
end
|
50
|
+
field :appearsIn, types[EpisodeEnum], "Which movies they appear in."
|
51
|
+
field :primaryFunction, types.String, "The primary function of the droid."
|
52
|
+
|
53
|
+
interfaces([CharacterInterface])
|
58
54
|
end
|
59
55
|
|
60
56
|
class FindRecordField < GraphQL::Field
|
@@ -72,16 +68,13 @@ class FindRecordField < GraphQL::Field
|
|
72
68
|
end
|
73
69
|
|
74
70
|
|
75
|
-
StarWarsQueryType = GraphQL::ObjectType.
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
human: FindRecordField.new(HumanType, HUMAN_DATA),
|
85
|
-
droid: FindRecordField.new(DroidType, DROID_DATA),
|
86
|
-
})
|
71
|
+
StarWarsQueryType = GraphQL::ObjectType.define do
|
72
|
+
name("Query")
|
73
|
+
field :hero do
|
74
|
+
argument :episode, EpisodeEnum, "If omitted, returns the hero of the whole saga. If provided, returns the hero of that particular episode"
|
75
|
+
resolve -> (obj, args, ctx) { args["episode"] == 5 ? luke : artoo }
|
76
|
+
end
|
77
|
+
|
78
|
+
field :human, field: FindRecordField.new(HumanType, HUMAN_DATA)
|
79
|
+
field :droid, field: FindRecordField.new(DroidType, DROID_DATA)
|
87
80
|
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.5.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-08-
|
11
|
+
date: 2015-08-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: parslet
|
@@ -164,6 +164,7 @@ files:
|
|
164
164
|
- lib/graph_ql/definition_helpers.rb
|
165
165
|
- lib/graph_ql/definition_helpers/argument_definer.rb
|
166
166
|
- lib/graph_ql/definition_helpers/definable.rb
|
167
|
+
- lib/graph_ql/definition_helpers/defined_by_config.rb
|
167
168
|
- lib/graph_ql/definition_helpers/field_definer.rb
|
168
169
|
- lib/graph_ql/definition_helpers/non_null_with_bang.rb
|
169
170
|
- lib/graph_ql/definition_helpers/string_named_hash.rb
|