graphql 1.10.0.pre3 → 1.10.0.pre4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/lib/generators/graphql/templates/schema.erb +7 -0
  3. data/lib/graphql/argument.rb +3 -35
  4. data/lib/graphql/define/assign_enum_value.rb +1 -1
  5. data/lib/graphql/define/assign_object_field.rb +3 -3
  6. data/lib/graphql/define/defined_object_proxy.rb +8 -2
  7. data/lib/graphql/define/instance_definable.rb +10 -106
  8. data/lib/graphql/directive.rb +4 -0
  9. data/lib/graphql/enum_type.rb +1 -71
  10. data/lib/graphql/execution/execute.rb +1 -1
  11. data/lib/graphql/execution/interpreter/runtime.rb +48 -8
  12. data/lib/graphql/execution/multiplex.rb +3 -3
  13. data/lib/graphql/field.rb +1 -117
  14. data/lib/graphql/function.rb +1 -30
  15. data/lib/graphql/input_object_type.rb +1 -23
  16. data/lib/graphql/interface_type.rb +1 -22
  17. data/lib/graphql/language/document_from_schema_definition.rb +9 -3
  18. data/lib/graphql/language/nodes.rb +2 -2
  19. data/lib/graphql/object_type.rb +1 -21
  20. data/lib/graphql/query.rb +0 -1
  21. data/lib/graphql/query/context.rb +2 -5
  22. data/lib/graphql/relay/connection_type.rb +2 -1
  23. data/lib/graphql/relay/edge_type.rb +1 -0
  24. data/lib/graphql/relay/mutation.rb +1 -86
  25. data/lib/graphql/relay/node.rb +2 -2
  26. data/lib/graphql/scalar_type.rb +1 -58
  27. data/lib/graphql/schema.rb +60 -9
  28. data/lib/graphql/schema/build_from_definition.rb +6 -1
  29. data/lib/graphql/schema/directive.rb +7 -1
  30. data/lib/graphql/schema/enum_value.rb +1 -0
  31. data/lib/graphql/schema/introspection_system.rb +4 -1
  32. data/lib/graphql/schema/list.rb +17 -2
  33. data/lib/graphql/schema/loader.rb +9 -3
  34. data/lib/graphql/schema/mutation.rb +1 -1
  35. data/lib/graphql/schema/object.rb +0 -4
  36. data/lib/graphql/schema/relay_classic_mutation.rb +1 -1
  37. data/lib/graphql/schema/resolver.rb +1 -1
  38. data/lib/graphql/schema/subscription.rb +5 -5
  39. data/lib/graphql/schema/type_membership.rb +1 -1
  40. data/lib/graphql/schema/union.rb +1 -1
  41. data/lib/graphql/subscriptions.rb +2 -2
  42. data/lib/graphql/subscriptions/action_cable_subscriptions.rb +1 -1
  43. data/lib/graphql/tracing.rb +7 -3
  44. data/lib/graphql/tracing/active_support_notifications_tracing.rb +4 -0
  45. data/lib/graphql/tracing/appsignal_tracing.rb +8 -0
  46. data/lib/graphql/tracing/data_dog_tracing.rb +8 -0
  47. data/lib/graphql/tracing/new_relic_tracing.rb +8 -0
  48. data/lib/graphql/tracing/platform_tracing.rb +25 -4
  49. data/lib/graphql/tracing/prometheus_tracing.rb +8 -0
  50. data/lib/graphql/tracing/scout_tracing.rb +8 -0
  51. data/lib/graphql/tracing/skylight_tracing.rb +8 -0
  52. data/lib/graphql/union_type.rb +12 -27
  53. data/lib/graphql/version.rb +1 -1
  54. metadata +8 -8
@@ -10,7 +10,7 @@ module GraphQL
10
10
  # - Take care to reload context when re-delivering the subscription. (see {Query#subscription_update?})
11
11
  #
12
12
  # @example Adding ActionCableSubscriptions to your schema
13
- # MySchema = GraphQL::Schema.define do
13
+ # class MySchema < GraphQL::Schema
14
14
  # # ...
15
15
  # use GraphQL::Subscriptions::ActionCableSubscriptions
