graphql 0.12.1 → 0.13.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (146) hide show
  1. checksums.yaml +4 -4
  2. data/lib/graphql.rb +31 -41
  3. data/lib/graphql/argument.rb +23 -21
  4. data/lib/graphql/base_type.rb +5 -8
  5. data/lib/graphql/define/assign_argument.rb +5 -2
  6. data/lib/graphql/define/type_definer.rb +2 -1
  7. data/lib/graphql/directive.rb +34 -36
  8. data/lib/graphql/directive/include_directive.rb +3 -7
  9. data/lib/graphql/directive/skip_directive.rb +3 -7
  10. data/lib/graphql/enum_type.rb +78 -76
  11. data/lib/graphql/execution_error.rb +1 -3
  12. data/lib/graphql/field.rb +99 -95
  13. data/lib/graphql/input_object_type.rb +49 -47
  14. data/lib/graphql/interface_type.rb +31 -34
  15. data/lib/graphql/introspection.rb +19 -18
  16. data/lib/graphql/introspection/directive_location_enum.rb +8 -0
  17. data/lib/graphql/introspection/directive_type.rb +1 -3
  18. data/lib/graphql/introspection/field_type.rb +1 -1
  19. data/lib/graphql/introspection/fields_field.rb +1 -1
  20. data/lib/graphql/introspection/introspection_query.rb +1 -3
  21. data/lib/graphql/introspection/possible_types_field.rb +7 -1
  22. data/lib/graphql/introspection/schema_field.rb +13 -9
  23. data/lib/graphql/introspection/type_by_name_field.rb +13 -17
  24. data/lib/graphql/introspection/typename_field.rb +12 -8
  25. data/lib/graphql/language.rb +5 -9
  26. data/lib/graphql/language/lexer.rb +668 -0
  27. data/lib/graphql/language/lexer.rl +149 -0
  28. data/lib/graphql/language/parser.rb +842 -116
  29. data/lib/graphql/language/parser.y +264 -0
  30. data/lib/graphql/language/token.rb +21 -0
  31. data/lib/graphql/list_type.rb +33 -31
  32. data/lib/graphql/non_null_type.rb +33 -31
  33. data/lib/graphql/object_type.rb +52 -55
  34. data/lib/graphql/query.rb +83 -80
  35. data/lib/graphql/query/context.rb +5 -1
  36. data/lib/graphql/query/directive_resolution.rb +16 -0
  37. data/lib/graphql/query/executor.rb +3 -3
  38. data/lib/graphql/query/input_validation_result.rb +17 -15
  39. data/lib/graphql/query/serial_execution.rb +5 -5
  40. data/lib/graphql/query/serial_execution/execution_context.rb +4 -3
  41. data/lib/graphql/query/serial_execution/selection_resolution.rb +19 -21
  42. data/lib/graphql/query/serial_execution/value_resolution.rb +1 -1
  43. data/lib/graphql/query/type_resolver.rb +22 -18
  44. data/lib/graphql/query/variable_validation_error.rb +14 -12
  45. data/lib/graphql/schema.rb +87 -77
  46. data/lib/graphql/schema/each_item_validator.rb +16 -12
  47. data/lib/graphql/schema/field_validator.rb +14 -10
  48. data/lib/graphql/schema/implementation_validator.rb +26 -22
  49. data/lib/graphql/schema/middleware_chain.rb +2 -1
  50. data/lib/graphql/schema/possible_types.rb +34 -0
  51. data/lib/graphql/schema/printer.rb +122 -120
  52. data/lib/graphql/schema/type_expression.rb +1 -0
  53. data/lib/graphql/schema/type_map.rb +3 -10
  54. data/lib/graphql/schema/type_reducer.rb +65 -81
  55. data/lib/graphql/schema/type_validator.rb +45 -41
  56. data/lib/graphql/static_validation.rb +7 -9
  57. data/lib/graphql/static_validation/all_rules.rb +29 -24
  58. data/lib/graphql/static_validation/arguments_validator.rb +39 -35
  59. data/lib/graphql/static_validation/literal_validator.rb +44 -40
  60. data/lib/graphql/static_validation/message.rb +30 -26
  61. data/lib/graphql/static_validation/rules/argument_literals_are_compatible.rb +15 -11
  62. data/lib/graphql/static_validation/rules/arguments_are_defined.rb +14 -10
  63. data/lib/graphql/static_validation/rules/directives_are_defined.rb +16 -12
  64. data/lib/graphql/static_validation/rules/directives_are_in_valid_locations.rb +59 -0
  65. data/lib/graphql/static_validation/rules/fields_are_defined_on_type.rb +25 -21
  66. data/lib/graphql/static_validation/rules/fields_have_appropriate_selections.rb +28 -24
  67. data/lib/graphql/static_validation/rules/fields_will_merge.rb +84 -80
  68. data/lib/graphql/static_validation/rules/fragment_spreads_are_possible.rb +49 -43
  69. data/lib/graphql/static_validation/rules/fragment_types_exist.rb +22 -17
  70. data/lib/graphql/static_validation/rules/fragments_are_finite.rb +19 -15
  71. data/lib/graphql/static_validation/rules/fragments_are_on_composite_types.rb +25 -20
  72. data/lib/graphql/static_validation/rules/fragments_are_used.rb +36 -23
  73. data/lib/graphql/static_validation/rules/required_arguments_are_present.rb +29 -25
  74. data/lib/graphql/static_validation/rules/variable_default_values_are_correctly_typed.rb +21 -17
  75. data/lib/graphql/static_validation/rules/variable_usages_are_allowed.rb +79 -70
  76. data/lib/graphql/static_validation/rules/variables_are_input_types.rb +24 -20
  77. data/lib/graphql/static_validation/rules/variables_are_used_and_defined.rb +122 -119
  78. data/lib/graphql/static_validation/type_stack.rb +138 -129
  79. data/lib/graphql/static_validation/validator.rb +29 -25
  80. data/lib/graphql/type_kinds.rb +42 -40
  81. data/lib/graphql/union_type.rb +22 -16
  82. data/lib/graphql/version.rb +1 -1
  83. data/readme.md +12 -27
  84. data/spec/graphql/base_type_spec.rb +3 -3
  85. data/spec/graphql/directive_spec.rb +10 -18
  86. data/spec/graphql/enum_type_spec.rb +7 -7
  87. data/spec/graphql/execution_error_spec.rb +1 -1
  88. data/spec/graphql/field_spec.rb +14 -13
  89. data/spec/graphql/id_type_spec.rb +6 -6
  90. data/spec/graphql/input_object_type_spec.rb +39 -39
  91. data/spec/graphql/interface_type_spec.rb +16 -32
  92. data/spec/graphql/introspection/directive_type_spec.rb +5 -9
  93. data/spec/graphql/introspection/input_value_type_spec.rb +10 -4
  94. data/spec/graphql/introspection/introspection_query_spec.rb +2 -2
  95. data/spec/graphql/introspection/schema_type_spec.rb +2 -2
  96. data/spec/graphql/introspection/type_type_spec.rb +34 -6
  97. data/spec/graphql/language/parser_spec.rb +299 -105
  98. data/spec/graphql/language/visitor_spec.rb +4 -4
  99. data/spec/graphql/list_type_spec.rb +11 -11
  100. data/spec/graphql/object_type_spec.rb +10 -10
  101. data/spec/graphql/query/arguments_spec.rb +7 -7
  102. data/spec/graphql/query/context_spec.rb +11 -3
  103. data/spec/graphql/query/executor_spec.rb +26 -19
  104. data/spec/graphql/query/serial_execution/execution_context_spec.rb +6 -6
  105. data/spec/graphql/query/serial_execution/value_resolution_spec.rb +2 -2
  106. data/spec/graphql/query/type_resolver_spec.rb +3 -3
  107. data/spec/graphql/query_spec.rb +6 -38
  108. data/spec/graphql/scalar_type_spec.rb +28 -19
  109. data/spec/graphql/schema/field_validator_spec.rb +1 -1
  110. data/spec/graphql/schema/middleware_chain_spec.rb +12 -1
  111. data/spec/graphql/schema/printer_spec.rb +12 -4
  112. data/spec/graphql/schema/rescue_middleware_spec.rb +1 -1
  113. data/spec/graphql/schema/type_expression_spec.rb +2 -2
  114. data/spec/graphql/schema/type_reducer_spec.rb +21 -36
  115. data/spec/graphql/schema/type_validator_spec.rb +9 -9
  116. data/spec/graphql/schema_spec.rb +1 -1
  117. data/spec/graphql/static_validation/rules/argument_literals_are_compatible_spec.rb +4 -4
  118. data/spec/graphql/static_validation/rules/arguments_are_defined_spec.rb +4 -4
  119. data/spec/graphql/static_validation/rules/directives_are_defined_spec.rb +5 -5
  120. data/spec/graphql/static_validation/rules/directives_are_in_valid_locations_spec.rb +39 -0
  121. data/spec/graphql/static_validation/rules/fields_are_defined_on_type_spec.rb +5 -5
  122. data/spec/graphql/static_validation/rules/fields_have_appropriate_selections_spec.rb +4 -4
  123. data/spec/graphql/static_validation/rules/fields_will_merge_spec.rb +2 -2
  124. data/spec/graphql/static_validation/rules/fragment_spreads_are_possible_spec.rb +1 -1
  125. data/spec/graphql/static_validation/rules/fragment_types_exist_spec.rb +2 -2
  126. data/spec/graphql/static_validation/rules/fragments_are_finite_spec.rb +2 -2
  127. data/spec/graphql/static_validation/rules/fragments_are_on_composite_types_spec.rb +2 -2
  128. data/spec/graphql/static_validation/rules/fragments_are_used_spec.rb +3 -3
  129. data/spec/graphql/static_validation/rules/required_arguments_are_present_spec.rb +3 -3
  130. data/spec/graphql/static_validation/rules/variable_default_values_are_correctly_typed_spec.rb +5 -5
  131. data/spec/graphql/static_validation/rules/variable_usages_are_allowed_spec.rb +3 -1
  132. data/spec/graphql/static_validation/rules/variables_are_input_types_spec.rb +4 -4
  133. data/spec/graphql/static_validation/rules/variables_are_used_and_defined_spec.rb +3 -3
  134. data/spec/graphql/static_validation/type_stack_spec.rb +3 -2
  135. data/spec/graphql/static_validation/validator_spec.rb +26 -6
  136. data/spec/graphql/union_type_spec.rb +5 -4
  137. data/spec/spec_helper.rb +2 -5
  138. data/spec/support/dairy_app.rb +30 -9
  139. data/spec/support/dairy_data.rb +1 -1
  140. data/spec/support/star_wars_data.rb +26 -26
  141. data/spec/support/star_wars_schema.rb +1 -1
  142. metadata +40 -21
  143. data/lib/graphql/language/transform.rb +0 -113
  144. data/lib/graphql/query/directive_chain.rb +0 -44
  145. data/lib/graphql/repl.rb +0 -27
  146. data/spec/graphql/language/transform_spec.rb +0 -156
