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
@@ -2,4 +2,8 @@ class GraphQL::ScalarType < GraphQL::ObjectType
2
2
  def kind
3
3
  GraphQL::TypeKinds::SCALAR
4
4
  end
5
+
6
+ def to_s
7
+ "<GraphQL::ScalarType #{name} >"
8
+ end
5
9
  end
@@ -1,6 +1,6 @@
1
- GraphQL::STRING_TYPE = GraphQL::ScalarType.new do
2
- name "String"
3
- def coerce(value)
1
+ GraphQL::STRING_TYPE = GraphQL::ScalarType.new do |t|
2
+ t.name "String"
3
+ def t.coerce(value)
4
4
  value.to_s
5
5
  end
6
6
  end
@@ -1,14 +1,10 @@
1
1
  class GraphQL::TypeDefiner
2
- TYPES = {
3
- Int: GraphQL::INT_TYPE,
4
- String: GraphQL::STRING_TYPE,
5
- Float: GraphQL::FLOAT_TYPE,
6
- Boolean: GraphQL::BOOLEAN_TYPE,
7
- }
2
+ include Singleton
8
3
 
9
- TYPES.each do |method_name, type|
10
- define_method(method_name) { type }
11
- end
4
+ def Int; GraphQL::INT_TYPE; end
5
+ def String; GraphQL::STRING_TYPE; end
6
+ def Float; GraphQL::FLOAT_TYPE; end
7
+ def Boolean; GraphQL::BOOLEAN_TYPE; end
12
8
 
13
9
  def [](type)
14
10
  GraphQL::ListType.new(of_type: type)
@@ -1,25 +1,14 @@
1
1
  class GraphQL::Union
2
2
  include GraphQL::NonNullWithBang
3
- attr_reader :name, :possible_types
4
- def initialize(name, types)
5
- if types.length < 2
6
- raise ArgumentError, "Union #{name} must be defined with 2 or more types, not #{types.length}"
7
- end
8
-
9
- non_object_types = types.select {|t| t.kind != GraphQL::TypeKinds::OBJECT}
10
- if non_object_types.any?
11
- types_string = non_object_types.map{|t| "#{t.name} #{t.kind}"}.join(", ")
12
- raise ArgumentError, "Unions can only consist of Object types, but #{name} has non-object types: #{types_string}"
13
- end
14
-
3
+ attr_reader :name, :description, :possible_types
4
+ def initialize(name, desc, types)
15
5
  @name = name
6
+ @description = desc
16
7
  @possible_types = types
17
8
  end
18
9
 
19
- def kind; GraphQL::TypeKinds::UNION; end
20
-
21
- def include?(type)
22
- possible_types.include?(type)
10
+ def kind
11
+ GraphQL::TypeKinds::UNION
23
12
  end
24
13
 
25
14
  # Find a type in this union for a given object.
@@ -30,6 +19,6 @@ class GraphQL::Union
30
19
  end
31
20
 
32
21
  def to_s
33
- "<GraphQL::Union #{name} [#{possible_types.map(&:name).join(", ")}]>"
22
+ "<GraphQL::Union #{name}>"
34
23
  end
35
24
  end
@@ -1,3 +1,3 @@
1
1
  module GraphQL
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -1,84 +1,8 @@
1
- require "active_support/core_ext/object/blank"
2
- require "active_support/core_ext/string/inflections"
3
- require "active_support/dependencies/autoload"
4
1
  require "json"
5
2
  require "parslet"
3
+ require "singleton"
6
4
 
7
5
  module GraphQL