16
16
  # end
@@ -18,12 +18,12 @@ module GraphQL
18
18
  # __Warning:__ Installing/uninstalling tracers is not thread-safe. Do it during application boot only.
19
19
  #
20
20
  # @example Sending custom events
21
- # GraphQL::Tracing.trace("my_custom_event", { ... }) do
21
+ # query.trace("my_custom_event", { ... }) do
22
22
  # # do stuff ...
23
23
  # end
24
24
  #
25
25
  # @example Adding a tracer to a schema
26
- # MySchema = GraphQL::Schema.define do
26
+ # class MySchema < GraphQL::Schema
27
27
  # tracer MyTracer # <= responds to .trace(key, data, &block)
28
28
  # end
29
29
  #
@@ -43,7 +43,11 @@ module GraphQL
43
43
  # execute_query | `{ query: GraphQL::Query }`
44
44
  # execute_query_lazy | `{ query: GraphQL::Query?, multiplex: GraphQL::Execution::Multiplex? }`
45
45
  # execute_field | `{ context: GraphQL::Query::Context::FieldResolutionContext?, owner: Class?, field: GraphQL::Schema::Field?, query: GraphQL::Query?, path: Array<String, Integer>?}`
46
- # execute_field_lazy | `{ context: GraphQL::Query::Context::FieldResolutionContext?, owner: Class?, field: GraphQL::Schema::Field?, query: GraphqL::Query?, path: Array<String, Integer>?}`
46
+ # execute_field_lazy | `{ context: GraphQL::Query::Context::FieldResolutionContext?, owner: Class?, field: GraphQL::Schema::Field?, query: GraphQL::Query?, path: Array<String, Integer>?}`
47
+ # authorized | `{ context: GraphQL::Query::Context, type: Class, object: Object, path: Array<String, Integer> }`
48
+ # authorized_lazy | `{ context: GraphQL::Query::Context, type: Class, object: Object, path: Array<String, Integer> }`
49
+ # resolve_type | `{ context: GraphQL::Query::Context, type: Class, object: Object, path: Array<String, Integer> }`
50
+ # resolve_type_lazy | `{ context: GraphQL::Query::Context, type: Class, object: Object, path: Array<String, Integer> }`
47
51
  #
48
52
  # Note that `execute_field` and `execute_field_lazy` receive different data in different settings:
49
53
  #
@@ -17,6 +17,10 @@ module GraphQL
17
17
  "execute_query_lazy" => "execute_query_lazy.graphql",
18
18
  "execute_field" => "execute_field.graphql",
19
19
  "execute_field_lazy" => "execute_field_lazy.graphql",
20
+ "authorized" => "authorized.graphql",
21
+ "authorized_lazy" => "authorized_lazy.graphql",
22
+ "resolve_type" => "resolve_type.graphql",
23
+ "resolve_type_lazy" => "resolve_type.graphql",
20
24
  }
21
25
 
22
26
  def self.trace(key, metadata)
@@ -23,6 +23,14 @@ module GraphQL
23
23
  def platform_field_key(type, field)
24
24
  "#{type.graphql_name}.#{field.graphql_name}.graphql"
25
25
  end
26
+
27
+ def platform_authorized_key(type)
28
+ "#{type.graphql_name}.authorized.graphql"
29
+ end
30
+
31
+ def platform_resolve_type_key(type)
32
+ "#{type.graphql_name}.resolve_type.graphql"
33
+ end
26
34
  end
27
35
  end
28
36
  end
@@ -63,6 +63,14 @@ module GraphQL
63
63
  def platform_field_key(type, field)
64
64
  "#{type.graphql_name}.#{field.graphql_name}"
65
65
  end
66
+
67
+ def platform_authorized_key(type)
68
+ "#{type.graphql_name}.authorized"
69
+ end
70
+
71
+ def platform_resolve_type_key(type)
72
+ "#{type.graphql_name}.resolve_type"
73
+ end
66
74
  end
67
75
  end
68
76
  end
@@ -49,6 +49,14 @@ module GraphQL
49
49
  def platform_field_key(type, field)
50
50
  "GraphQL/#{type.graphql_name}/#{field.graphql_name}"