@@ -1,29 +1,33 @@
1
- # Initialized with a {GraphQL::Schema}, then it can validate {GraphQL::Language::Nodes::Documents}s based on that schema.
2
- #
3
- # By default, it's used by {GraphQL::Query}
4
- #
5
- # @example Validate a query
6
- # validator = GraphQL::StaticValidation::Validator.new(schema: MySchema)
7
- # document = GraphQL.parse(query_string)
8
- # errors = validator.validate(document)
9
- #
10
- class GraphQL::StaticValidation::Validator
11
- # @param schema [GraphQL::Schema]
12
- # @param rule [Array<#validate(context)>] a list of rules to use when validating
13
- def initialize(schema:, rules: GraphQL::StaticValidation::ALL_RULES)
14
- @schema = schema
15
- @rules = rules
16
- end
1
+ module GraphQL
2
+ module StaticValidation
3
+ # Initialized with a {GraphQL::Schema}, then it can validate {GraphQL::Language::Nodes::Documents}s based on that schema.
4
+ #
5
+ # By default, it's used by {GraphQL::Query}
6
+ #
7
+ # @example Validate a query
8
+ # validator = GraphQL::StaticValidation::Validator.new(schema: MySchema)
9
+ # document = GraphQL.parse(query_string)
10
+ # errors = validator.validate(document)
11
+ #
12
+ class Validator
13
+ # @param schema [GraphQL::Schema]
14
+ # @param rule [Array<#validate(context)>] a list of rules to use when validating
15
+ def initialize(schema:, rules: GraphQL::StaticValidation::ALL_RULES)
16
+ @schema = schema
17
+ @rules = rules
18
+ end
17
19
 
