graphql 1.12.20 → 1.13.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (125) hide show
  1. checksums.yaml +4 -4
  2. data/lib/generators/graphql/core.rb +3 -1
  3. data/lib/generators/graphql/install_generator.rb +9 -2
  4. data/lib/generators/graphql/mutation_generator.rb +1 -1
  5. data/lib/generators/graphql/object_generator.rb +2 -1
  6. data/lib/generators/graphql/templates/schema.erb +2 -2
  7. data/lib/generators/graphql/type_generator.rb +0 -1
  8. data/lib/graphql/analysis/ast/field_usage.rb +2 -2
  9. data/lib/graphql/analysis/ast/query_complexity.rb +10 -14
  10. data/lib/graphql/analysis/ast/visitor.rb +4 -4
  11. data/lib/graphql/backtrace/table.rb +1 -1
  12. data/lib/graphql/base_type.rb +4 -2
  13. data/lib/graphql/boolean_type.rb +1 -1
  14. data/lib/graphql/dataloader.rb +55 -22
  15. data/lib/graphql/directive/deprecated_directive.rb +1 -1
  16. data/lib/graphql/directive/include_directive.rb +1 -1
  17. data/lib/graphql/directive/skip_directive.rb +1 -1
  18. data/lib/graphql/directive.rb +0 -4
  19. data/lib/graphql/enum_type.rb +5 -1
  20. data/lib/graphql/execution/errors.rb +1 -0
  21. data/lib/graphql/execution/interpreter/arguments.rb +1 -1
  22. data/lib/graphql/execution/interpreter/arguments_cache.rb +2 -2
  23. data/lib/graphql/execution/interpreter/runtime.rb +30 -18
  24. data/lib/graphql/execution/lookahead.rb +2 -2
  25. data/lib/graphql/execution/multiplex.rb +4 -1
  26. data/lib/graphql/float_type.rb +1 -1
  27. data/lib/graphql/id_type.rb +1 -1
  28. data/lib/graphql/int_type.rb +1 -1
  29. data/lib/graphql/introspection/directive_type.rb +1 -1
  30. data/lib/graphql/introspection/entry_points.rb +2 -2
  31. data/lib/graphql/introspection/enum_value_type.rb +2 -2
  32. data/lib/graphql/introspection/field_type.rb +2 -2
  33. data/lib/graphql/introspection/input_value_type.rb +4 -4
  34. data/lib/graphql/introspection/schema_type.rb +2 -2
  35. data/lib/graphql/introspection/type_type.rb +10 -10
  36. data/lib/graphql/language/block_string.rb +2 -6
  37. data/lib/graphql/language/document_from_schema_definition.rb +4 -2
  38. data/lib/graphql/language/lexer.rb +0 -3
  39. data/lib/graphql/language/lexer.rl +0 -4
  40. data/lib/graphql/language/nodes.rb +12 -2
  41. data/lib/graphql/language/parser.rb +442 -434
  42. data/lib/graphql/language/parser.y +5 -4
  43. data/lib/graphql/language/printer.rb +6 -1
  44. data/lib/graphql/language/sanitized_printer.rb +5 -5
  45. data/lib/graphql/language/token.rb +0 -4
  46. data/lib/graphql/name_validator.rb +0 -4
  47. data/lib/graphql/query/arguments.rb +1 -1
  48. data/lib/graphql/query/arguments_cache.rb +1 -1
  49. data/lib/graphql/query/context.rb +15 -2
  50. data/lib/graphql/query/literal_input.rb +1 -1
  51. data/lib/graphql/query/null_context.rb +12 -7
  52. data/lib/graphql/query/serial_execution/field_resolution.rb +1 -1
  53. data/lib/graphql/query/variables.rb +5 -1
  54. data/lib/graphql/relay/edges_instrumentation.rb +0 -1
  55. data/lib/graphql/relay/global_id_resolve.rb +1 -1
  56. data/lib/graphql/relay/page_info.rb +1 -1
  57. data/lib/graphql/rubocop/graphql/base_cop.rb +36 -0
  58. data/lib/graphql/rubocop/graphql/default_null_true.rb +43 -0
  59. data/lib/graphql/rubocop/graphql/default_required_true.rb +43 -0
  60. data/lib/graphql/rubocop.rb +4 -0
  61. data/lib/graphql/schema/addition.rb +37 -28
  62. data/lib/graphql/schema/argument.rb +8 -6
  63. data/lib/graphql/schema/build_from_definition.rb +5 -5
  64. data/lib/graphql/schema/directive/feature.rb +1 -1
  65. data/lib/graphql/schema/directive/flagged.rb +2 -2
  66. data/lib/graphql/schema/directive/include.rb +1 -1
  67. data/lib/graphql/schema/directive/skip.rb +1 -1
  68. data/lib/graphql/schema/directive/transform.rb +1 -1
  69. data/lib/graphql/schema/directive.rb +7 -3
  70. data/lib/graphql/schema/enum.rb +60 -10
  71. data/lib/graphql/schema/enum_value.rb +6 -0
  72. data/lib/graphql/schema/field/connection_extension.rb +1 -1
  73. data/lib/graphql/schema/field.rb +130 -39
  74. data/lib/graphql/schema/field_extension.rb +52 -2
  75. data/lib/graphql/schema/find_inherited_value.rb +1 -0
  76. data/lib/graphql/schema/finder.rb +5 -5
  77. data/lib/graphql/schema/input_object.rb +8 -5
  78. data/lib/graphql/schema/interface.rb +11 -20
  79. data/lib/graphql/schema/introspection_system.rb +1 -1
  80. data/lib/graphql/schema/list.rb +3 -1
  81. data/lib/graphql/schema/member/accepts_definition.rb +15 -3
  82. data/lib/graphql/schema/member/build_type.rb +0 -4
  83. data/lib/graphql/schema/member/cached_graphql_definition.rb +29 -2
  84. data/lib/graphql/schema/member/has_arguments.rb +55 -13
  85. data/lib/graphql/schema/member/has_deprecation_reason.rb +1 -1
  86. data/lib/graphql/schema/member/has_fields.rb +76 -18
  87. data/lib/graphql/schema/member/has_interfaces.rb +90 -0
  88. data/lib/graphql/schema/member.rb +1 -0
  89. data/lib/graphql/schema/non_null.rb +3 -1
  90. data/lib/graphql/schema/object.rb +10 -75
  91. data/lib/graphql/schema/printer.rb +1 -1
  92. data/lib/graphql/schema/relay_classic_mutation.rb +29 -3
  93. data/lib/graphql/schema/resolver/has_payload_type.rb +27 -2
  94. data/lib/graphql/schema/resolver.rb +19 -5
  95. data/lib/graphql/schema/scalar.rb +2 -0
  96. data/lib/graphql/schema/subscription.rb +11 -1
  97. data/lib/graphql/schema/traversal.rb +1 -1
  98. data/lib/graphql/schema/type_expression.rb +1 -1
  99. data/lib/graphql/schema/type_membership.rb +18 -4
  100. data/lib/graphql/schema/union.rb +8 -1
  101. data/lib/graphql/schema/validator/format_validator.rb +3 -5
  102. data/lib/graphql/schema/validator/numericality_validator.rb +1 -0
  103. data/lib/graphql/schema/validator.rb +4 -7
  104. data/lib/graphql/schema/warden.rb +116 -52
  105. data/lib/graphql/schema.rb +106 -22
  106. data/lib/graphql/static_validation/base_visitor.rb +5 -5
  107. data/lib/graphql/static_validation/definition_dependencies.rb +0 -1
  108. data/lib/graphql/static_validation/literal_validator.rb +1 -1
  109. data/lib/graphql/static_validation/rules/argument_literals_are_compatible.rb +1 -1
  110. data/lib/graphql/static_validation/rules/fields_will_merge.rb +15 -8
  111. data/lib/graphql/static_validation/rules/required_arguments_are_present.rb +3 -1
  112. data/lib/graphql/static_validation/rules/required_input_object_attributes_are_present.rb +4 -4
  113. data/lib/graphql/static_validation/rules/variable_usages_are_allowed.rb +7 -7
  114. data/lib/graphql/string_type.rb +1 -1
  115. data/lib/graphql/subscriptions/action_cable_subscriptions.rb +8 -4
  116. data/lib/graphql/subscriptions/event.rb +20 -12
  117. data/lib/graphql/subscriptions.rb +17 -19
  118. data/lib/graphql/types/relay/connection_behaviors.rb +26 -9
  119. data/lib/graphql/types/relay/default_relay.rb +5 -1
  120. data/lib/graphql/types/relay/edge_behaviors.rb +13 -2
  121. data/lib/graphql/types/relay/has_node_field.rb +1 -1
  122. data/lib/graphql/types/relay/has_nodes_field.rb +1 -1
  123. data/lib/graphql/version.rb +1 -1
  124. data/lib/graphql.rb +10 -32
  125. metadata +10 -5