51
51
  end
52
+
53
+ def platform_authorized_key(type)
54
+ "GraphQL/Authorize/#{type.graphql_name}"
55
+ end
56
+
57
+ def platform_resolve_type_key(type)
58
+ "GraphQL/ResolveType/#{type.graphql_name}"
59
+ end
52
60
  end
53
61
  end
54
62
  end
@@ -21,7 +21,6 @@ module GraphQL
21
21
  def trace(key, data)
22
22
  case key
23
23
  when "lex", "parse", "validate", "analyze_query", "analyze_multiplex", "execute_query", "execute_query_lazy", "execute_multiplex"
24
- data.fetch(:query).context.namespace(self.class)[:platform_key_cache] = {} if key == "execute_query"
25
24
  platform_key = @platform_keys.fetch(key)
26
25
  platform_trace(platform_key, key, data) do
27
26
  yield
@@ -33,9 +32,9 @@ module GraphQL
33
32
  trace_field = true # implemented with instrumenter
34
33
  else
35
34
  field = data[:field]
36
- platform_key_cache = data.fetch(:query).context.namespace(self.class).fetch(:platform_key_cache)
37
- platform_key = platform_key_cache.fetch(field) do
38
- platform_key_cache[field] = platform_field_key(data[:owner], field)
35
+ cache = platform_key_cache(data.fetch(:query).context)
36
+ platform_key = cache.fetch(field) do
37
+ cache[field] = platform_field_key(data[:owner], field)
39
38
  end
40
39
 
41
40
  return_type = field.type.unwrap
@@ -53,6 +52,24 @@ module GraphQL
53
52
  else
54
53
  yield
55
54
  end
55
+ when "authorized", "authorized_lazy"
56
+ cache = platform_key_cache(data.fetch(:context))
57
+ type = data.fetch(:type)
58
+ platform_key = cache.fetch(type) do
59
+ cache[type] = platform_authorized_key(type)
60
+ end
61
+ platform_trace(platform_key, key, data) do
62
+ yield
63
+ end
64
+ when "resolve_type", "resolve_type_lazy"
65
+ cache = platform_key_cache(data.fetch(:context))
66
+ type = data.fetch(:type)
67
+ platform_key = cache.fetch(type) do
68
+ cache[type] = platform_resolve_type_key(type)
69
+ end
70
+ platform_trace(platform_key, key, data) do
71
+ yield
72
+ end
56
73
  else
57
74
  # it's a custom key
58
75
  yield
@@ -87,6 +104,10 @@ module GraphQL
87
104
 
88
105
  private
89
106
  attr_reader :options
107
+
108
+ def platform_key_cache(ctx)
109
+ ctx.namespace(self.class)[:platform_key_cache] ||= {}
110
+ end
90
111
  end
91
112
  end
92
113
  end
@@ -36,6 +36,14 @@ module GraphQL
36
36
  "#{type.graphql_name}.#{field.graphql_name}"
37
37
  end
38
38
 
39
+ def platform_authorized_key(type)
40
+ "#{type.graphql_name}.authorized"
41
+ end
42
+
43
+ def platform_resolve_type_key(type)
44
+ "#{type.graphql_name}.resolve_type"
45
+ end
46
+
39
47
  private
40
48
 
41
49
  def instrument_execution(platform_key, key, data, &block)
@@ -30,6 +30,14 @@ module GraphQL
30
30
  def platform_field_key(type, field)
31
31
  "#{type.graphql_name}.#{field.graphql_name}"
32
32
  end
33
+
34
+ def platform_authorized_key(type)
35
+ "#{type.graphql_name}.authorized"
36
+ end
37
+
38
+ def platform_resolve_type_key(type)
39
+ "#{type.graphql_name}.resolve_type"
40
+ end
33
41
  end
34
42
  end
35
43
  end
@@ -57,6 +57,14 @@ module GraphQL
57
57
  def platform_field_key(type, field)
58
58
  "graphql.#{type.graphql_name}.#{field.graphql_name}"
59
59
  end
60
+
61
+ def platform_authorized_key(type)
62
+ "graphql.authorized.#{type.graphql_name}"
63
+ end
64
+
65
+ def platform_resolve_type_key(type)
66
+ "graphql.resolve_type.#{type.graphql_name}"
67
+ end
60
68
  end
