graphql 0.1.0 → 0.2.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 (108) hide show
  1. checksums.yaml +4 -4
  2. data/lib/graph_ql/directive.rb +9 -5
  3. data/lib/graph_ql/directives/include_directive.rb +2 -2
  4. data/lib/graph_ql/directives/skip_directive.rb +2 -2
  5. data/lib/graph_ql/enum.rb +5 -8
  6. data/lib/graph_ql/field.rb +50 -0
  7. data/lib/graph_ql/interface.rb +4 -0
  8. data/lib/graph_ql/introspection/arguments_field.rb +2 -2
  9. data/lib/graph_ql/introspection/directive_type.rb +10 -10
  10. data/lib/graph_ql/introspection/enum_value_type.rb +11 -8
  11. data/lib/graph_ql/introspection/enum_values_field.rb +5 -5
  12. data/lib/graph_ql/introspection/field_type.rb +14 -10
  13. data/lib/graph_ql/introspection/fields_field.rb +4 -4
  14. data/lib/graph_ql/introspection/input_fields_field.rb +3 -3
  15. data/lib/graph_ql/introspection/input_value_type.rb +8 -8
  16. data/lib/graph_ql/introspection/interfaces_field.rb +5 -0
  17. data/lib/graph_ql/introspection/of_type_field.rb +3 -9
  18. data/lib/graph_ql/introspection/possible_types_field.rb +3 -10
  19. data/lib/graph_ql/introspection/schema_type.rb +8 -14
  20. data/lib/graph_ql/introspection/type_kind_enum.rb +1 -1
  21. data/lib/graph_ql/introspection/type_type.rb +17 -19
  22. data/lib/graph_ql/introspection/typename_field.rb +15 -0
  23. data/lib/graph_ql/parser.rb +9 -0
  24. data/lib/graph_ql/parser/nodes.rb +17 -7
  25. data/lib/graph_ql/parser/parser.rb +7 -7
  26. data/lib/graph_ql/parser/transform.rb +23 -20
  27. data/lib/graph_ql/parser/visitor.rb +29 -13
  28. data/lib/graph_ql/query.rb +39 -16
  29. data/lib/graph_ql/query/field_resolution_strategy.rb +15 -11
  30. data/lib/graph_ql/query/type_resolver.rb +4 -2
  31. data/lib/graph_ql/repl.rb +1 -1
  32. data/lib/graph_ql/schema.rb +19 -7
  33. data/lib/graph_ql/schema/each_item_validator.rb +12 -0
  34. data/lib/graph_ql/schema/field_validator.rb +13 -0
  35. data/lib/graph_ql/schema/implementation_validator.rb +21 -0
  36. data/lib/graph_ql/schema/schema_validator.rb +10 -0
  37. data/lib/graph_ql/schema/type_reducer.rb +6 -6
  38. data/lib/graph_ql/schema/type_validator.rb +47 -0
  39. data/lib/graph_ql/static_validation.rb +18 -0
  40. data/lib/graph_ql/static_validation/argument_literals_are_compatible.rb +13 -0
  41. data/lib/graph_ql/static_validation/arguments_are_defined.rb +10 -0
  42. data/lib/graph_ql/static_validation/arguments_validator.rb +16 -0
  43. data/lib/graph_ql/static_validation/directives_are_defined.rb +18 -0
  44. data/lib/graph_ql/static_validation/fields_are_defined_on_type.rb +29 -0
  45. data/lib/graph_ql/static_validation/fields_have_appropriate_selections.rb +31 -0
  46. data/lib/graph_ql/static_validation/fields_will_merge.rb +93 -0
  47. data/lib/graph_ql/static_validation/fragment_types_exist.rb +24 -0
  48. data/lib/graph_ql/static_validation/fragments_are_used.rb +30 -0
  49. data/lib/graph_ql/static_validation/literal_validator.rb +27 -0
  50. data/lib/graph_ql/static_validation/message.rb +29 -0
  51. data/lib/graph_ql/static_validation/required_arguments_are_present.rb +13 -0
  52. data/lib/graph_ql/static_validation/type_stack.rb +87 -0
  53. data/lib/graph_ql/static_validation/validator.rb +48 -0
  54. data/lib/graph_ql/type_kinds.rb +50 -12
  55. data/lib/graph_ql/types/argument_definer.rb +7 -0
  56. data/lib/graph_ql/types/boolean_type.rb +3 -3
  57. data/lib/graph_ql/types/field_definer.rb +19 -0
  58. data/lib/graph_ql/types/float_type.rb +3 -3
  59. data/lib/graph_ql/types/input_object_type.rb +4 -0
  60. data/lib/graph_ql/types/input_value.rb +1 -1
  61. data/lib/graph_ql/types/int_type.rb +4 -4
  62. data/lib/graph_ql/types/list_type.rb +5 -1
  63. data/lib/graph_ql/types/non_null_type.rb +4 -0
  64. data/lib/graph_ql/types/object_type.rb +9 -20
  65. data/lib/graph_ql/types/scalar_type.rb +4 -0
  66. data/lib/graph_ql/types/string_type.rb +3 -3
  67. data/lib/graph_ql/types/type_definer.rb +5 -9
  68. data/lib/graph_ql/union.rb +6 -17
  69. data/lib/graph_ql/version.rb +1 -1
  70. data/lib/graphql.rb +58 -78
  71. data/readme.md +80 -7
  72. data/spec/graph_ql/interface_spec.rb +15 -1
  73. data/spec/graph_ql/introspection/directive_type_spec.rb +2 -2
  74. data/spec/graph_ql/introspection/schema_type_spec.rb +2 -1
  75. data/spec/graph_ql/introspection/type_type_spec.rb +16 -1
  76. data/spec/graph_ql/parser/parser_spec.rb +3 -1
  77. data/spec/graph_ql/parser/transform_spec.rb +12 -2
  78. data/spec/graph_ql/parser/visitor_spec.rb +13 -5
  79. data/spec/graph_ql/query_spec.rb +25 -13
  80. data/spec/graph_ql/schema/field_validator_spec.rb +21 -0
  81. data/spec/graph_ql/schema/type_reducer_spec.rb +2 -2
  82. data/spec/graph_ql/schema/type_validator_spec.rb +54 -0
  83. data/spec/graph_ql/static_validation/argument_literals_are_compatible_spec.rb +41 -0
  84. data/spec/graph_ql/static_validation/arguments_are_defined_spec.rb +40 -0
  85. data/spec/graph_ql/static_validation/directives_are_defined_spec.rb +33 -0
  86. data/spec/graph_ql/static_validation/fields_are_defined_on_type_spec.rb +59 -0
  87. data/spec/graph_ql/static_validation/fields_have_appropriate_selections_spec.rb +30 -0
  88. data/spec/graph_ql/{validations → static_validation}/fields_will_merge_spec.rb +24 -17
  89. data/spec/graph_ql/static_validation/fragment_types_exist_spec.rb +38 -0
  90. data/spec/graph_ql/static_validation/fragments_are_used_spec.rb +24 -0
  91. data/spec/graph_ql/static_validation/required_arguments_are_present_spec.rb +41 -0
  92. data/spec/graph_ql/static_validation/type_stack_spec.rb +35 -0
  93. data/spec/graph_ql/static_validation/validator_spec.rb +28 -0
  94. data/spec/graph_ql/types/object_type_spec.rb +1 -1
  95. data/spec/graph_ql/union_spec.rb +1 -14
  96. data/spec/support/dummy_app.rb +75 -53
  97. metadata +53 -31
  98. data/lib/graph_ql/fields/abstract_field.rb +0 -37
  99. data/lib/graph_ql/fields/access_field.rb +0 -24
  100. data/lib/graph_ql/fields/field.rb +0 -34
  101. data/lib/graph_ql/types/abstract_type.rb +0 -14
  102. data/lib/graph_ql/validations/fields_are_defined_on_type.rb +0 -44
  103. data/lib/graph_ql/validations/fields_will_merge.rb +0 -80
  104. data/lib/graph_ql/validations/fragments_are_used.rb +0 -24
  105. data/lib/graph_ql/validator.rb +0 -29
  106. data/spec/graph_ql/validations/fields_are_defined_on_type_spec.rb +0 -28
  107. data/spec/graph_ql/validations/fragments_are_used_spec.rb +0 -28
  108. data/spec/graph_ql/validator_spec.rb +0 -24