@@ -35,7 +35,8 @@ module GraphQL
35
35
  # It's called when you subclass this base connection, trying to use the
36
36
  # class name to set defaults. You can call it again in the class definition
37
37
  # to override the default (or provide a value, if the default lookup failed).
38
- def edge_type(edge_type_class, edge_class: GraphQL::Relay::Edge, node_type: edge_type_class.node_type, nodes_field: self.has_nodes_field, node_nullable: self.node_nullable, edges_nullable: self.edges_nullable, edge_nullable: self.edge_nullable)
38
+ # @param field_options [Hash] Any extra keyword arguments to pass to the `field :edges, ...` and `field :nodes, ...` configurations
39
+ def edge_type(edge_type_class, edge_class: GraphQL::Relay::Edge, node_type: edge_type_class.node_type, nodes_field: self.has_nodes_field, node_nullable: self.node_nullable, edges_nullable: self.edges_nullable, edge_nullable: self.edge_nullable, field_options: nil)
39
40
  # Set this connection's graphql name
40
41
  node_type_name = node_type.graphql_name
41
42
 
@@ -43,13 +44,22 @@ module GraphQL
43
44
  @edge_type = edge_type_class
44
45
  @edge_class = edge_class
45
46
 
46
- field :edges, [edge_type_class, null: edge_nullable],
47
+ base_field_options = {
48
+ name: :edges,
49
+ type: [edge_type_class, null: edge_nullable],
47
50
  null: edges_nullable,
48
51
  description: "A list of edges.",
49
52
  legacy_edge_class: edge_class, # This is used by the old runtime only, for EdgesInstrumentation
50
- connection: false
53
+ connection: false,
54
+ }
51
55
 