61
69
  end
62
70
  end
@@ -1,31 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
  module GraphQL
3
- # A Union is is a collection of object types which may appear in the same place.
4
- #
5
- # The members of a union are declared with `possible_types`.
6
- #
7
- # @example A union of object types
8
- # MediaUnion = GraphQL::UnionType.define do
9
- # name "Media"
10
- # description "Media objects which you can enjoy"
11
- # possible_types [AudioType, ImageType, VideoType]
12
- # end
13
- #
14
- # A union itself has no fields; only its members have fields.
15
- # So, when you query, you must use fragment spreads to access fields.
16
- #
17
- # @example Querying for fields on union members
18
- # {
19
- # searchMedia(name: "Jens Lekman") {
20
- # ... on Audio { name, duration }
21
- # ... on Image { name, height, width }
22
- # ... on Video { name, length, quality }
23
- # }
24
- # }
25
- #
3
+ # @api deprecated
26
4
  class UnionType < GraphQL::BaseType
5
+ # Rubocop was unhappy about the syntax when this was a proc literal
6
+ class AcceptPossibleTypesDefinition
7
+ def self.call(target, possible_types, options = {})
8
+ target.add_possible_types(possible_types, **options)
9
+ end
10
+ end
11
+
27
12
  accepts_definitions :resolve_type, :type_membership_class,
28
- possible_types: ->(target, possible_types, options = {}) { target.add_possible_types(possible_types, options) }
13
+ possible_types: AcceptPossibleTypesDefinition
29
14
  ensure_defined :possible_types, :resolve_type, :resolve_type_proc, :type_membership_class
30
15
 
31
16
  attr_accessor :resolve_type_proc
@@ -72,13 +57,13 @@ module GraphQL
72
57
  # This is a re-assignment, so clear the previous values
73
58
  @type_memberships = []
74
59
  @cached_possible_types = nil
75
- add_possible_types(types, {})
60
+ add_possible_types(types, **{})
76
61
  end
77
62
 
78
- def add_possible_types(types, options)
63
+ def add_possible_types(types, **options)
79
64
  @type_memberships ||= []
80
65
  Array(types).each { |t|
81
- @type_memberships << self.type_membership_class.new(self, t, options)
66
+ @type_memberships << self.type_membership_class.new(self, t, **options)
82
67
  }
83
68
  nil
84
69
  end
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module GraphQL
3
- VERSION = "1.10.0.pre3"
3
+ VERSION = "1.10.0.pre4"
4
4
  end
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.10.0.pre3
4
+ version: 1.10.0.pre4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Mosolgo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-12-17 00:00:00.000000000 Z
11
+ date: 2020-01-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: benchmark-ips
@@ -182,30 +182,30 @@ dependencies:
182
182
  name: racc
183
183
  requirement: !ruby/object:Gem::Requirement
184
184
  requirements:
185
- - - '='
185
+ - - "~>"
186
186
  - !ruby/object:Gem::Version
187
- version: 1.4.15
187
+ version: '1.4'
188
188
  type: :development
189
189
  prerelease: false
190
190
  version_requirements: !ruby/object:Gem::Requirement
191
191
  requirements:
192
- - - '='
192
+ - - "~>"
193
193
  - !ruby/object:Gem::Version
194
- version: 1.4.15
194
+ version: '1.4'
195
195
  - !ruby/object:Gem::Dependency
196
196
  name: rake
197
197
  requirement: !ruby/object:Gem::Requirement
198
198
  requirements:
199
199
  - - "~>"
200
200
  - !ruby/object:Gem::Version
201
- version: '11'
201
+ version: '12'
202
202
  type: :development
203
203
  prerelease: false
204
204
  version_requirements: !ruby/object:Gem::Requirement
205
205
  requirements:
206
206
  - - "~>"
207
207
  - !ruby/object:Gem::Version
208
- version: '11'
208
+ version: '12'
209
209
  - !ruby/object:Gem::Dependency
210
210
  name: rubocop
211
211
  requirement: !ruby/object:Gem::Requirement