18
- # Validate `document` against the schema. Returns an array of message hashes.
19
- # @param document [GraphQL::Language::Nodes::Document]
20
- # @return [Array<Hash>]
21
- def validate(query)
22
- context = GraphQL::StaticValidation::ValidationContext.new(query)
23
- @rules.each do |rules|
24
- rules.new.validate(context)
20
+ # Validate `document` against the schema. Returns an array of message hashes.
21
+ # @param document [GraphQL::Language::Nodes::Document]
22
+ # @return [Array<Hash>]
23
+ def validate(query)
24
+ context = GraphQL::StaticValidation::ValidationContext.new(query)
25
+ @rules.each do |rules|
26
+ rules.new.validate(context)
27
+ end
28
+ context.visitor.visit(query.document)
29
+ context.errors.map(&:to_h)
30
+ end
25
31
  end
26
- context.visitor.visit(query.document)
27
- context.errors.map(&:to_h)
28
32
  end
29
33
  end
@@ -1,46 +1,48 @@
1
- # Type kinds are the basic categories which a type may belong to (`Object`, `Scalar`, `Union`...)
2
- module GraphQL::TypeKinds
3
- # These objects are singletons, eg `GraphQL::TypeKinds::UNION`, `GraphQL::TypeKinds::SCALAR`.
4
- class TypeKind
5
- attr_reader :name
6
- def initialize(name, resolves: false, fields: false, wraps: false, input: false)
7
- @name = name
8
- @resolves = resolves
9
- @fields = fields
10
- @wraps = wraps
11
- @input = input
12
- @composite = fields? || resolves?
13
- end
1
+ module GraphQL
2
+ # Type kinds are the basic categories which a type may belong to (`Object`, `Scalar`, `Union`...)
3
+ module TypeKinds
4
+ # These objects are singletons, eg `GraphQL::TypeKinds::UNION`, `GraphQL::TypeKinds::SCALAR`.
5
+ class TypeKind
6
+ attr_reader :name
7
+ def initialize(name, resolves: false, fields: false, wraps: false, input: false)
8
+ @name = name
9
+ @resolves = resolves
10
+ @fields = fields
11
+ @wraps = wraps
12
+ @input = input
13
+ @composite = fields? || resolves?
14
+ end
14
15
 
