graphql 0.18.14 → 0.18.15

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/lib/graphql/analysis/query_complexity.rb +15 -6
  3. data/lib/graphql/analysis/query_depth.rb +11 -10
  4. data/lib/graphql/directive.rb +2 -6
  5. data/lib/graphql/directive/include_directive.rb +0 -4
  6. data/lib/graphql/directive/skip_directive.rb +0 -4
  7. data/lib/graphql/execution/directive_checks.rb +22 -13
  8. data/lib/graphql/execution_error.rb +7 -0
  9. data/lib/graphql/internal_representation/node.rb +20 -2
  10. data/lib/graphql/internal_representation/rewrite.rb +66 -20
  11. data/lib/graphql/language/generation.rb +22 -8
  12. data/lib/graphql/language/nodes.rb +48 -20
  13. data/lib/graphql/language/parser.rb +436 -423
  14. data/lib/graphql/language/parser.y +22 -19
  15. data/lib/graphql/language/parser_tests.rb +131 -2
  16. data/lib/graphql/query/serial_execution/field_resolution.rb +1 -0
  17. data/lib/graphql/query/serial_execution/selection_resolution.rb +1 -1
  18. data/lib/graphql/query/serial_execution/value_resolution.rb +4 -1
  19. data/lib/graphql/schema/printer.rb +1 -1
  20. data/lib/graphql/static_validation/message.rb +1 -1
  21. data/lib/graphql/version.rb +1 -1
  22. data/readme.md +10 -12
  23. data/spec/graphql/directive_spec.rb +139 -1
  24. data/spec/graphql/execution_error_spec.rb +63 -3
  25. data/spec/graphql/introspection/type_type_spec.rb +2 -0
  26. data/spec/graphql/language/generation_spec.rb +55 -7
  27. data/spec/graphql/query/executor_spec.rb +4 -2
  28. data/spec/graphql/schema/catchall_middleware_spec.rb +1 -0
  29. data/spec/graphql/schema/printer_spec.rb +1 -1
  30. data/spec/graphql/schema/timeout_middleware_spec.rb +10 -5
  31. data/spec/graphql/static_validation/rules/argument_literals_are_compatible_spec.rb +6 -6
  32. data/spec/graphql/static_validation/rules/arguments_are_defined_spec.rb +4 -4
  33. data/spec/graphql/static_validation/rules/directives_are_defined_spec.rb +2 -2
  34. data/spec/graphql/static_validation/rules/directives_are_in_valid_locations_spec.rb +2 -2
  35. data/spec/graphql/static_validation/rules/fields_are_defined_on_type_spec.rb +3 -3
  36. data/spec/graphql/static_validation/rules/fields_have_appropriate_selections_spec.rb +2 -2
  37. data/spec/graphql/static_validation/rules/fragment_spreads_are_possible_spec.rb +3 -3
  38. data/spec/graphql/static_validation/rules/fragment_types_exist_spec.rb +2 -2
  39. data/spec/graphql/static_validation/rules/fragments_are_finite_spec.rb +2 -2
  40. data/spec/graphql/static_validation/rules/fragments_are_named_spec.rb +1 -1
  41. data/spec/graphql/static_validation/rules/fragments_are_on_composite_types_spec.rb +3 -3
  42. data/spec/graphql/static_validation/rules/fragments_are_used_spec.rb +2 -2
  43. data/spec/graphql/static_validation/rules/mutation_root_exists_spec.rb +1 -1
  44. data/spec/graphql/static_validation/rules/required_arguments_are_present_spec.rb +3 -3
  45. data/spec/graphql/static_validation/rules/subscription_root_exists_spec.rb +1 -1
  46. data/spec/graphql/static_validation/rules/variable_default_values_are_correctly_typed_spec.rb +4 -4
  47. data/spec/graphql/static_validation/rules/variable_usages_are_allowed_spec.rb +4 -4
  48. data/spec/graphql/static_validation/rules/variables_are_input_types_spec.rb +3 -3
  49. data/spec/graphql/static_validation/rules/variables_are_used_and_defined_spec.rb +3 -3
  50. data/spec/graphql/static_validation/validator_spec.rb +1 -1
  51. data/spec/support/dairy_app.rb +8 -0
  52. metadata +30 -2
@@ -28,13 +28,13 @@ describe GraphQL::StaticValidation::FragmentTypesExist do
28
28
  inline_fragment_error = {
29
29
  "message"=>"No such type Something, so it can't be a fragment condition",
30
30
  "locations"=>[{"line"=>11, "column"=>5}],
31
- "path"=>["fragment somethingFields"],
31
+ "fields"=>["fragment somethingFields"],
32
32
  }