52
- define_nodes_field(node_nullable) if nodes_field
56
+ if field_options
57
+ base_field_options.merge!(field_options)
58
+ end
59
+
60
+ field(**base_field_options)
61
+
62
+ define_nodes_field(node_nullable, field_options: field_options) if nodes_field
53
63
 
54
64
  description("The connection type for #{node_type_name}.")
55
65
  end
@@ -60,8 +70,8 @@ module GraphQL
60
70
  end
61
71
 
62
72
  # Add the shortcut `nodes` field to this connection and its subclasses
63
- def nodes_field(node_nullable: self.node_nullable)
64
- define_nodes_field(node_nullable)
73
+ def nodes_field(node_nullable: self.node_nullable, field_options: nil)
74
+ define_nodes_field(node_nullable, field_options: field_options)
65
75
  end
66
76
 
67
77
  def authorized?(obj, ctx)
@@ -118,11 +128,18 @@ module GraphQL
118
128
 
119
129
  private
120
130
 
121
- def define_nodes_field(nullable)
122
- field :nodes, [@node_type, null: nullable],
131
+ def define_nodes_field(nullable, field_options: nil)
132
+ base_field_options = {
133
+ name: :nodes,
134
+ type: [@node_type, null: nullable],
123
135
  null: nullable,
124
136
  description: "A list of nodes.",
125
- connection: false
137
+ connection: false,
138
+ }
139
+ if field_options
140
+ base_field_options.merge!(field_options)
141
+ end
142
+ field(**base_field_options)
126
143
  end