15
- # Does this TypeKind have multiple possible implementors?
16
- def resolves?; @resolves; end
17
- # Does this TypeKind have queryable fields?
18
- def fields?; @fields; end
19
- # Does this TypeKind modify another type?
20
- def wraps?; @wraps; end
21
- # Is this TypeKind a valid query input?
22
- def input?; @input; end
23
- def to_s; @name; end
24
- # Is this TypeKind composed of many values?
25
- def composite?; @composite; end
26
- end
16
+ # Does this TypeKind have multiple possible implementors?
17
+ def resolves?; @resolves; end
18
+ # Does this TypeKind have queryable fields?
19
+ def fields?; @fields; end
20
+ # Does this TypeKind modify another type?
21
+ def wraps?; @wraps; end
22
+ # Is this TypeKind a valid query input?
23
+ def input?; @input; end
24
+ def to_s; @name; end
25
+ # Is this TypeKind composed of many values?
26
+ def composite?; @composite; end
27
+ end
27
28
 
28
- TYPE_KINDS = [
29
- SCALAR = TypeKind.new("SCALAR", input: true),
30
- OBJECT = TypeKind.new("OBJECT", fields: true),
31
- INTERFACE = TypeKind.new("INTERFACE", resolves: true, fields: true),
32
- UNION = TypeKind.new("UNION", resolves: true),
33
- ENUM = TypeKind.new("ENUM", input: true),
34
- INPUT_OBJECT = TypeKind.new("INPUT_OBJECT", input: true),
35
- LIST = TypeKind.new("LIST", wraps: true),
36
- NON_NULL = TypeKind.new("NON_NULL", wraps: true),
37
- ]
29
+ TYPE_KINDS = [
30
+ SCALAR = TypeKind.new("SCALAR", input: true),
31
+ OBJECT = TypeKind.new("OBJECT", fields: true),
32
+ INTERFACE = TypeKind.new("INTERFACE", resolves: true, fields: true),
33
+ UNION = TypeKind.new("UNION", resolves: true),
34
+ ENUM = TypeKind.new("ENUM", input: true),
35
+ INPUT_OBJECT = TypeKind.new("INPUT_OBJECT", input: true),
36
+ LIST = TypeKind.new("LIST", wraps: true),
37
+ NON_NULL = TypeKind.new("NON_NULL", wraps: true),
38
+ ]
38
39
 
