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,4 +1,4 @@
1
- Cheese = Struct.new(:id, :flavor, :fatContent, :source)
1
+ Cheese = Struct.new(:id, :flavor, :fat_content, :source)
2
2
  CHEESES = {
3
3
  1 => Cheese.new(1, "Brie", 0.19, 1),
4
4
  2 => Cheese.new(2, "Gouda", 0.3, 1),
@@ -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.new do |e|
6
- e.name("Episode")
7
- e.description("One of the films in the Star Wars Trilogy.")
5
+ EpisodeEnum = GraphQL::EnumType.define do
6
+ name("Episode")
7
+ description("One of the films in the Star Wars Trilogy.")
8
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)
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.new do |i, types, field|
15
- i.name("Character")
16
- i.description("A character in the Star Wars Trilogy.")
14
+ CharacterInterface = GraphQL::InterfaceType.define do
15
+ name("Character")
16
+ description("A character in the Star Wars Trilogy.")
17
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
- })
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.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])
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.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])
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.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
- })
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.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-10 00:00:00.000000000 Z
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