127
144
  end
128
145
 
@@ -17,7 +17,11 @@ module GraphQL
17
17
  end
18
18
 
19
19
  def to_graphql
20
- type_defn = super
20
+ type_defn = if method(:to_graphql).super_method.arity
21
+ super(silence_deprecation_warning: true)
22
+ else
23
+ super
24
+ end
21
25
  type_defn.default_relay = default_relay?
22
26
  type_defn
23
27
  end
@@ -16,11 +16,22 @@ module GraphQL
16
16
  #
17
17
  # @param node_type [Class] A `Schema::Object` subclass
18
18
  # @param null [Boolean]
19
- def node_type(node_type = nil, null: self.node_nullable)
19
+ # @param field_options [Hash] Any extra arguments to pass to the `field :node` configuration
20
+ def node_type(node_type = nil, null: self.node_nullable, field_options: nil)
20
21
  if node_type
21
22
  @node_type = node_type
22
23
  # Add a default `node` field
23
- field :node, node_type, null: null, description: "The item at the end of the edge.", connection: false
24
+ base_field_options = {
25
+ name: :node,
26
+ type: node_type,
27
+ null: null,
28
+ description: "The item at the end of the edge.",
29
+ connection: false,
30
+ }
31
+ if field_options
32
+ base_field_options.merge!(field_options)
33
+ end
34
+ field(**base_field_options)
24
35
  end
25
36
  @node_type
26
37
  end
@@ -22,7 +22,7 @@ module GraphQL
22
22
 
23
23
  def field_block
