graphql 1.8.6 → 1.8.7
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.
- checksums.yaml +5 -5
- data/lib/generators/graphql/mutation_generator.rb +1 -1
- data/lib/generators/graphql/templates/base_enum.erb +3 -1
- data/lib/generators/graphql/templates/base_input_object.erb +3 -1
- data/lib/generators/graphql/templates/base_interface.erb +4 -2
- data/lib/generators/graphql/templates/base_object.erb +3 -1
- data/lib/generators/graphql/templates/base_union.erb +3 -1
- data/lib/generators/graphql/templates/enum.erb +5 -3
- data/lib/generators/graphql/templates/interface.erb +6 -4
- data/lib/generators/graphql/templates/loader.erb +14 -12
- data/lib/generators/graphql/templates/mutation.erb +9 -6
- data/lib/generators/graphql/templates/mutation_type.erb +8 -6
- data/lib/generators/graphql/templates/object.erb +6 -4
- data/lib/generators/graphql/templates/query_type.erb +13 -11
- data/lib/generators/graphql/templates/union.erb +5 -3
- data/lib/graphql/argument.rb +19 -2
- data/lib/graphql/base_type.rb +1 -1
- data/lib/graphql/define/instance_definable.rb +2 -0
- data/lib/graphql/enum_type.rb +1 -0
- data/lib/graphql/execution/instrumentation.rb +28 -20
- data/lib/graphql/field.rb +3 -3
- data/lib/graphql/input_object_type.rb +2 -1
- data/lib/graphql/query.rb +1 -9
- data/lib/graphql/query/variables.rb +1 -18
- data/lib/graphql/relay.rb +0 -1
- data/lib/graphql/relay/mongo_relation_connection.rb +10 -0
- data/lib/graphql/relay/mutation.rb +2 -1
- data/lib/graphql/schema.rb +5 -4
- data/lib/graphql/schema/base_64_bp.rb +25 -0
- data/lib/graphql/schema/base_64_encoder.rb +5 -1
- data/lib/graphql/schema/field.rb +52 -22
- data/lib/graphql/schema/interface.rb +2 -0
- data/lib/graphql/schema/list.rb +3 -15
- data/lib/graphql/schema/member.rb +8 -4
- data/lib/graphql/schema/member/base_dsl_methods.rb +12 -6
- data/lib/graphql/schema/member/has_arguments.rb +7 -0
- data/lib/graphql/schema/member/relay_shortcuts.rb +47 -0
- data/lib/graphql/schema/member/scoped.rb +21 -0
- data/lib/graphql/schema/non_null.rb +8 -17
- data/lib/graphql/schema/resolver.rb +99 -76
- data/lib/graphql/schema/unique_within_type.rb +4 -1
- data/lib/graphql/schema/wrapper.rb +29 -0
- data/lib/graphql/static_validation/validation_context.rb +1 -3
- data/lib/graphql/subscriptions/action_cable_subscriptions.rb +1 -1
- data/lib/graphql/type_kinds.rb +32 -8
- data/lib/graphql/types/relay/base_connection.rb +17 -3
- data/lib/graphql/types/relay/base_edge.rb +12 -0
- data/lib/graphql/version.rb +1 -1
- data/spec/generators/graphql/enum_generator_spec.rb +8 -6
- data/spec/generators/graphql/install_generator_spec.rb +24 -20
- data/spec/generators/graphql/interface_generator_spec.rb +6 -4
- data/spec/generators/graphql/loader_generator_spec.rb +30 -26
- data/spec/generators/graphql/mutation_generator_spec.rb +18 -13
- data/spec/generators/graphql/object_generator_spec.rb +12 -6
- data/spec/generators/graphql/union_generator_spec.rb +10 -4
- data/spec/graphql/authorization_spec.rb +55 -14
- data/spec/graphql/input_object_type_spec.rb +11 -0
- data/spec/graphql/language/generation_spec.rb +8 -6
- data/spec/graphql/language/nodes_spec.rb +8 -6
- data/spec/graphql/relay/connection_instrumentation_spec.rb +1 -1
- data/spec/graphql/relay/mongo_relation_connection_spec.rb +54 -0
- data/spec/graphql/schema/field_spec.rb +9 -0
- data/spec/graphql/schema/list_spec.rb +46 -0
- data/spec/graphql/schema/member/scoped_spec.rb +161 -0
- data/spec/graphql/schema/non_null_spec.rb +46 -0
- data/spec/graphql/schema/object_spec.rb +15 -0
- data/spec/graphql/schema/resolver_spec.rb +165 -25
- data/spec/graphql/subscriptions/serialize_spec.rb +0 -22
- data/spec/graphql/subscriptions_spec.rb +19 -31
- data/spec/support/global_id.rb +23 -0
- data/spec/support/lazy_helpers.rb +1 -1
- data/spec/support/star_trek/data.rb +19 -2
- data/spec/support/star_trek/schema.rb +37 -22
- data/spec/support/star_wars/schema.rb +24 -17
- metadata +220 -208
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a2aa5dc86bfb37cc0c46b7974618bddc91b203b0
|
4
|
+
data.tar.gz: 92979d239d0fbd9a010261dec5d0b1285c617c3f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 26ccb7f54465c14158a933a4bbc52eaba9576725ea06ce1a5425128fd39ad133013383ffa650bc6bbbdf16030bf232ab021da6a1c39ee20933d294b49d5d8d57
|
7
|
+
data.tar.gz: 7ec6717d6a3cf091189269e92d991cd49fdec20802d68cb7c83d60b9ab615535ad626c8163a5022e713f4c9f875bfaec1430b51098ec3e55eca5e91ff6e1a622
|
@@ -38,7 +38,7 @@ module Graphql
|
|
38
38
|
sentinel = /class .*MutationType\s*<\s*[^\s]+?\n/m
|
39
39
|
in_root do
|
40
40
|
gsub_file "#{options[:directory]}/types/mutation_type.rb", / \# TODO\: Add Mutations as fields\s*\n/m, ""
|
41
|
-
inject_into_file "#{options[:directory]}/types/mutation_type.rb", "
|
41
|
+
inject_into_file "#{options[:directory]}/types/mutation_type.rb", " field :#{field_name}, mutation: Mutations::#{mutation_name}\n", after: sentinel, verbose: false, force: false
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
@@ -1,3 +1,5 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
<%
|
1
|
+
module Types
|
2
|
+
class <%= type_ruby_name.split('::')[-1] %> < Types::BaseEnum
|
3
|
+
<% prepared_values.each do |v| %> value "<%= v[0] %>"<%= v.length > 1 ? ", value: #{v[1]}" : "" %>
|
4
|
+
<% end %> end
|
5
|
+
end
|
@@ -1,4 +1,6 @@
|
|
1
|
-
module
|
2
|
-
|
3
|
-
|
4
|
-
<%
|
1
|
+
module Types
|
2
|
+
module <%= type_ruby_name.split('::')[-1] %>
|
3
|
+
include Types::BaseInterface
|
4
|
+
<% normalized_fields.each do |f| %> <%= f.to_ruby %>
|
5
|
+
<% end %> end
|
6
|
+
end
|
@@ -1,15 +1,17 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
1
|
+
module Loaders
|
2
|
+
class <%= class_name %> < GraphQL::Batch::Loader
|
3
|
+
# Define `initialize` to store grouping arguments, eg
|
4
|
+
#
|
5
|
+
# Loaders::<%= class_name %>.for(group).load(value)
|
6
|
+
#
|
7
|
+
# def initialize()
|
8
|
+
# end
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
# `keys` contains each key from `.load(key)`.
|
11
|
+
# Find the corresponding values, then
|
12
|
+
# call `fulfill(key, value)` or `fulfill(key, nil)`
|
13
|
+
# for each key.
|
14
|
+
def perform(keys)
|
15
|
+
end
|
14
16
|
end
|
15
17
|
end
|
@@ -1,11 +1,14 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
module Mutations
|
2
|
+
class <%= mutation_name %> < GraphQL::Schema::RelayClassicMutation
|
3
|
+
# TODO: define return fields
|
4
|
+
# field :post, Types::PostType, null: false
|
4
5
|
|
5
|
-
|
6
|
-
|
6
|
+
# TODO: define arguments
|
7
|
+
# argument :name, String, required: true
|
7
8
|
|
8
|
-
def resolve(**inputs)
|
9
9
|
# TODO: define resolve method
|
10
|
+
# def resolve(name:)
|
11
|
+
# { post: ... }
|
12
|
+
# end
|
10
13
|
end
|
11
14
|
end
|
@@ -1,8 +1,10 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
1
|
+
module Types
|
2
|
+
class MutationType < Types::BaseObject
|
3
|
+
# TODO: remove me
|
4
|
+
field :test_field, String, null: false,
|
5
|
+
description: "An example field added by the generator"
|
6
|
+
def test_field
|
7
|
+
"Hello World"
|
8
|
+
end
|
7
9
|
end
|
8
10
|
end
|
@@ -1,4 +1,6 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
<%
|
4
|
-
<% end %>
|
1
|
+
module Types
|
2
|
+
class <%= type_ruby_name.split('::')[-1] %> < Types::BaseObject
|
3
|
+
<% if options.node %> implements GraphQL::Relay::Node.interface
|
4
|
+
<% end %><% normalized_fields.each do |f| %> <%= f.to_ruby %>
|
5
|
+
<% end %> end
|
6
|
+
end
|
@@ -1,13 +1,15 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
module Types
|
2
|
+
class QueryType < Types::BaseObject
|
3
|
+
# Add root-level fields here.
|
4
|
+
# They will be entry points for queries on your schema.
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
6
|
+
# TODO: remove me
|
7
|
+
field :test_field, String, null: false,
|
8
|
+
description: "An example field added by the generator"
|
9
|
+
def test_field
|
10
|
+
"Hello World!"
|
11
|
+
end
|
11
12
|
<% if options[:relay] %>
|
12
|
-
|
13
|
-
<% end %>end
|
13
|
+
field :node, field: GraphQL::Relay::Node.field
|
14
|
+
<% end %> end
|
15
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
<%
|
1
|
+
module Types
|
2
|
+
class <%= type_ruby_name.split('::')[-1] %> < Types::BaseUnion
|
3
|
+
<% if possible_types.any? %> possible_types [<%= normalized_possible_types.join(", ") %>]
|
4
|
+
<% end %> end
|
5
|
+
end
|
data/lib/graphql/argument.rb
CHANGED
@@ -36,7 +36,8 @@ module GraphQL
|
|
36
36
|
class Argument
|
37
37
|
include GraphQL::Define::InstanceDefinable
|
38
38
|
accepts_definitions :name, :type, :description, :default_value, :as, :prepare
|
39
|
-
|
39
|
+
attr_reader :default_value
|
40
|
+
attr_accessor :description, :name, :as
|
40
41
|
attr_accessor :ast_node
|
41
42
|
alias :graphql_name :name
|
42
43
|
|
@@ -65,7 +66,7 @@ module GraphQL
|
|
65
66
|
@default_value = nil
|
66
67
|
else
|
67
68
|
@has_default_value = true
|
68
|
-
@default_value = new_default_value
|
69
|
+
@default_value = GraphQL::Argument.deep_stringify(new_default_value)
|
69
70
|
end
|
70
71
|
end
|
71
72
|
|
@@ -127,5 +128,21 @@ module GraphQL
|
|
127
128
|
GraphQL::Argument.define(kwargs, &block)
|
128
129
|
end
|
129
130
|
end
|
131
|
+
|
132
|
+
# @api private
|
133
|
+
def self.deep_stringify(val)
|
134
|
+
case val
|
135
|
+
when Array
|
136
|
+
val.map { |v| deep_stringify(v) }
|
137
|
+
when Hash
|
138
|
+
new_val = {}
|
139
|
+
val.each do |k, v|
|
140
|
+
new_val[k.to_s] = deep_stringify(v)
|
141
|
+
end
|
142
|
+
new_val
|
143
|
+
else
|
144
|
+
val
|
145
|
+
end
|
146
|
+
end
|
130
147
|
end
|
131
148
|
end
|
data/lib/graphql/base_type.rb
CHANGED
@@ -177,6 +177,7 @@ module GraphQL
|
|
177
177
|
pending_methods = @pending_methods
|
178
178
|
self.singleton_class.class_eval {
|
179
179
|
pending_methods.each do |method|
|
180
|
+
undef_method(method.name) if method_defined?(method.name)
|
180
181
|
define_method(method.name, method)
|
181
182
|
end
|
182
183
|
}
|
@@ -200,6 +201,7 @@ module GraphQL
|
|
200
201
|
@pending_methods = method_names.map { |n| self.class.instance_method(n) }
|
201
202
|
self.singleton_class.class_eval do
|
202
203
|
method_names.each do |method_name|
|
204
|
+
undef_method(method_name) if method_defined?(method_name)
|
203
205
|
define_method(method_name) { |*args, &block|
|
204
206
|
ensure_defined
|
205
207
|
self.send(method_name, *args, &block)
|
data/lib/graphql/enum_type.rb
CHANGED
@@ -51,30 +51,38 @@ module GraphQL
|
|
51
51
|
|
52
52
|
# Call each before hook, and if they all succeed, yield.
|
53
53
|
# If they don't all succeed, call after_ for each one that succeeded.
|
54
|
-
def call_hooks(instrumenters, object, before_hook_name, after_hook_name
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
#
|
64
|
-
#
|
65
|
-
|
54
|
+
def call_hooks(instrumenters, object, before_hook_name, after_hook_name)
|
55
|
+
begin
|
56
|
+
successful = []
|
57
|
+
instrumenters.each do |instrumenter|
|
58
|
+
instrumenter.public_send(before_hook_name, object)
|
59
|
+
successful << instrumenter
|
60
|
+
end
|
61
|
+
|
62
|
+
# if any before hooks raise an exception, quit calling before hooks,
|
63
|
+
# but call the after hooks on anything that succeeded but also
|
64
|
+
# raise the exception that came from the before hook.
|
65
|
+
rescue => e
|
66
|
+
raise call_after_hooks(successful, object, after_hook_name, e)
|
67
|
+
end
|
68
|
+
|
69
|
+
begin
|
70
|
+
yield # Call the user code
|
71
|
+
ensure
|
72
|
+
ex = call_after_hooks(successful, object, after_hook_name, nil)
|
73
|
+
raise ex if ex
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def call_after_hooks(instrumenters, object, after_hook_name, ex)
|
78
|
+
instrumenters.reverse.each do |instrumenter|
|
66
79
|
begin
|
67
|
-
# Call the next instrumenter on the list,
|
68
|
-
# basically passing along the original block
|
69
|
-
call_hooks(instrumenters, object, before_hook_name, after_hook_name, i + 1) {
|
70
|
-
yield
|
71
|
-
}
|
72
|
-
ensure
|
73
|
-
# Regardless of how the next instrumenter in the list behaves,
|
74
|
-
# call the after_hook of this instrumenter
|
75
80
|
instrumenter.public_send(after_hook_name, object)
|
81
|
+
rescue => e
|
82
|
+
ex = e
|
76
83
|
end
|
77
84
|
end
|
85
|
+
ex
|
78
86
|
end
|
79
87
|
end
|
80
88
|
end
|
data/lib/graphql/field.rb
CHANGED
@@ -156,7 +156,7 @@ module GraphQL
|
|
156
156
|
attr_reader :lazy_resolve_proc
|
157
157
|
|
158
158
|
# @return [String] The name of this field on its {GraphQL::ObjectType} (or {GraphQL::InterfaceType})
|
159
|
-
|
159
|
+
attr_reader :name
|
160
160
|
alias :graphql_name :name
|
161
161
|
|
162
162
|
# @return [String, nil] The client-facing description of this field
|
@@ -175,10 +175,10 @@ module GraphQL
|
|
175
175
|
attr_accessor :complexity
|
176
176
|
|
177
177
|
# @return [Symbol, nil] The method to call on `obj` to return this field (overrides {#name} if present)
|
178
|
-
|
178
|
+
attr_reader :property
|
179
179
|
|
180
180
|
# @return [Object, nil] The key to access with `obj.[]` to resolve this field (overrides {#name} if present)
|
181
|
-
|
181
|
+
attr_reader :hash_key
|
182
182
|
|
183
183
|
# @return [Object, GraphQL::Function] The function used to derive this field
|
184
184
|
attr_accessor :function
|
@@ -93,7 +93,8 @@ module GraphQL
|
|
93
93
|
coerced_value = input_field_defn.type.coerce_input(field_value, ctx)
|
94
94
|
input_values[input_key] = input_field_defn.prepare(coerced_value, ctx)
|
95
95
|
elsif input_field_defn.default_value?
|
96
|
-
|
96
|
+
coerced_value = input_field_defn.type.coerce_input(input_field_defn.default_value, ctx)
|
97
|
+
input_values[input_key] = coerced_value
|
97
98
|
defaults_used << input_key
|
98
99
|
end
|
99
100
|
end
|
data/lib/graphql/query.rb
CHANGED
@@ -29,7 +29,7 @@ module GraphQL
|
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
-
attr_reader :schema, :context, :
|
32
|
+
attr_reader :schema, :context, :provided_variables
|
33
33
|
|
34
34
|
# The value for root types
|
35
35
|
attr_accessor :root_value
|
@@ -60,9 +60,6 @@ module GraphQL
|
|
60
60
|
# @return [String, nil] the triggered event, if this query is a subscription update
|
61
61
|
attr_reader :subscription_topic
|
62
62
|
|
63
|
-
# @return [String, nil]
|
64
|
-
attr_reader :operation_name
|
65
|
-
|
66
63
|
attr_reader :tracers
|
67
64
|
|
68
65
|
# Prepare query `query_string` on `schema`
|
@@ -220,11 +217,6 @@ module GraphQL
|
|
220
217
|
@arguments_cache[irep_or_ast_node][definition]
|
221
218
|
end
|
222
219
|
|
223
|
-
# @return [GraphQL::Language::Nodes::OperationDefinition, nil]
|
224
|
-
def selected_operation
|
225
|
-
with_prepared_ast { @selected_operation }
|
226
|
-
end
|
227
|
-
|
228
220
|
def validation_pipeline
|
229
221
|
with_prepared_ast { @validation_pipeline }
|
230
222
|
end
|
@@ -14,7 +14,7 @@ module GraphQL
|
|
14
14
|
schema = ctx.schema
|
15
15
|
@context = ctx
|
16
16
|
|
17
|
-
@provided_variables = deep_stringify(provided_variables)
|
17
|
+
@provided_variables = GraphQL::Argument.deep_stringify(provided_variables)
|
18
18
|
@errors = []
|
19
19
|
@storage = ast_variables.each_with_object({}) do |ast_variable, memo|
|
20
20
|
# Find the right value for this variable:
|
@@ -52,23 +52,6 @@ module GraphQL
|
|
52
52
|
end
|
53
53
|
|
54
54
|
def_delegators :@storage, :length, :key?, :[], :fetch, :to_h
|
55
|
-
|
56
|
-
private
|
57
|
-
|
58
|
-
def deep_stringify(val)
|
59
|
-
case val
|
60
|
-
when Array
|
61
|
-
val.map { |v| deep_stringify(v) }
|
62
|
-
when Hash
|
63
|
-
new_val = {}
|
64
|
-
val.each do |k, v|
|
65
|
-
new_val[k.to_s] = deep_stringify(v)
|
66
|
-
end
|
67
|
-
new_val
|
68
|
-
else
|
69
|
-
val
|
70
|
-
end
|
71
|
-
end
|
72
55
|
end
|
73
56
|
end
|
74
57
|
end
|
data/lib/graphql/relay.rb
CHANGED
@@ -36,5 +36,15 @@ module GraphQL
|
|
36
36
|
if defined?(Mongoid::Criteria)
|
37
37
|
BaseConnection.register_connection_implementation(Mongoid::Criteria, MongoRelationConnection)
|
38
38
|
end
|
39
|
+
|
40
|
+
# Mongoid 5 and 6
|
41
|
+
if defined?(Mongoid::Relations::Targets::Enumerable)
|
42
|
+
BaseConnection.register_connection_implementation(Mongoid::Relations::Targets::Enumerable, MongoRelationConnection)
|
43
|
+
end
|
44
|
+
|
45
|
+
# Mongoid 7
|
46
|
+
if defined?(Mongoid::Association::Referenced::HasMany::Targets::Enumerable)
|
47
|
+
BaseConnection.register_connection_implementation(Mongoid::Association::Referenced::HasMany::Targets::Enumerable, MongoRelationConnection)
|
48
|
+
end
|
39
49
|
end
|
40
50
|
end
|