33
33
  assert_includes(errors, inline_fragment_error, "on inline fragments")
34
34
  fragment_def_error = {
35
35
  "message"=>"No such type Nothing, so it can't be a fragment condition",
36
36
  "locations"=>[{"line"=>5, "column"=>9}],
37
- "path"=>["query getCheese", "cheese", "... on Nothing"],
37
+ "fields"=>["query getCheese", "cheese", "... on Nothing"],
38
38
  }
39
39
  assert_includes(errors, fragment_def_error, "on fragment definitions")
40
40
  end
@@ -39,12 +39,12 @@ describe GraphQL::StaticValidation::FragmentsAreFinite do
39
39
  {
40
40
  "message"=>"Fragment sourceField contains an infinite loop",
41
41
  "locations"=>[{"line"=>12, "column"=>5}],
42
- "path"=>["fragment sourceField"],
42
+ "fields"=>["fragment sourceField"],
43
43
  },
44
44
  {
45
45
  "message"=>"Fragment flavorField contains an infinite loop",
46
46
  "locations"=>[{"line"=>17, "column"=>5}],
47
- "path"=>["fragment flavorField"],
47
+ "fields"=>["fragment flavorField"],
48
48
  }
49
49
  ]
50
50
  assert_equal(expected, errors)
@@ -17,7 +17,7 @@ describe GraphQL::StaticValidation::FragmentTypesExist do
17
17
  fragment_def_error = {
18
18
  "message"=>"Fragment definition has no name",
19
19
  "locations"=>[{"line"=>2, "column"=>5}],
20
- "path"=>["fragment "],
20
+ "fields"=>["fragment "],
21
21
  }
22
22
  assert_includes(errors, fragment_def_error, "on fragment definitions")
23
23
  end
@@ -34,17 +34,17 @@ describe GraphQL::StaticValidation::FragmentsAreOnCompositeTypes do
34
34
  {
35
35
  "message"=>"Invalid fragment on type Boolean (must be Union, Interface or Object)",
36
36
  "locations"=>[{"line"=>6, "column"=>11}],
37
- "path"=>["query getCheese", "cheese", "... on Cheese", "... on Boolean"],
37
+ "fields"=>["query getCheese", "cheese", "... on Cheese", "... on Boolean"],
38
38
  },
39
39
  {
40
40
  "message"=>"Invalid fragment on type DairyProductInput (must be Union, Interface or Object)",
41
41
  "locations"=>[{"line"=>14, "column"=>9}],
42
- "path"=>["query getCheese", "cheese", "... on DairyProductInput"],
42
+ "fields"=>["query getCheese", "cheese", "... on DairyProductInput"],
43
43
  },
44
44
  {
45
45
  "message"=>"Invalid fragment on type Int (must be Union, Interface or Object)",
46
46
  "locations"=>[{"line"=>20, "column"=>5}],
47
- "path"=>["fragment intFields"],
47
+ "fields"=>["fragment intFields"],
48
48
  },
49
49
  ]
50
50
  assert_equal(expected, errors)
@@ -19,7 +19,7 @@ describe GraphQL::StaticValidation::FragmentsAreUsed do
19
19
  assert_includes(errors, {
20
20
  "message"=>"Fragment unusedFields was defined, but not used",
21
21
  "locations"=>[{"line"=>8, "column"=>5}],
22
- "path"=>[],
22
+ "fields"=>[],
23
23
  })
24
24
  end
25
25
 
@@ -27,7 +27,7 @@ describe GraphQL::StaticValidation::FragmentsAreUsed do
27
27
  assert_includes(errors, {
28
28
  "message"=>"Fragment undefinedFields was used, but not defined",
29
29
  "locations"=>[{"line"=>5, "column"=>7}],
30
- "path"=>["query getCheese", "... undefinedFields"]
30
+ "fields"=>["query getCheese", "... undefinedFields"]
31
31
  })
32
32
  end
33
33
 
@@ -32,7 +32,7 @@ describe GraphQL::StaticValidation::MutationRootExists do
32
32
  missing_mutation_root_error = {
33
33
  "message"=>"Schema is not configured for mutations",
34
34
  "locations"=>[{"line"=>2, "column"=>5}],
35
- "path"=>["mutation addBagel"],
35
+ "fields"=>["mutation addBagel"],
36
36
  }
37
37
  assert_includes(errors, missing_mutation_root_error)
38
38
  end
@@ -24,21 +24,21 @@ describe GraphQL::StaticValidation::RequiredArgumentsArePresent do
24
24
  query_root_error = {
25
25
  "message"=>"Field 'cheese' is missing required arguments: id",
26
26
  "locations"=>[{"line"=>4, "column"=>7}],
27
- "path"=>["query getCheese", "cheese"],
27
+ "fields"=>["query getCheese", "cheese"],
28
28
  }