39
- KIND_NAMES = TYPE_KINDS.map(&:name)
40
- class TypeKind
41
- KIND_NAMES.each do |kind_name|
42
- define_method("#{kind_name.downcase}?") do
43
- self.name == kind_name
40
+ KIND_NAMES = TYPE_KINDS.map(&:name)
41
+ class TypeKind
42
+ KIND_NAMES.each do |kind_name|
43
+ define_method("#{kind_name.downcase}?") do
44
+ self.name == kind_name
45
+ end
44
46
  end
45
47
  end
46
48
  end
@@ -1,19 +1,25 @@
1
- # A collection of {ObjectType}s
2
- #
3
- # @example a union of types
4
- #
5
- # PetUnion = GraphQL::UnionType.define do
6
- # name "Pet"
7
- # description "Animals that live in your house"
8
- # possible_types [DogType, CatType, FishType]
9
- # end
10
- #
11
- class GraphQL::UnionType < GraphQL::BaseType
12
- include GraphQL::BaseType::HasPossibleTypes
13
- attr_accessor :name, :description, :possible_types
14
- accepts_definitions :possible_types, :resolve_type
1
+ module GraphQL
2
+ # A collection of {ObjectType}s
3
+ #
4
+ # @example a union of types
5
+ #
6
+ # PetUnion = GraphQL::UnionType.define do
7
+ # name "Pet"
8
+ # description "Animals that live in your house"
9
+ # possible_types [DogType, CatType, FishType]
10
+ # end
11
+ #
12
+ class UnionType < GraphQL::BaseType
13
+ include GraphQL::BaseType::HasPossibleTypes
14
+ attr_accessor :name, :description, :possible_types
15
+ accepts_definitions :possible_types, :resolve_type
15
16
 
16
- def kind
17
- GraphQL::TypeKinds::UNION
17
+ def kind
18
+ GraphQL::TypeKinds::UNION
19
+ end
20
+
21
+ def include?(child_type_defn)
22
+ possible_types.include?(child_type_defn)
23
+ end
18
24
  end
19
25
  end
@@ -1,3 +1,3 @@
1
1
  module GraphQL
2
- VERSION = "0.12.1"
2
+ VERSION = "0.13.0"
3
3
  end
data/readme.md CHANGED
@@ -64,10 +64,6 @@ Schema = GraphQL::Schema.new(
64
64
  )
65
65
  ```
66
66
 
67
- See also:
68
- - the [test schema](https://github.com/rmosolgo/graphql-ruby/blob/master/spec/support/dairy_app.rb)
69
- - [`graphql-ruby-demo`](https://github.com/rmosolgo/graphql-ruby-demo) for an example schema on Rails
70
-
71
67
  #### Execute queries
72
68
 
73
69
  Execute GraphQL queries on a given schema, from a query string.
@@ -84,11 +80,6 @@ result_hash = Schema.execute(query_string)
84
80
  # }
85
81
  ```
86
82
 