8
- extend ActiveSupport::Autoload
9
- autoload(:Directive)
10
- autoload(:Enum)
11
- autoload(:Interface)
12
- autoload(:Parser)
13
- autoload(:Query)
14
- autoload(:Repl)
15
- autoload(:Schema)
16
- autoload(:TypeKinds)
17
- autoload(:Union)
18
- autoload(:Validator)
19
- autoload(:VERSION)
20
-
21
- autoload_under "directives" do
22
- autoload(:DirectiveChain)
23
- autoload(:IncludeDirective)
24
- autoload(:SkipDirective)
25
- end
26
-
27
- autoload_under "fields" do
28
- autoload(:AbstractField)
29
- autoload(:AccessField)
30
- autoload(:Field)
31
- end
32
-
33
- autoload_under "introspection" do
34
- autoload(:ArgumentsField)
35
- autoload(:DirectiveType)
36
- autoload(:EnumValuesField)
37
- autoload(:EnumValueType)
38
- autoload(:FieldType)
39
- autoload(:FieldsField)
40
- autoload(:InputValueType)
41
- autoload(:InputFieldsField)
42
- autoload(:OfTypeField)
43
- autoload(:PossibleTypesField)
44
- autoload(:SchemaType)
45
- autoload(:TypeKindEnum)
46
- autoload(:TypeType)
47
- end
48
-
49
- autoload_under "parser" do
50
- autoload(:Nodes)
51
- autoload(:Parser)
52
- autoload(:Transform)
53
- autoload(:Visitor)
54
- end
55
-
56
- autoload_under "types" do
57
- autoload(:AbstractType)
58
- autoload(:BOOLEAN_TYPE)
59
- autoload(:ScalarType)
60
- autoload(:FLOAT_TYPE)
61
- autoload(:InputObjectType)
62
- autoload(:InputValue)
63
- autoload(:INT_TYPE)
64
- autoload(:ListType)
65
- autoload(:NonNullType)
66
- autoload(:NonNullWithBang)
67
- autoload(:ObjectType)
68
- autoload(:STRING_TYPE)
69
- autoload(:TypeDefiner)
70
- end
71
-
72
- module Validations
73
- extend ActiveSupport::Autoload
74
- autoload(:FieldsWillMerge)
75
- autoload(:FragmentsAreUsed)
76
- autoload(:FieldsAreDefinedOnType)
77
- end
78
-
79
- PARSER = Parser.new
80
- TRANSFORM = Transform.new
81
-
82
6
  def self.parse(string, as: nil)
83
7
  parser = as ? GraphQL::PARSER.send(as) : GraphQL::PARSER
84
8
  tree = parser.parse(string)
@@ -88,7 +12,6 @@ module GraphQL
88
12
  raise [line, col, string].join(", ")
89
13
  end
90
14
 
91
-
92
15
  module Definable
93
16
  def attr_definable(*names)
94
17
  attr_accessor(*names)
@@ -111,4 +34,61 @@ module GraphQL
111
34
  end
112
35
  end
113
36
  end
37
+
38
+ module Introspection; end
114
39
  end