24
24
  Proc.new {
25
- argument :id, "ID!", required: true,
25
+ argument :id, "ID!",
26
26
  description: "ID of the object."
27
27
 
28
28
  def resolve(obj, args, ctx)
@@ -22,7 +22,7 @@ module GraphQL
22
22
 
23
23
  def field_block
24
24
  Proc.new {
25
- argument :ids, "[ID!]!", required: true,
25
+ argument :ids, "[ID!]!",
26
26
  description: "IDs of the objects."
27
27
 
28
28
  def resolve(obj, args, ctx)
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module GraphQL
3
- VERSION = "1.12.20"
3
+ VERSION = "1.13.1"
4
4
  end
data/lib/graphql.rb CHANGED
@@ -55,31 +55,6 @@ module GraphQL
55
55
  def self.scan_with_ragel(graphql_string)
56
56
  GraphQL::Language::Lexer.tokenize(graphql_string)
57
57
  end
58
-
59
- # Support Ruby 2.2 by implementing `-"str"`. If we drop 2.2 support, we can remove this backport.
60
- if !String.method_defined?(:-@)
61
- module StringDedupBackport
62
- refine String do
63
- def -@
64
- if frozen?
65
- self
66
- else
67
- self.dup.freeze
68
- end
69
- end
70
- end
71
- end
72
- end
73
-
74
- if !String.method_defined?(:match?)
75
- module StringMatchBackport
76
- refine String do
77
- def match?(pattern)
78
- self =~ pattern
79
- end
80
- end
81
- end
82
- end
83
58
  end
84
59
 
85
60
  # Order matters for these:
@@ -125,10 +100,14 @@ require "graphql/execution"
125
100
  require "graphql/pagination"
126
101
  require "graphql/schema"
127
102
  require "graphql/query"
103
+ require "graphql/types"
104
+ require "graphql/dataloader"
105
+ require "graphql/filter"
106
+ require "graphql/internal_representation"
128
107
  require "graphql/directive"
108
+ require "graphql/static_validation"
129
109
  require "graphql/execution"
130
- require "graphql/types"
131
- require "graphql/relay"
110
+ require "graphql/deprecation"
132
111
  require "graphql/boolean_type"
133
112
  require "graphql/float_type"
134
113
  require "graphql/id_type"
@@ -137,11 +116,8 @@ require "graphql/string_type"
137
116
  require "graphql/schema/built_in_types"
138
117
  require "graphql/schema/loader"
139
118
  require "graphql/schema/printer"
140
- require "graphql/filter"
141
- require "graphql/internal_representation"
142
- require "graphql/static_validation"
143
- require "graphql/dataloader"
144
119
  require "graphql/introspection"
120
+ require "graphql/relay"
145
121
 
146
122
  require "graphql/version"
147
123
  require "graphql/compatibility"
@@ -155,7 +131,9 @@ require "graphql/authorization"
155
131
  require "graphql/unauthorized_error"
156
132
  require "graphql/unauthorized_field_error"
157
133
  require "graphql/load_application_object_failed_error"
158
- require "graphql/deprecation"
134
+ require "graphql/directive/include_directive"
135
+ require "graphql/directive/skip_directive"
136
+ require "graphql/directive/deprecated_directive"
159
137
 
160
138
  module GraphQL
161
139
  # Ruby has `deprecate_constant`,
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: 1.12.20
4
+ version: 1.13.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Mosolgo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-11-17 00:00:00.000000000 Z
11
+ date: 2021-12-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: benchmark-ips
@@ -128,14 +128,14 @@ dependencies:
128
128
  requirements:
129
129
  - - '='
130
130
  - !ruby/object:Gem::Version
131
- version: '0.68'
131
+ version: '1.12'
132
132
  type: :development
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
136
  - - '='
137
137
  - !ruby/object:Gem::Version
138
- version: '0.68'
138
+ version: '1.12'
139
139
  - !ruby/object:Gem::Dependency
140
140
  name: parser
141
141
  requirement: !ruby/object:Gem::Requirement
@@ -467,6 +467,10 @@ files:
467
467
  - lib/graphql/relay/range_add.rb
468
468
  - lib/graphql/relay/relation_connection.rb
469
469
  - lib/graphql/relay/type_extensions.rb
470
+ - lib/graphql/rubocop.rb
471
+ - lib/graphql/rubocop/graphql/base_cop.rb
472
+ - lib/graphql/rubocop/graphql/default_null_true.rb
473
+ - lib/graphql/rubocop/graphql/default_required_true.rb
470
474
  - lib/graphql/runtime_type_error.rb
471
475
  - lib/graphql/scalar_type.rb
472
476
  - lib/graphql/schema.rb
@@ -514,6 +518,7 @@ files:
514
518
  - lib/graphql/schema/member/has_deprecation_reason.rb
515
519
  - lib/graphql/schema/member/has_directives.rb
516
520
  - lib/graphql/schema/member/has_fields.rb
521
+ - lib/graphql/schema/member/has_interfaces.rb
517
522
  - lib/graphql/schema/member/has_path.rb
518
523
  - lib/graphql/schema/member/has_unresolved_type_error.rb
519
524
  - lib/graphql/schema/member/has_validators.rb
@@ -695,7 +700,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
695
700
  requirements:
696
701
  - - ">="
697
702
  - !ruby/object:Gem::Version
698
- version: 2.2.0
703
+ version: 2.4.0
699
704
  required_rubygems_version: !ruby/object:Gem::Requirement
700
705
  requirements:
701
706
  - - ">="