87
- See also:
88
- - [query_spec.rb](https://github.com/rmosolgo/graphql-ruby/blob/master/spec/graphql/query_spec.rb) for an example of query execution.
89
- - [`queries_controller.rb`](https://github.com/rmosolgo/graphql-ruby-demo/blob/master/app/controllers/queries_controller.rb) for a Rails example
90
- - Try it on [heroku](http://graphql-ruby-demo.herokuapp.com)
91
-
92
83
  #### Use with Relay
93
84
 
94
85
  If you're building a backend for [Relay](http://facebook.github.io/relay/), you'll need:
@@ -96,21 +87,6 @@ If you're building a backend for [Relay](http://facebook.github.io/relay/), you'
96
87
  - A JSON dump of the schema, which you can get by sending [`GraphQL::Introspection::INTROSPECTION_QUERY`](https://github.com/rmosolgo/graphql-ruby/blob/master/lib/graphql/introspection/introspection_query.rb)
97
88
  - Relay-specific helpers for GraphQL like Connections, node fields, and global ids. Here's one example of those: [`graphql-relay`](https://github.com/rmosolgo/graphql-relay-ruby)
98
89
 
99
- ## Getting Started Tutorials
100
-
101
- #### Series: Building a blog in GraphQL and Relay on Rails
102
- 1. **Introduction:** https://medium.com/@gauravtiwari/graphql-and-relay-on-rails-getting-started-955a49d251de
103
- 2. **Part1:** https://medium.com/@gauravtiwari/graphql-and-relay-on-rails-creating-types-and-schema-b3f9b232ccfc
104
- 3. **Part2:**
105
- https://medium.com/@gauravtiwari/graphql-and-relay-on-rails-first-relay-powered-react-component-cb3f9ee95eca
106
-
107
- #### Tutorials
108
-
109
- 1. https://medium.com/@khor/relay-facebook-on-rails-8b4af2057152
110
- 2. https://blog.jacobwgillespie.com/from-rest-to-graphql-b4e95e94c26b#.4cjtklrwt
111
- 3. http://mgiroux.me/2015/getting-started-with-rails-graphql-relay/
112
- 4. http://mgiroux.me/2015/uploading-files-using-relay-with-rails/
113
-
114
90
  ## Goals
115
91
 
116
92
  - Implement the GraphQL spec & support a Relay front end
@@ -126,20 +102,29 @@ https://medium.com/@gauravtiwari/graphql-and-relay-on-rails-first-relay-powered-
126
102
 
127
103
  ## Related Projects
128
104
 
105
+ ### Code
106
+
129
107
  - `graphql-ruby` + Rails demo ([src](https://github.com/rmosolgo/graphql-ruby-demo) / [heroku](http://graphql-ruby-demo.herokuapp.com))
130
108
  - [`graphql-batch`](https://github.com/shopify/graphql-batch), a batched query execution strategy
131
- - [`graphql-parallel`](https://github.com/rmosolgo/graphql-parallel), an asynchronous query execution strategy
132
109
  - [Example Relay support](https://github.com/rmosolgo/graphql-relay-ruby) in Ruby
133
110
  - [`graphql-libgraphqlparser`](https://github.com/rmosolgo/graphql-libgraphqlparser), bindings to [libgraphqlparser](https://github.com/graphql/libgraphqlparser), a C-level parser.
134
111
 
112
+ ### Blog Posts
113
+
114
+ - Building a blog in GraphQL and Relay on Rails [Introduction](https://medium.com/@gauravtiwari/graphql-and-relay-on-rails-getting-started-955a49d251de), [Part 1]( https://medium.com/@gauravtiwari/graphql-and-relay-on-rails-creating-types-and-schema-b3f9b232ccfc), [Part 2](https://medium.com/@gauravtiwari/graphql-and-relay-on-rails-first-relay-powered-react-component-cb3f9ee95eca)
115
+ - https://medium.com/@khor/relay-facebook-on-rails-8b4af2057152
116
+ - https://blog.jacobwgillespie.com/from-rest-to-graphql-b4e95e94c26b#.4cjtklrwt
117
+ - http://mgiroux.me/2015/getting-started-with-rails-graphql-relay/
118
+ - http://mgiroux.me/2015/uploading-files-using-relay-with-rails/
119
+
135
120
  ## To Do
136
121
 
137
- - Interface's possible types should be a property of the schema, not the interface
138
122
  - Type lookup should be by type name (to support reloaded constants in Rails code)
139
123
  - Add a complexity validator (reject queries if they're too big)
140
124
  - Add docs for shared behaviors & DRY code
141
- - Optimize the pure-Ruby parser (hand-write, RACC?!)
142
125
  - Revamp the fixture Schema to be more useful (better names, more extensible)
126
+ - Fix when a field's type is left out `field :name, "This is the name field"`
127
+ - Revisit error handling & `debug:` option
143
128
  - __Subscriptions__
144
129
  - This is a good chance to make an `Operation` abstraction of which `query`, `mutation` and `subscription` are members
145
130
  - For a subscription, `graphql` would send an outbound message to the system (allow the host application to manage its own subscriptions via Pusher, ActionCable, whatever)
@@ -1,7 +1,7 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  describe GraphQL::BaseType do
4
- it 'becomes non-null with !' do
4
+ it "becomes non-null with !" do
5
5
  type = GraphQL::EnumType.new
6
6
  non_null_type = !type
7
7
  assert_equal(GraphQL::TypeKinds::NON_NULL, non_null_type.kind)
@@ -9,7 +9,7 @@ describe GraphQL::BaseType do
9
9
  assert_equal(GraphQL::TypeKinds::NON_NULL, (!GraphQL::STRING_TYPE).kind)
10
10
  end
11
11
 
12
- it 'can be compared' do
12
+ it "can be compared" do
13
13
  assert_equal(!GraphQL::INT_TYPE, !GraphQL::INT_TYPE)
14
14
  refute_equal(!GraphQL::FLOAT_TYPE, GraphQL::FLOAT_TYPE)
15
15
  assert_equal(
@@ -1,8 +1,8 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  describe GraphQL::Directive do
4
4
  let(:result) { DummySchema.execute(query_string, variables: {"t" => true, "f" => false}) }
5
- describe 'on fields' do
5
+ describe "on fields" do
6
6
  let(:query_string) { %|query directives($t: Boolean!, $f: Boolean!) {
7
7
  cheese(id: 1) {
8
8
  # plain fields:
@@ -23,11 +23,11 @@ describe GraphQL::Directive do
23
23
  fragment dontIncludeIdField on Cheese { dontIncludeId: id @include(if: false) }
24
24
  fragment skipIdField on Cheese { skipId: id @skip(if: true) }
25
25
  fragment dontSkipIdField on Cheese { dontSkipId: id @skip(if: false) }
26
- |}
27
- it 'intercepts fields' do
26
+ |
27
+ }
28
+ it "intercepts fields" do
28
29
  expected = { "data" =>{
29
30
  "cheese" => {
30
- "dontSkipDontIncludeFlavor" => "Brie", #skip has precedence over include
31
31
  "dontSkipFlavor" => "Brie",
32
32
  "includeFlavor" => "Brie",
33
33
  "includeId" => 1,
@@ -37,7 +37,7 @@ describe GraphQL::Directive do
37
37
  assert_equal(expected, result)
38
38
  end
39
39
  end
40
- describe 'on fragments' do
40
+ describe "on fragments spreads and inline fragments" do
41
41
  let(:query_string) { %|query directives {
42
42
  cheese(id: 1) {
43
43
  ... skipFlavorField @skip(if: true)
@@ -45,37 +45,29 @@ describe GraphQL::Directive do
45
45
  ... includeFlavorField @include(if: true)
46
46
  ... dontIncludeFlavorField @include(if: false)
47
47
 
48
- ... includeIdField
49
- ... dontIncludeIdField
50
- ... skipIdField
51
- ... dontSkipIdField
52
48
 
53
49
  ... on Cheese @skip(if: true) { skipInlineId: id }
54
50
  ... on Cheese @skip(if: false) { dontSkipInlineId: id }
55
51
  ... on Cheese @include(if: true) { includeInlineId: id }
56
52
  ... on Cheese @include(if: false) { dontIncludeInlineId: id }
53
+ ... @skip(if: true) { skipNoType: id }
54
+ ... @skip(if: false) { dontSkipNoType: id }
57
55
  }
58
56
  }
59
57
  fragment includeFlavorField on Cheese { includeFlavor: flavor }
60
58
  fragment dontIncludeFlavorField on Cheese { dontIncludeFlavor: flavor }
61
59
  fragment skipFlavorField on Cheese { skipFlavor: flavor }
62
60
  fragment dontSkipFlavorField on Cheese { dontSkipFlavor: flavor }
63
-
64
- fragment includeIdField on Cheese @include(if: true) { includeId: id }
65
- fragment dontIncludeIdField on Cheese @include(if: false) { dontIncludeId: id }
66
- fragment skipIdField on Cheese @skip(if: true) { skipId: id }
67
- fragment dontSkipIdField on Cheese @skip(if: false) { dontSkipId: id }
68
61
  |}
69
62
 
70
- it 'intercepts fragment spreads' do
63
+ it "intercepts fragment spreads" do
71
64
  expected = { "data" => {
72
65
  "cheese" => {
73
66
  "dontSkipFlavor" => "Brie",
74
67
  "includeFlavor" => "Brie",
75
- "includeId" => 1,
76
- "dontSkipId" => 1,
77
68
  "dontSkipInlineId" => 1,
78
69
  "includeInlineId" => 1,
70
+ "dontSkipNoType" => 1,
79
71
  },
80
72
  }}
81
73
  assert_equal(expected, result)
@@ -1,9 +1,9 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  describe GraphQL::EnumType do
4
4
  let(:enum) { DairyAnimalEnum }
5
5
 
6
- it 'coerces names to underlying values' do
6
+ it "coerces names to underlying values" do
7
7
  assert_equal("YAK", enum.coerce_input("YAK"))
8
8
  assert_equal(1, enum.coerce_input("COW"))
9
9
  end
@@ -13,14 +13,14 @@ describe GraphQL::EnumType do
13
13
  assert_equal("COW", enum.coerce_result(1))
14
14
  end
15
15
 
16
- it 'has value description' do
17
- assert_equal("Animal with horns", enum.values['GOAT'].description)
16
+ it "has value description" do
17
+ assert_equal("Animal with horns", enum.values["GOAT"].description)
18
18
  end
19
19
 
20
- describe 'validate_input with bad input' do
21
- let(:result) { DairyAnimalEnum.validate_input('bad enum') }
20
+ describe "validate_input with bad input" do
21
+ let(:result) { DairyAnimalEnum.validate_input("bad enum") }
22
22
 
23
- it 'returns an invalid result' do
23
+ it "returns an invalid result" do
24
24
  assert(!result.valid?)
25
25
  end
26
26
  end
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  describe GraphQL::ExecutionError do
4
4
  let(:result) { DummySchema.execute(query_string) }
@@ -1,7 +1,7 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  describe GraphQL::Field do
4
- it 'accepts a proc as type' do
4
+ it "accepts a proc as type" do
5
5
  field = GraphQL::Field.define do
6
6
  type(-> { DairyProductUnion })
7
7
  end
@@ -18,27 +18,28 @@ describe GraphQL::Field do
18
18
  end
19
19
 
20
20
 
21
- describe '.property ' do
21
+ describe ".property " do
22
22
  let(:field) do
23
23
  GraphQL::Field.define do
24
- name 'field_name'
24
+ name "field_name"
25
25
  # satisfies 'can define by config' below
26
26
  property :internal_prop
27
27
  end
28
28
  end
29
29
 
30
- it 'can define by config' do
30
+ it "can define by config" do
31
31
  assert_equal(field.property, :internal_prop)
32
32
  end
33
33
 
34
- it 'has nil property if not defined' do
34
+ it "has nil property if not defined" do
35
35
  no_prop_field = GraphQL::Field.define { }
36
36
  assert_equal(no_prop_field.property, nil)
37
37
  end
38
38
 
39
- describe 'default resolver' do
39
+ describe "default resolver" do
40
40
  def acts_like_default_resolver(field, old_prop, new_prop)
41
- object = OpenStruct.new(old_prop => 'old value', new_prop => 'new value', field.name.to_sym => 'unset value')
41
+ object = OpenStruct.new(old_prop => "old value", new_prop => "new value", field.name.to_sym => "unset value")
42
+
42
43
 
43
44
  old_result = field.resolve(object, nil, nil)
44
45
  field.property = new_prop
@@ -46,16 +47,16 @@ describe GraphQL::Field do
46
47
  field.property = nil
47
48
  unset_result = field.resolve(object, nil, nil)
48
49
 
49
- assert_equal(old_result, 'old value')
50
- assert_equal(new_result, 'new value')
51
- assert_equal(unset_result, 'unset value')
50
+ assert_equal(old_result, "old value")
51
+ assert_equal(new_result, "new value")
52
+ assert_equal(unset_result, "unset value")
52
53
  end
53
54
 
54
- it 'responds to changes in property' do
55
+ it "responds to changes in property" do
55
56
  acts_like_default_resolver(field, :internal_prop, :new_prop)
56
57
  end
57
58
 
58
- it 'is reassigned if resolve is set to nil' do
59
+ it "is reassigned if resolve is set to nil" do
59
60
  field.resolve = nil
60
61
  acts_like_default_resolver(field, :internal_prop, :new_prop)
61
62
  end