29
29
  assert_includes(errors, query_root_error)
30
30
 
31
31
  fragment_error = {
32
32
  "message"=>"Field 'similarCheese' is missing required arguments: source",
33
33
  "locations"=>[{"line"=>8, "column"=>7}],
34
- "path"=>["fragment cheeseFields", "similarCheese"],
34
+ "fields"=>["fragment cheeseFields", "similarCheese"],
35
35
  }
36
36
  assert_includes(errors, fragment_error)
37
37
 
38
38
  directive_error = {
39
39
  "message"=>"Directive 'skip' is missing required arguments: if",
40
40
  "locations"=>[{"line"=>10, "column"=>10}],
41
- "path"=>["fragment cheeseFields", "id"],
41
+ "fields"=>["fragment cheeseFields", "id"],
42
42
  }
43
43
  assert_includes(errors, directive_error)
44
44
  end
@@ -27,7 +27,7 @@ describe GraphQL::StaticValidation::SubscriptionRootExists do
27
27
  missing_subscription_root_error = {
28
28
  "message"=>"Schema is not configured for subscriptions",
29
29
  "locations"=>[{"line"=>2, "column"=>5}],
30
- "path"=>["subscription"],
30
+ "fields"=>["subscription"],
31
31
  }
32
32
  assert_includes(errors, missing_subscription_root_error)
33
33
  end
@@ -25,22 +25,22 @@ describe GraphQL::StaticValidation::VariableDefaultValuesAreCorrectlyTyped do
25
25
  {
26
26
  "message"=>"Default value for $badFloat doesn't match type Float",
27
27
  "locations"=>[{"line"=>6, "column"=>7}],
28
- "path"=>["query getCheese"],
28
+ "fields"=>["query getCheese"],
29
29
  },
30
30
  {
31
31
  "message"=>"Default value for $badInt doesn't match type Int",
32
32
  "locations"=>[{"line"=>7, "column"=>7}],
33
- "path"=>["query getCheese"],
33
+ "fields"=>["query getCheese"],
34
34
  },
35
35
  {
36
36
  "message"=>"Default value for $badInput doesn't match type DairyProductInput",
37
37
  "locations"=>[{"line"=>9, "column"=>7}],
38
- "path"=>["query getCheese"],
38
+ "fields"=>["query getCheese"],
39
39
  },
40
40
  {
41
41
  "message"=>"Non-null variable $nonNull can't have a default value",
42
42
  "locations"=>[{"line"=>10, "column"=>7}],
43
- "path"=>["query getCheese"],
43
+ "fields"=>["query getCheese"],
44
44
  }
45
45
  ]
46
46
  assert_equal(expected, errors)
@@ -44,22 +44,22 @@ describe GraphQL::StaticValidation::VariableUsagesAreAllowed do
44
44
  {
45
45
  "message"=>"Nullability mismatch on variable $badInt and argument id (Int / Int!)",
46
46
  "locations"=>[{"line"=>14, "column"=>28}],
47
- "path"=>["query getCheese", "badCheese", "id"],
47
+ "fields"=>["query getCheese", "badCheese", "id"],
48
48
  },
49
49
  {
50
50
  "message"=>"Type mismatch on variable $badStr and argument id (String! / Int!)",
51
51
  "locations"=>[{"line"=>15, "column"=>28}],
52
- "path"=>["query getCheese", "badStrCheese", "id"],
52
+ "fields"=>["query getCheese", "badStrCheese", "id"],
53
53
  },
54
54
  {
55
55
  "message"=>"Nullability mismatch on variable $badAnimals and argument source ([DairyAnimal]! / [DairyAnimal!]!)",
56
56
  "locations"=>[{"line"=>18, "column"=>30}],
57
- "path"=>["query getCheese", "cheese", "other", "source"],
57
+ "fields"=>["query getCheese", "cheese", "other", "source"],
58
58
  },
59
59
  {
60
60
  "message"=>"List dimension mismatch on variable $deepAnimals and argument source ([[DairyAnimal!]!]! / [DairyAnimal!]!)",
61
61
  "locations"=>[{"line"=>19, "column"=>32}],
62
- "path"=>["query getCheese", "cheese", "tooDeep", "source"],
62
+ "fields"=>["query getCheese", "cheese", "tooDeep", "source"],
63
63
  }
64
64
  ]
65
65
  assert_equal(expected, errors)