40
+
41
+ # Order matters for these:
42
+
43
+ require 'graph_ql/types/non_null_with_bang'
44
+ require 'graph_ql/types/object_type'
45
+ require 'graph_ql/types/list_type'
46
+ require 'graph_ql/types/scalar_type'
47
+ require 'graph_ql/types/non_null_type'
48
+ require 'graph_ql/types/input_value'
49
+ require 'graph_ql/types/input_object_type'
50
+
51
+ require 'graph_ql/types/type_definer'
52
+ require 'graph_ql/types/field_definer'
53
+ require 'graph_ql/types/argument_definer'
54
+
55
+ require 'graph_ql/enum'
56
+ require 'graph_ql/field'
57
+ require 'graph_ql/union'
58
+ require 'graph_ql/type_kinds'
59
+ require 'graph_ql/introspection/typename_field'
60
+
61
+ require 'graph_ql/types/int_type'
62
+ require 'graph_ql/types/string_type'
63
+ require 'graph_ql/types/float_type'
64
+ require 'graph_ql/types/boolean_type'
65
+
66
+ require 'graph_ql/introspection/input_value_type'
67
+ require 'graph_ql/introspection/enum_value_type'
68
+ require 'graph_ql/introspection/type_kind_enum'
69
+
70
+ require 'graph_ql/introspection/fields_field'
71
+ require 'graph_ql/introspection/of_type_field'
72
+ require 'graph_ql/introspection/input_fields_field'
73
+ require 'graph_ql/introspection/possible_types_field'
74
+ require 'graph_ql/introspection/enum_values_field'
75
+ require 'graph_ql/introspection/interfaces_field'
76
+
77
+ require 'graph_ql/introspection/type_type'
78
+ require 'graph_ql/introspection/field_type'
79
+
80
+ require 'graph_ql/introspection/arguments_field'
81
+ require 'graph_ql/introspection/directive_type'
82
+ require 'graph_ql/introspection/schema_type'
83
+
84
+ require 'graph_ql/parser'
85
+ require 'graph_ql/directive'
86
+ require 'graph_ql/schema'
87
+
88
+ # Order does not matter for these:
89
+
90
+ require 'graph_ql/interface'
91
+ require 'graph_ql/query'
92
+ require 'graph_ql/repl'
93
+ require 'graph_ql/static_validation'
94
+ require 'graph_ql/version'
data/readme.md CHANGED
@@ -6,23 +6,96 @@
6
6
  [![Test Coverage](https://codeclimate.com/github/rmosolgo/graphql-ruby/badges/coverage.svg)](https://codeclimate.com/github/rmosolgo/graphql-ruby)
7
7
  [![built with love](https://cloud.githubusercontent.com/assets/2231765/6766607/d07992c6-cfc9-11e4-813f-d9240714dd50.png)](http://rmosolgo.github.io/react-badges/)
8
8
 
9
- __Current status__: rewriting according to spec, see also the previous [prototype implementation](https://github.com/rmosolgo/graphql-ruby/tree/74ad3c30a6d8db010ec3856f5871f8a02fcfba42)!
10
-
11
9
  ## Overview
12
10
 
13
- - See the __[test schema](https://github.com/rmosolgo/graphql-ruby/blob/master/spec/support/dummy_app.rb)__ for an example GraphQL schema in Ruby.
14
- - See __[query_spec.rb](https://github.com/rmosolgo/graphql-ruby/blob/master/spec/graph_ql/query_spec.rb)__ for an example of query execution.
11
+ - __Install the gem__:
12
+
13
+ ```ruby
14
+ # Gemfile
15
+ gem 'graphql'
16
+ ```
17
+
18
+ ```
19
+ $ bundle install
20
+ ```
21
+
22
+ - __Declare types & build a schema__:
23
+
24
+ ```ruby
25
+ # Declare a type...
26
+ PostType = GraphQL::ObjectType.new do |t, types, field|
27
+ t.name "Post"
28
+ t.description "A blog post"
29
+ t.fields({
30
+ id: field.build(type: !types.Int)
31
+ title: field.build(type: !types.String),
32
+ body: field.build(type: !types.String),
33
+ comments: field.build(type: types[!CommentType])
34
+ })
35
+ end
36
+
37
+ # ...and a query root
38
+ QueryType = GraphQL::ObjectType.new do |t, types, field, arg|
39
+ t.name "Query"
40
+ t.description "The query root of this schema"
41
+ t.fields({
42
+ post: GraphQL::Field.new do |f|
43
+ f.arguments(id: arg.build(type: !types.Int))
44
+ f.resolve -> (object, args, context) {
45
+ Post.find(args["id"])
46
+ }
47
+ end
48
+ })
49
+ end
50
+
51
+ # Then create your schema
52
+ Schema = GraphQL::Schema.new(query: QueryType, mutation: nil)
53
+ ```
54
+
55
+ See also:
56
+ - the [test schema](https://github.com/rmosolgo/graphql-ruby/blob/master/spec/support/dummy_app.rb)
57
+ - [`graphql-ruby-demo`](https://github.com/rmosolgo/graphql-ruby-demo) for an example schema on Rails
58
+
59
+ - __Execute queries__:
60
+
61
+ ```ruby
62
+ query = GraphQL::Query.new(Schema, query_string)
63
+ result_hash = query.result
64
+ # {
65
+ # "data" => {
66
+ # "post" => {
67
+ # "id" => 1,
68
+ # "title" => "GraphQL is nice"
69
+ # }
70
+ # }
71
+ # }
72
+ ```
73
+
74
+ See also:
75
+ - [query_spec.rb](https://github.com/rmosolgo/graphql-ruby/blob/master/spec/graph_ql/query_spec.rb) for an example of query execution.
76
+ - [`queries_controller.rb`](https://github.com/rmosolgo/graphql-ruby-demo/blob/master/app/controllers/queries_controller.rb) for a Rails example
77
+ - Try it on [heroku](http://graphql-ruby-demo.herokuapp.com)
15
78
 
16
79
  ## To Do:
17
80
 
18
81
  - Validations:
19
- - implement lots of validators
20
- - build error object with position
21
- - Express failure with `errors` key (http://facebook.github.io/graphql/#sec-Errors)
82
+ - Implement validations:
83
+ - [Fragment spreads are on Object/Union/Interface](http://facebook.github.io/graphql/#sec-Fragments-On-Composite-Types)
84
+ - [Fragments don't go infinite](http://facebook.github.io/graphql/#sec-Fragment-spreads-must-not-form-cycles)
85
+ - [Fragment spreads are possible](http://facebook.github.io/graphql/#sec-Fragment-spread-is-possible)
86
+ - [In object scope, object-typed fragments are the same type](http://facebook.github.io/graphql/#sec-Object-Spreads-In-Object-Scope)
87
+ - [In object scope, abstract-typed fragments fit that object](http://facebook.github.io/graphql/#sec-Abstract-Spreads-in-Object-Scope)
88
+ - [In abstract scope, object-typed fragments fit that type](http://facebook.github.io/graphql/#sec-Object-Spreads-In-Abstract-Scope)
89
+ - [In abstract scope, abstract-typed fragments must share a type](http://facebook.github.io/graphql/#sec-Abstract-Spreads-in-Abstract-Scope)
90
+ - everything in [Variables](http://facebook.github.io/graphql/#sec-Validation.Operations.Variables)
22
91
  - directives:
23
92
  - `@skip` has precedence over `@include`
24
93
  - directives on fragments: http://facebook.github.io/graphql/#sec-Fragment-Directives
94
+ - Support any "real" value for enum, not just stringified name (see `Character::EPISODES` in demo)
25
95
  - field merging (https://github.com/graphql/graphql-js/issues/19#issuecomment-118515077)
96
+ - Code clean-up
97
+ - Unify unwrapping types (It's on `TypeKind` but it's still not right)
98
+ - de-dup stringify keys logic in `Field` and `ObjectType` and `Directive`
26
99
 
27
100
  ## Goals:
28
101
 
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe GraphQL::Interface do
4
- let(:interface) { Edible }
4
+ let(:interface) { EdibleInterface }
5
5
  it 'has possible types' do
6
6
  assert_equal([CheeseType, MilkType], interface.possible_types)
7
7
  end
@@ -10,4 +10,18 @@ describe GraphQL::Interface do
10
10
  assert_equal(CheeseType, interface.resolve_type(CHEESES.values.first))
11
11
  assert_equal(MilkType, interface.resolve_type(MILKS.values.first))
12
12
  end
13
+
14
+ describe 'query evaluation' do
15
+ let(:query) { GraphQL::Query.new(DummySchema, query_string, context: {}, params: {"cheeseId" => 2})}
16
+ let(:result) { query.result }
17
+ let(:query_string) {%|
18
+ query fav {
19
+ favoriteEdible { fatContent }
20
+ }
21
+ |}
22
+ it 'gets fields from the type for the given object' do
23
+ expected = {"data"=>{"fav"=>{"favoriteEdible"=>{"fatContent"=>0.04}}}}
24
+ assert_equal(expected, result)
25
+ end
26
+ end
13
27
  end
@@ -1,10 +1,10 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe GraphQL::DirectiveType do
3
+ describe GraphQL::Introspection::DirectiveType do
4
4
  let(:query_string) {%|
5
5
  query getDirectives {
6
6
  __schema {
7
- directives { name, args { name, type { name, ofType { name }} }, onField, onFragment, onOperation }
7
+ directives { name, args { name, type { name, ofType { name } } }, onField, onFragment, onOperation }
8
8
  }
9
9
  }
10
10
  |}
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe GraphQL::SchemaType do
3
+ describe GraphQL::Introspection::SchemaType do
4
4
  let(:query_string) {%|
5
5
  query getSchema {
6
6
  __schema {
@@ -21,6 +21,7 @@ describe GraphQL::SchemaType do
21
21
  {"name"=>"fromSource"},
22
22
  {"name"=>"favoriteEdible"},
23
23
  {"name"=>"searchDairy"},
24
+ {"name"=>"error"},
24
25
  {"name"=>"__typename"},
25
26
  {"name"=>"__type"},
26
27
  {"name"=>"__schema"},
@@ -1,9 +1,10 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe GraphQL::TypeType do
3
+ describe GraphQL::Introspection::TypeType do
4
4
  let(:query_string) {%|
5
5
  query introspectionQuery {
6
6
  cheeseType: __type(name: "Cheese") { name, kind, fields { name, isDeprecated, type { name, ofType { name } } } }
7
+ milkType: __type(name: "Milk") { interfaces { name }, fields { type { name, ofType { name } } } }
7
8
  dairyAnimal: __type(name: "DairyAnimal") { name, kind, enumValues(includeDeprecated: false) { name, isDeprecated } }
8
9
  dairyProduct: __type(name: "DairyProduct") { name, kind, possibleTypes { name } }
9
10
  animalProduct: __type(name: "AnimalProduct") { name, kind, possibleTypes { name }, fields { name } }
@@ -14,6 +15,7 @@ describe GraphQL::TypeType do
14
15
  {"name"=>"id", "isDeprecated" => false, "type" => { "name" => "Non-Null", "ofType" => { "name" => "Int"}}},
15
16
  {"name"=>"flavor", "isDeprecated" => false, "type" => { "name" => "Non-Null", "ofType" => { "name" => "String"}}},
16
17
  {"name"=>"source", "isDeprecated" => false, "type" => { "name" => "Non-Null", "ofType" => { "name" => "DairyAnimal"}}},
18
+ {"name"=>"similarCheeses", "isDeprecated"=>false, "type"=>{"name"=>"Cheese", "ofType"=>nil}},
17
19
  {"name"=>"__typename", "isDeprecated"=>false, "type"=> { "name" => "Non-Null", "ofType" => { "name" => "String"}}},
18
20
  ]}
19
21
 
@@ -29,6 +31,19 @@ describe GraphQL::TypeType do
29
31
  "kind" => "OBJECT",
30
32
  "fields"=> cheese_fields
31
33
  },
34
+ "milkType"=>{
35
+ "interfaces"=>[
36
+ {"name"=>"Edible"},
37
+ {"name"=>"AnimalProduct"}
38
+ ],
39
+ "fields"=>[
40
+ {"type"=>{"name"=>"Non-Null", "ofType"=>{"name"=>"Int"}}},
41
+ {"type"=>{"name"=>"DairyAnimal", "ofType"=>nil}},
42
+ {"type"=>{"name"=>"Non-Null", "ofType"=>{"name"=>"Float"}}},
43
+ {"type"=>{"name"=>"List", "ofType"=>{"name"=>"String"}}},
44
+ {"type"=>{"name"=>"Non-Null", "ofType"=>{"name"=>"String"}}}
45
+ ]
46
+ },
32
47
  "dairyAnimal"=>{
33
48
  "name"=>"DairyAnimal",
34
49
  "kind"=>"ENUM",
@@ -38,7 +38,7 @@ describe GraphQL::Parser do
38
38
  assert(parser.operation_definition.parse_with_debug(%|{id, name, ...people}|), "just a selection")
39
39
  assert(parser.operation_definition.parse_with_debug(%|query personStuff {id, name, ...people, ... stuff}|), "named fetch")
40
40
  assert(parser.operation_definition.parse_with_debug(%|query personStuff @flagDirective {id, name, ...people}|), "with a directive")
41
- assert(parser.operation_definition.parse_with_debug(%|mutation changeStuff($stuff: Int = 1, $things: [Boolean]!) {id, name, ...people}|), "mutation with arguments")
41
+ assert(parser.operation_definition.parse_with_debug(%|mutation changeStuff($stuff: Int = 1, $things: [SomeType]!) {id, name, ...people}|), "mutation with arguments")
42
42
  end
43
43
 
44
44
  it 'parses fragment definitions' do
@@ -85,7 +85,9 @@ describe GraphQL::Parser do
85
85
  it 'gets floats' do
86
86
  assert(parser.value.parse_with_debug("1.14"), 'no exponent')
87
87
  assert(parser.value.parse_with_debug("6.7e-9"), 'negative exponent')
88
+ assert(parser.value.parse_with_debug("6.7e+9"), 'positive exponent')
88
89
  assert(parser.value.parse_with_debug("0.4e12"), 'exponent')
90
+ assert(parser.value.parse_with_debug("6.7E+9"), 'big e')
89
91
  end
90
92
 
91
93
  it 'gets booleans' do