@@ -0,0 +1,38 @@
1
+ require 'spec_helper'
2
+
3
+ describe GraphQL::StaticValidation::FragmentTypesExist do
4
+ let(:document) { GraphQL.parse("
5
+ query getCheese {
6
+ cheeese(id: 1) {
7
+ ... on Cheese { source }
8
+ ... on Nothing { whatever }
9
+ ... somethingFields
10
+ ... cheeseFields
11
+ }
12
+ }
13
+
14
+ fragment somethingFields on Something {
15
+ something
16
+ }
17
+ fragment cheeseFields on Cheese {
18
+ fatContent
19
+ }
20
+ ")}
21
+
22
+ let(:validator) { GraphQL::StaticValidation::Validator.new(schema: DummySchema, validators: [GraphQL::StaticValidation::FragmentTypesExist]) }
23
+ let(:errors) { validator.validate(document) }
24
+
25
+ it 'finds non-existent types on fragments' do
26
+ assert_equal(2, errors.length)
27
+ inline_fragment_error = {
28
+ "message"=>"No such type Something, so it can't be a fragment condition",
29
+ "locations"=>[{"line"=>11, "column"=>5}]
30
+ }
31
+ assert_includes(errors, inline_fragment_error, "on inline fragments")
32
+ fragment_def_error = {
33
+ "message"=>"No such type Nothing, so it can't be a fragment condition",
34
+ "locations"=>[{"line"=>5, "column"=>9}]
35
+ }
36
+ assert_includes(errors, fragment_def_error, "on fragment definitions")
37
+ end
38
+ end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ describe GraphQL::StaticValidation::FragmentsAreUsed do
4
+ let(:document) { GraphQL.parse("
5
+ query getCheese {
6
+ name,
7
+ ...cheeseFields
8
+ ...undefinedFields
9
+ }
10
+ fragment cheeseFields on Cheese { fatContent }
11
+ fragment unusedFields on Cheese { is, not, used }
12
+ ")}
13
+
14
+ let(:validator) { GraphQL::StaticValidation::Validator.new(schema: DummySchema, validators: [GraphQL::StaticValidation::FragmentsAreUsed]) }
15
+ let(:errors) { validator.validate(document) }
16
+
17
+ it 'adds errors for unused fragment definitions' do
18
+ assert_includes(errors, {"message"=>"Fragment unusedFields was defined, but not used", "locations"=>[{"line"=>8, "column"=>5}]})
19
+ end
20
+
21
+ it 'adds errors for undefined fragment spreads' do
22
+ assert_includes(errors, {"message"=>"Fragment undefinedFields was used, but not defined", "locations"=>[{"line"=>5, "column"=>7}]})
23
+ end
24
+ end
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+
3
+ describe GraphQL::StaticValidation::RequiredArgumentsArePresent do
4
+ let(:document) { GraphQL.parse("
5
+ query getCheese {
6
+ cheese(id: 1) { source }
7
+ cheese { source }
8
+ }
9
+
10
+ fragment cheeseFields on Cheese {
11
+ similarCheeses(id: 1)
12
+ flavor @include(if: true)
13
+ id @skip
14
+ }
15
+ ")}
16
+
17
+ let(:validator) { GraphQL::StaticValidation::Validator.new(schema: DummySchema, validators: [GraphQL::StaticValidation::RequiredArgumentsArePresent]) }
18
+ let(:errors) { validator.validate(document) }
19
+
20
+ it 'finds undefined arguments to fields and directives' do
21
+ assert_equal(3, errors.length)
22
+
23
+ query_root_error = {
24
+ "message"=>"Field 'cheese' is missing required arguments: id",
25
+ "locations"=>[{"line"=>4, "column"=>7}]
26
+ }
27
+ assert_includes(errors, query_root_error)
28
+
29
+ fragment_error = {
30
+ "message"=>"Field 'similarCheeses' is missing required arguments: source",
31
+ "locations"=>[{"line"=>8, "column"=>7}]
32
+ }
33
+ assert_includes(errors, fragment_error)
34
+
35
+ directive_error = {
36
+ "message"=>"Directive 'skip' is missing required arguments: if",
37
+ "locations"=>[{"line"=>10, "column"=>11}]
38
+ }
39
+ assert_includes(errors, directive_error)
40
+ end
41
+ end
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+
3
+ class TypeCheckValidator
4
+ def self.checks
5
+ @checks ||= []
6
+ end
7
+
8
+ def validate(context)
9
+ self.class.checks.clear
10
+ context.visitor[GraphQL::Nodes::Field] << -> (node, parent) {
11
+ self.class.checks << context.object_types.map(&:name)
12
+ }
13
+ end
14
+ end
15
+
16
+ describe GraphQL::StaticValidation::TypeStack do
17
+ let(:query_string) {%|
18
+ query getCheese {
19
+ cheese(id: 1) { id, ... edibleFields }
20
+ }
21
+ fragment edibleFields on Edible { fatContent }
22
+ |}
23
+ let(:document) { GraphQL.parse(query_string) }
24
+ let(:validator) { GraphQL::StaticValidation::Validator.new(schema: DummySchema, validators: [TypeCheckValidator]) }
25
+
26
+ it 'stores up types' do
27
+ validator.validate(document)
28
+ expected = [
29
+ ["Query", "Cheese"],
30
+ ["Query", "Cheese", "Non-Null"],
31
+ ["Edible", "Non-Null"]
32
+ ]
33
+ assert_equal(expected, TypeCheckValidator.checks)
34
+ end
35
+ end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ class SchemaErrorValidator
4
+ def validate(context)
5
+ context.errors << GraphQL::StaticValidation::Message.new("Something is wrong: #{context.schema}", line: 100, col: 4)
6
+ end
7
+ end
8
+
9
+ class DocumentErrorValidator
10
+ include
11
+ def validate(context)
12
+ context.errors << GraphQL::StaticValidation::Message.new("Something is wrong: #{context.document.name}", line: 1, col: 1)
13
+ end
14
+ end
15
+
16
+ describe GraphQL::StaticValidation::Validator do
17
+ let(:document) { OpenStruct.new(name: "This is not a document", children: []) }
18
+ let(:validator) { GraphQL::StaticValidation::Validator.new(schema: "This is not a schema", validators: [SchemaErrorValidator, DocumentErrorValidator]) }
19
+
20
+ it 'uses validators' do
21
+ errors = validator.validate(document)
22
+ expected_errors = [
23
+ {"message" => "Something is wrong: This is not a schema", "locations" => [{"line" => 100, "column" => 4}]},
24
+ {"message" => "Something is wrong: This is not a document", "locations" => [{"line" => 1, "column" => 1}]}
25
+ ]
26
+ assert_equal(expected_errors, errors)
27
+ end
28
+ end
@@ -15,7 +15,7 @@ describe GraphQL::ObjectType do
15
15
  end
16
16
 
17
17
  it 'may have interfaces' do
18
- assert_equal([Edible, AnimalProduct], type.interfaces)
18
+ assert_equal([EdibleInterface, AnimalProductInterface], type.interfaces)
19
19
  end
20
20
 
21
21
  it 'becomes non-null with !' do
@@ -3,24 +3,11 @@ require 'spec_helper'
3
3
  describe GraphQL::Union 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::Union.new("MyUnion", [type_1, type_2]) }
6
+ let(:union) { GraphQL::Union.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
10
10
 
11
- it 'identifies members' do
12
- assert(union.include?(type_1))
13
- assert(!union.include?(:type_3))
14
- end
15
-
16
- it 'must be 2+ types' do
17
- assert_raises(ArgumentError) { GraphQL::Union.new("Something", [type_1])}
18
- end
19
-
20
- it 'must be all object types' do
21
- assert_raises(ArgumentError) { GraphQL::Union.new("Something", [type_1, type_2, union])}
22
- end
23
-
24
11
  it 'infers type from an object' do
25
12
  assert_equal(CheeseType, DairyProductUnion.resolve_type(CHEESES[1]))
26
13
  end
@@ -1,18 +1,21 @@
1
1
  require_relative './dummy_data'
2
2
 
3
- Edible = GraphQL::Interface.new do
4
- name "Edible"
5
- description "Something you can eat, yum"
6
- fields({
7
- fatContent: field(type: !type.Float, desc: "Percentage which is fat"),
3
+ EdibleInterface = GraphQL::Interface.new do |i, type, field|
4
+ i.name "Edible"
5
+ i.description "Something you can eat, yum"
6
+ i.fields({
7
+ fatContent: field.build(
8
+ type: !type.Float,
9
+ property: :non_existent_field_that_should_never_be_called,
10
+ desc: "Percentage which is fat"),
8
11
  })
9
12
  end
10
13
 
11
- AnimalProduct = GraphQL::Interface.new do
12
- name "AnimalProduct"
13
- description "Comes from an animal, no joke"
14
- fields({
15
- source: field(type: !type.String, desc: "Animal which produced this product"),
14
+ AnimalProductInterface = GraphQL::Interface.new do |i, type, field|
15
+ i.name "AnimalProduct"
16
+ i.description "Comes from an animal, no joke"
17
+ i.fields({
18
+ source: field.build(type: !type.String, desc: "Animal which produced this product"),
16
19
  })
17
20
  end
18
21
 
@@ -25,52 +28,64 @@ DairyAnimalEnum = GraphQL::Enum.new do |e|
25
28
  e.value("YAK", "Animal with long hair", deprecation_reason: "Out of fashion")
26
29
  end
27
30
 
28
- CheeseType = GraphQL::ObjectType.new do
29
- name "Cheese"
30
- description "Cultured dairy product"
31
- interfaces [Edible, AnimalProduct]
32
- self.fields = {
33
- id: field(type: !type.Int, desc: "Unique identifier"),
34
- flavor: field(type: !type.String, desc: "Kind of cheese"),
35
- source: field(type: !DairyAnimalEnum, desc: "Animal which produced the milk for this cheese"),
36
- fatContent: field(type: !type.Float, desc: "Percentage which is milkfat", deprecation_reason: "Diet fashion has changed"),
31
+ CheeseType = GraphQL::ObjectType.new do |t, type, field, arg|
32
+ t.name "Cheese"
33
+ t.description "Cultured dairy product"
34
+ t.interfaces [EdibleInterface, AnimalProductInterface]
35
+ t.fields = {
36
+ id: field.build(type: !type.Int, desc: "Unique identifier"),
37
+ flavor: field.build(type: !type.String, desc: "Kind of cheese"),
38
+ source: field.build(type: !DairyAnimalEnum, desc: "Animal which produced the milk for this cheese"),
39
+ similarCheeses: GraphQL::Field.new do |f|
40
+ f.description "Cheeses like this one"
41
+ f.type(t)
42
+ f.arguments({source: arg.build(type: !type[!DairyAnimalEnum])})
43
+ f.resolve -> (t, a, c) { CHEESES.values.find { |c| c.source == a["source"] } }
44
+ end,
45
+ fatContent: field.build(type: !type.Float, desc: "Percentage which is milkfat", deprecation_reason: "Diet fashion has changed"),
37
46
  }
38
47
  end
39
48
 
40
- MilkType = GraphQL::ObjectType.new do
41
- name 'Milk'
42
- description "Dairy beverage"
43
- interfaces [Edible, AnimalProduct]
44
- self.fields = {
45
- id: field(type: !type.Int, desc: "Unique identifier"),
46
- source: field(type: DairyAnimalEnum, desc: "Animal which produced this milk"),
47
- fatContent: field(type: !type.Float, desc: "Percentage which is milkfat"),
48
- flavors: field(
49
+ MilkType = GraphQL::ObjectType.new do |t, type, field, arg|
50
+ t.name 'Milk'
51
+ t.description "Dairy beverage"
52
+ t.interfaces [EdibleInterface, AnimalProductInterface]
53
+ t.fields = {
54
+ id: field.build(type: !type.Int, desc: "Unique identifier"),
55
+ source: field.build(type: DairyAnimalEnum, desc: "Animal which produced this milk"),
56
+ fatContent: field.build(type: !type.Float, desc: "Percentage which is milkfat"),
57
+ flavors: field.build(
49
58
  type: type[type.String],
50
59
  desc: "Chocolate, Strawberry, etc",
51
- args: {limit: {type: type.Int}}
60
+ args: {limit: arg.build({type: type.Int})}
52
61
  ),
53
62
  }
54
63
  end
55
64
 
56
- DairyProductUnion = GraphQL::Union.new("DairyProduct", [MilkType, CheeseType])
57
-
58
- DairyProductInputType = GraphQL::InputObjectType.new {
59
- name "DairyProductInput"
60
- description "Properties for finding a dairy product"
61
- input_fields({
62
- source: arg({type: DairyAnimalEnum}),
63
- fatContent: arg({type: type.Float}),
65
+ DairyProductUnion = GraphQL::Union.new(
66
+ "DairyProduct",
67
+ "Kinds of food made from milk",
68
+ [MilkType, CheeseType]
69
+ )
70
+
71
+ DairyProductInputType = GraphQL::InputObjectType.new {|t, type, field, arg|
72
+ t.name "DairyProductInput"
73
+ t.description "Properties for finding a dairy product"
74
+ t.input_fields({
75
+ source: arg.build({type: DairyAnimalEnum}),
76
+ fatContent: arg.build({type: type.Float}),
64
77
  })
65
78
  }
66
79
 
67
80
 
68
- class FetchField < GraphQL::AbstractField
69
- attr_reader :type
81
+ class FetchField
82
+ attr_reader :type, :arguments, :deprecation_reason
70
83
  attr_accessor :name
71
84
  def initialize(type:, data:)
72
85
  @type = type
73
86
  @data = data
87
+ @arguments = {"id" => GraphQL::InputValue.new(type: !GraphQL::INT_TYPE, name: "id")}
88
+ @deprecation_reason = nil
74
89
  end
75
90
 
76
91
  def description
@@ -82,9 +97,10 @@ class FetchField < GraphQL::AbstractField
82
97
  end
83
98
  end
84
99
 
85
- SourceField = GraphQL::Field.new do |f|
100
+ SourceField = GraphQL::Field.new do |f, type, field, arg|
86
101
  f.type GraphQL::ListType.new(of_type: CheeseType)
87
102
  f.description "Cheese from source"
103
+ f.arguments(source: arg.build(type: !DairyAnimalEnum))
88
104
  f.resolve -> (target, arguments, context) {
89
105
  CHEESES.values.select{ |c| c.source == arguments["source"] }
90
106
  }
@@ -92,23 +108,23 @@ end
92
108
 
93
109
  FavoriteField = GraphQL::Field.new do |f|
94
110
  f.description "My favorite food"
95
- f.type Edible
111
+ f.type EdibleInterface
96
112
  f.resolve -> (t, a, c) { MILKS[1] }
97
113
  end
98
114
 
99
115
 
100
- QueryType = GraphQL::ObjectType.new do
101
- name "Query"
102
- description "Query root of the system"
103
- fields({
116
+ QueryType = GraphQL::ObjectType.new do |t, types, field, arg|
117
+ t.name "Query"
118
+ t.description "Query root of the system"
119
+ t.fields({
104
120
  cheese: FetchField.new(type: CheeseType, data: CHEESES),
105
121
  fromSource: SourceField,
106
122
  favoriteEdible: FavoriteField,
107
123
  searchDairy: GraphQL::Field.new { |f|
108
124
  f.name "searchDairy"
109
125
  f.description "Find dairy products matching a description"
110
- f.type DairyProductUnion
111
- f.arguments({product: {type: DairyProductInputType}})
126
+ f.type !DairyProductUnion
127
+ f.arguments({product: arg.build({type: DairyProductInputType})})
112
128
  f.resolve -> (t, a, c) {
113
129
  products = CHEESES.values + MILKS.values
114
130
  source = a["product"]["source"]
@@ -117,20 +133,25 @@ QueryType = GraphQL::ObjectType.new do
117
133
  end
118
134
  products.first
119
135
  }
120
- }
136
+ },
137
+ error: GraphQL::Field.new { |f|
138
+ f.description "Raise an error"
139
+ f.type GraphQL::STRING_TYPE
140
+ f.resolve -> (t, a, c) { raise("This error was raised on purpose") }
141
+ },
121
142
  })
122
143
  end
123
144
 
124
145
  GLOBAL_VALUES = []
125
146
 
126
- MutationType = GraphQL::ObjectType.new do
127
- name "Mutation"
128
- description "The root for mutations in this schema"
129
- fields({
147
+ MutationType = GraphQL::ObjectType.new do |t, type, field, arg|
148
+ t.name "Mutation"
149
+ t.description "The root for mutations in this schema"
150
+ t.fields({
130
151
  pushValue: GraphQL::Field.new { |f|
131
152
  f.description("Push a value onto a global array :D")
132
153
  f.type(!type[!type.Int])
133
- f.arguments(value: arg(type: !type.Int))
154
+ f.arguments(value: arg.build(type: !type.Int))
134
155
  f.resolve -> (o, args, ctx) {
135
156
  GLOBAL_VALUES << args["value"]
136
157
  GLOBAL_VALUES
@@ -138,4 +159,5 @@ MutationType = GraphQL::ObjectType.new do
138
159
  }
139
160
  })
140
161
  end
162
+
141
163
  DummySchema = GraphQL::Schema.new(query: QueryType, mutation: MutationType)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: graphql
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Mosolgo
@@ -10,20 +10,6 @@ bindir: bin
10
10
  cert_chain: []
11
11
  date: 2015-03-06 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: activesupport
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '4'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '4'
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: parslet
29
15
  requirement: !ruby/object:Gem::Requirement
@@ -177,9 +163,7 @@ files:
177
163
  - lib/graph_ql/directives/include_directive.rb
178
164
  - lib/graph_ql/directives/skip_directive.rb
179
165
  - lib/graph_ql/enum.rb
180
- - lib/graph_ql/fields/abstract_field.rb
181
- - lib/graph_ql/fields/access_field.rb
182
- - lib/graph_ql/fields/field.rb
166
+ - lib/graph_ql/field.rb
183
167
  - lib/graph_ql/interface.rb
184
168
  - lib/graph_ql/introspection/arguments_field.rb
185
169
  - lib/graph_ql/introspection/directive_type.rb
@@ -189,11 +173,14 @@ files:
189
173
  - lib/graph_ql/introspection/fields_field.rb
190
174
  - lib/graph_ql/introspection/input_fields_field.rb
191
175
  - lib/graph_ql/introspection/input_value_type.rb
176
+ - lib/graph_ql/introspection/interfaces_field.rb
192
177
  - lib/graph_ql/introspection/of_type_field.rb
193
178
  - lib/graph_ql/introspection/possible_types_field.rb
194
179
  - lib/graph_ql/introspection/schema_type.rb
195
180
  - lib/graph_ql/introspection/type_kind_enum.rb
196
181
  - lib/graph_ql/introspection/type_type.rb
182
+ - lib/graph_ql/introspection/typename_field.rb
183
+ - lib/graph_ql/parser.rb
197
184
  - lib/graph_ql/parser/nodes.rb
198
185
  - lib/graph_ql/parser/parser.rb
199
186
  - lib/graph_ql/parser/transform.rb
@@ -208,10 +195,31 @@ files:
208
195
  - lib/graph_ql/query/type_resolver.rb
209
196
  - lib/graph_ql/repl.rb
210
197
  - lib/graph_ql/schema.rb
198
+ - lib/graph_ql/schema/each_item_validator.rb
199
+ - lib/graph_ql/schema/field_validator.rb
200
+ - lib/graph_ql/schema/implementation_validator.rb
201
+ - lib/graph_ql/schema/schema_validator.rb
211
202
  - lib/graph_ql/schema/type_reducer.rb
203
+ - lib/graph_ql/schema/type_validator.rb
204
+ - lib/graph_ql/static_validation.rb
205
+ - lib/graph_ql/static_validation/argument_literals_are_compatible.rb
206
+ - lib/graph_ql/static_validation/arguments_are_defined.rb
207
+ - lib/graph_ql/static_validation/arguments_validator.rb
208
+ - lib/graph_ql/static_validation/directives_are_defined.rb
209
+ - lib/graph_ql/static_validation/fields_are_defined_on_type.rb
210
+ - lib/graph_ql/static_validation/fields_have_appropriate_selections.rb
211
+ - lib/graph_ql/static_validation/fields_will_merge.rb
212
+ - lib/graph_ql/static_validation/fragment_types_exist.rb
213
+ - lib/graph_ql/static_validation/fragments_are_used.rb
214
+ - lib/graph_ql/static_validation/literal_validator.rb
215
+ - lib/graph_ql/static_validation/message.rb
216
+ - lib/graph_ql/static_validation/required_arguments_are_present.rb
217
+ - lib/graph_ql/static_validation/type_stack.rb
218
+ - lib/graph_ql/static_validation/validator.rb
212
219
  - lib/graph_ql/type_kinds.rb
213
- - lib/graph_ql/types/abstract_type.rb
220
+ - lib/graph_ql/types/argument_definer.rb
214
221
  - lib/graph_ql/types/boolean_type.rb
222
+ - lib/graph_ql/types/field_definer.rb
215
223
  - lib/graph_ql/types/float_type.rb
216
224
  - lib/graph_ql/types/input_object_type.rb
217
225
  - lib/graph_ql/types/input_value.rb
@@ -224,10 +232,6 @@ files:
224
232
  - lib/graph_ql/types/string_type.rb
225
233
  - lib/graph_ql/types/type_definer.rb
226
234
  - lib/graph_ql/union.rb
227
- - lib/graph_ql/validations/fields_are_defined_on_type.rb
228
- - lib/graph_ql/validations/fields_will_merge.rb
229
- - lib/graph_ql/validations/fragments_are_used.rb
230
- - lib/graph_ql/validator.rb
231
235
  - lib/graph_ql/version.rb
232
236
  - lib/graphql.rb
233
237
  - readme.md
@@ -243,14 +247,23 @@ files:
243
247
  - spec/graph_ql/parser/visitor_spec.rb
244
248
  - spec/graph_ql/query/operation_resolver_spec.rb
245
249
  - spec/graph_ql/query_spec.rb
250
+ - spec/graph_ql/schema/field_validator_spec.rb
246
251
  - spec/graph_ql/schema/type_reducer_spec.rb
252
+ - spec/graph_ql/schema/type_validator_spec.rb
253
+ - spec/graph_ql/static_validation/argument_literals_are_compatible_spec.rb
254
+ - spec/graph_ql/static_validation/arguments_are_defined_spec.rb
255
+ - spec/graph_ql/static_validation/directives_are_defined_spec.rb
256
+ - spec/graph_ql/static_validation/fields_are_defined_on_type_spec.rb
257
+ - spec/graph_ql/static_validation/fields_have_appropriate_selections_spec.rb
258
+ - spec/graph_ql/static_validation/fields_will_merge_spec.rb
259
+ - spec/graph_ql/static_validation/fragment_types_exist_spec.rb
260
+ - spec/graph_ql/static_validation/fragments_are_used_spec.rb
261
+ - spec/graph_ql/static_validation/required_arguments_are_present_spec.rb
262
+ - spec/graph_ql/static_validation/type_stack_spec.rb
263
+ - spec/graph_ql/static_validation/validator_spec.rb
247
264
  - spec/graph_ql/types/input_object_type_spec.rb
248
265
  - spec/graph_ql/types/object_type_spec.rb
249
266
  - spec/graph_ql/union_spec.rb
250
- - spec/graph_ql/validations/fields_are_defined_on_type_spec.rb
251
- - spec/graph_ql/validations/fields_will_merge_spec.rb
252
- - spec/graph_ql/validations/fragments_are_used_spec.rb
253
- - spec/graph_ql/validator_spec.rb
254
267
  - spec/spec_helper.rb
255
268
  - spec/support/dummy_app.rb
256
269
  - spec/support/dummy_data.rb
@@ -291,14 +304,23 @@ test_files:
291
304
  - spec/graph_ql/parser/visitor_spec.rb
292
305
  - spec/graph_ql/query/operation_resolver_spec.rb
293
306
  - spec/graph_ql/query_spec.rb
307
+ - spec/graph_ql/schema/field_validator_spec.rb
294
308
  - spec/graph_ql/schema/type_reducer_spec.rb
309
+ - spec/graph_ql/schema/type_validator_spec.rb
310
+ - spec/graph_ql/static_validation/argument_literals_are_compatible_spec.rb
311
+ - spec/graph_ql/static_validation/arguments_are_defined_spec.rb
312
+ - spec/graph_ql/static_validation/directives_are_defined_spec.rb
313
+ - spec/graph_ql/static_validation/fields_are_defined_on_type_spec.rb
314
+ - spec/graph_ql/static_validation/fields_have_appropriate_selections_spec.rb
315
+ - spec/graph_ql/static_validation/fields_will_merge_spec.rb
316
+ - spec/graph_ql/static_validation/fragment_types_exist_spec.rb
317
+ - spec/graph_ql/static_validation/fragments_are_used_spec.rb
318
+ - spec/graph_ql/static_validation/required_arguments_are_present_spec.rb
319
+ - spec/graph_ql/static_validation/type_stack_spec.rb
320
+ - spec/graph_ql/static_validation/validator_spec.rb
295
321
  - spec/graph_ql/types/input_object_type_spec.rb
296
322
  - spec/graph_ql/types/object_type_spec.rb
297
323
  - spec/graph_ql/union_spec.rb
298
- - spec/graph_ql/validations/fields_are_defined_on_type_spec.rb
299
- - spec/graph_ql/validations/fields_will_merge_spec.rb
300
- - spec/graph_ql/validations/fragments_are_used_spec.rb
301
- - spec/graph_ql/validator_spec.rb
302
324
  - spec/spec_helper.rb
303
325
  - spec/support/dummy_app.rb
304
326
  - spec/support/dummy_data.rb