@@ -22,17 +22,17 @@ describe GraphQL::StaticValidation::VariablesAreInputTypes do
22
22
  {
23
23
  "message"=>"AnimalProduct isn't a valid input type (on $interface)",
24
24
  "locations"=>[{"line"=>5, "column"=>7}],
25
- "path"=>["query getCheese"],
25
+ "fields"=>["query getCheese"],
26
26
  },
27
27
  {
28
28
  "message"=>"Milk isn't a valid input type (on $object)",
29
29
  "locations"=>[{"line"=>6, "column"=>7}],
30
- "path"=>["query getCheese"],
30
+ "fields"=>["query getCheese"],
31
31
  },
32
32
  {
33
33
  "message"=>"Cheese isn't a valid input type (on $objects)",
34
34
  "locations"=>[{"line"=>7, "column"=>7}],
35
- "path"=>["query getCheese"],
35
+ "fields"=>["query getCheese"],
36
36
  }
37
37
  ]
38
38
  assert_equal(expected, errors)
@@ -38,17 +38,17 @@ describe GraphQL::StaticValidation::VariablesAreUsedAndDefined do
38
38
  {
39
39
  "message"=>"Variable $notUsedVar is declared by getCheese but not used",
40
40
  "locations"=>[{"line"=>2, "column"=>5}],
41
- "path"=>["query getCheese"],
41
+ "fields"=>["query getCheese"],
42
42
  },
43
43
  {
44
44
  "message"=>"Variable $undefinedVar is used by getCheese but not declared",
45
45
  "locations"=>[{"line"=>11, "column"=>29}],
46
- "path"=>["query getCheese", "cheese", "whatever", "undefined"],
46
+ "fields"=>["query getCheese", "cheese", "whatever", "undefined"],
47
47
  },
48
48
  {
49
49
  "message"=>"Variable $undefinedFragmentVar is used by innerCheeseFields but not declared",
50
50
  "locations"=>[{"line"=>24, "column"=>26}],
51
- "path"=>["fragment innerCheeseFields", "source", "notDefined"],
51
+ "fields"=>["fragment innerCheeseFields", "source", "notDefined"],
52
52
  },
53
53
  ]
54
54
  assert_equal(expected, errors)
@@ -73,7 +73,7 @@ describe GraphQL::StaticValidation::Validator do
73
73
  {
74
74
  "message"=>"Fragment cheeseFields contains an infinite loop",
75
75
  "locations"=>[{"line"=>10, "column"=>9}],
76
- "path"=>["fragment cheeseFields"]
76
+ "fields"=>["fragment cheeseFields"]
77
77
  }
78
78
  ]
79
79
  assert_equal(expected, errors)
@@ -105,6 +105,14 @@ MilkType = GraphQL::ObjectType.define do
105
105
  args[:limit] ? milk.flavors.first(args[:limit]) : milk.flavors
106
106
  }
107
107
  end
108
+ field :executionError do
109
+ type GraphQL::STRING_TYPE
110
+ resolve -> (t, a, c) { raise(GraphQL::ExecutionError, "There was an execution error") }
111
+ end
112
+
113
+ field :allDairy, -> { types[DairyProductUnion] } do
114
+ resolve -> (obj, args, ctx) { CHEESES.values + MILKS.values }
115
+ end
108
116
  end
109
117
 
110
118
  SweetenerInterface = GraphQL::InterfaceType.define do
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.18.14
4
+ version: 0.18.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Mosolgo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-20 00:00:00.000000000 Z
11
+ date: 2016-09-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: codeclimate-test-reporter
@@ -234,6 +234,34 @@ dependencies:
234
234
  - - ">="
235
235
  - !ruby/object:Gem::Version
236
236
  version: '0'
237
+ - !ruby/object:Gem::Dependency
238
+ name: github-pages
239
+ requirement: !ruby/object:Gem::Requirement
240
+ requirements:
241
+ - - ">="
242
+ - !ruby/object:Gem::Version
243
+ version: '0'
244
+ type: :development
245
+ prerelease: false
246
+ version_requirements: !ruby/object:Gem::Requirement
247
+ requirements:
248
+ - - ">="
249
+ - !ruby/object:Gem::Version
250
+ version: '0'
251
+ - !ruby/object:Gem::Dependency
252
+ name: html-proofer
253
+ requirement: !ruby/object:Gem::Requirement
254
+ requirements:
255
+ - - ">="
256
+ - !ruby/object:Gem::Version
257
+ version: '0'
258
+ type: :development
259
+ prerelease: false
260
+ version_requirements: !ruby/object:Gem::Requirement
261
+ requirements:
262
+ - - ">="
263
+ - !ruby/object:Gem::Version
264
+ version: '0'
237
265
  description: A GraphQL server implementation for Ruby. Includes schema definition,
238
266
  query parsing, static validation, type definition, and query execution.
239
267
  email: