graphql 2.3.14 → 2.3.16
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/generators/graphql/orm_mutations_base.rb +1 -1
- data/lib/generators/graphql/templates/base_resolver.erb +2 -0
- data/lib/generators/graphql/type_generator.rb +1 -1
- data/lib/graphql/analysis.rb +1 -1
- data/lib/graphql/execution/interpreter/resolve.rb +10 -6
- data/lib/graphql/language/comment.rb +18 -0
- data/lib/graphql/language/document_from_schema_definition.rb +38 -4
- data/lib/graphql/language/lexer.rb +15 -12
- data/lib/graphql/language/nodes.rb +22 -14
- data/lib/graphql/language/parser.rb +5 -0
- data/lib/graphql/language/printer.rb +23 -7
- data/lib/graphql/language.rb +6 -5
- data/lib/graphql/query.rb +1 -1
- data/lib/graphql/rubocop/graphql/field_type_in_block.rb +9 -1
- data/lib/graphql/schema/argument.rb +13 -1
- data/lib/graphql/schema/enum.rb +1 -0
- data/lib/graphql/schema/enum_value.rb +9 -1
- data/lib/graphql/schema/field.rb +23 -3
- data/lib/graphql/schema/interface.rb +1 -0
- data/lib/graphql/schema/member/base_dsl_methods.rb +15 -0
- data/lib/graphql/schema/member/has_arguments.rb +2 -2
- data/lib/graphql/schema/member/has_fields.rb +2 -2
- data/lib/graphql/schema/resolver.rb +3 -4
- data/lib/graphql/schema/visibility/migration.rb +188 -0
- data/lib/graphql/schema/visibility/subset.rb +509 -0
- data/lib/graphql/schema/visibility.rb +30 -0
- data/lib/graphql/schema.rb +46 -41
- data/lib/graphql/static_validation/rules/directives_are_in_valid_locations.rb +2 -0
- data/lib/graphql/testing/helpers.rb +2 -1
- data/lib/graphql/tracing/notifications_trace.rb +2 -2
- data/lib/graphql/version.rb +1 -1
- metadata +10 -8
- data/lib/graphql/schema/subset.rb +0 -509
- data/lib/graphql/schema/types_migration.rb +0 -187
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eba638ac8e67c3d902cbc181c1236f58ed00b58c17ddb3dfa49a506e37c2e413
|
4
|
+
data.tar.gz: 2b7912e761ebbfc5188603c90f0ec273ed06d58cf648f2690be483b38760cde5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2eddfe7d8008e1fa918f3e5ab12deab7f85e4edf4d73474f8fd878c321c10f6d711ef7edcdb53ec227852f240feca0fbcd1e18850ec2665ab58ff1af005fee71
|
7
|
+
data.tar.gz: 0464ae90b5770e507bcffb02ef8b99fbff8da6f521c1704306674aca5bfd96609b0c72a088589f650e64466b8746661a3967d470e325bf4afe8100a68fadafa5
|
@@ -18,7 +18,7 @@ module Graphql
|
|
18
18
|
class_option :orm, banner: "NAME", type: :string, required: true,
|
19
19
|
desc: "ORM to generate the controller for"
|
20
20
|
|
21
|
-
class_option
|
21
|
+
class_option :namespaced_types,
|
22
22
|
type: :boolean,
|
23
23
|
required: false,
|
24
24
|
default: false,
|
data/lib/graphql/analysis.rb
CHANGED
@@ -81,7 +81,7 @@ module GraphQL
|
|
81
81
|
end
|
82
82
|
rescue Timeout::Error
|
83
83
|
[GraphQL::AnalysisError.new("Timeout on validation of query")]
|
84
|
-
rescue GraphQL::UnauthorizedError
|
84
|
+
rescue GraphQL::UnauthorizedError, GraphQL::ExecutionError
|
85
85
|
# This error was raised during analysis and will be returned the client before execution
|
86
86
|
[]
|
87
87
|
end
|
@@ -12,12 +12,16 @@ module GraphQL
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def self.resolve_each_depth(lazies_at_depth, dataloader)
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
15
|
+
smallest_depth = nil
|
16
|
+
lazies_at_depth.each_key do |depth_key|
|
17
|
+
smallest_depth ||= depth_key
|
18
|
+
if depth_key < smallest_depth
|
19
|
+
smallest_depth = depth_key
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
if smallest_depth
|
24
|
+
lazies = lazies_at_depth.delete(smallest_depth)
|
21
25
|
if lazies.any?
|
22
26
|
dataloader.append_job {
|
23
27
|
lazies.each(&:value) # resolve these Lazy instances
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module GraphQL
|
3
|
+
module Language
|
4
|
+
module Comment
|
5
|
+
def self.print(str, indent: '')
|
6
|
+
lines = str.split("\n").map do |line|
|
7
|
+
comment_str = "".dup
|
8
|
+
comment_str << indent
|
9
|
+
comment_str << "# "
|
10
|
+
comment_str << line
|
11
|
+
comment_str.rstrip
|
12
|
+
end
|
13
|
+
|
14
|
+
lines.join("\n") + "\n"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -18,6 +18,7 @@ module GraphQL
|
|
18
18
|
include_built_in_directives: false, include_built_in_scalars: false, always_include_schema: false
|
19
19
|
)
|
20
20
|
@schema = schema
|
21
|
+
@context = context
|
21
22
|
@always_include_schema = always_include_schema
|
22
23
|
@include_introspection_types = include_introspection_types
|
23
24
|
@include_built_in_scalars = include_built_in_scalars
|
@@ -58,6 +59,7 @@ module GraphQL
|
|
58
59
|
|
59
60
|
GraphQL::Language::Nodes::ObjectTypeDefinition.new(
|
60
61
|
name: object_type.graphql_name,
|
62
|
+
comment: object_type.comment,
|
61
63
|
interfaces: ints,
|
62
64
|
fields: build_field_nodes(@types.fields(object_type)),
|
63
65
|
description: object_type.description,
|
@@ -68,6 +70,7 @@ module GraphQL
|
|
68
70
|
def build_field_node(field)
|
69
71
|
GraphQL::Language::Nodes::FieldDefinition.new(
|
70
72
|
name: field.graphql_name,
|
73
|
+
comment: field.comment,
|
71
74
|
arguments: build_argument_nodes(@types.arguments(field)),
|
72
75
|
type: build_type_name_node(field.type),
|
73
76
|
description: field.description,
|
@@ -78,6 +81,7 @@ module GraphQL
|
|
78
81
|
def build_union_type_node(union_type)
|
79
82
|
GraphQL::Language::Nodes::UnionTypeDefinition.new(
|
80
83
|
name: union_type.graphql_name,
|
84
|
+
comment: union_type.comment,
|
81
85
|
description: union_type.description,
|
82
86
|
types: @types.possible_types(union_type).sort_by(&:graphql_name).map { |type| build_type_name_node(type) },
|
83
87
|
directives: directives(union_type),
|
@@ -87,6 +91,7 @@ module GraphQL
|
|
87
91
|
def build_interface_type_node(interface_type)
|
88
92
|
GraphQL::Language::Nodes::InterfaceTypeDefinition.new(
|
89
93
|
name: interface_type.graphql_name,
|
94
|
+
comment: interface_type.comment,
|
90
95
|
interfaces: @types.interfaces(interface_type).sort_by(&:graphql_name).map { |type| build_type_name_node(type) },
|
91
96
|
description: interface_type.description,
|
92
97
|
fields: build_field_nodes(@types.fields(interface_type)),
|
@@ -97,6 +102,7 @@ module GraphQL
|
|
97
102
|
def build_enum_type_node(enum_type)
|
98
103
|
GraphQL::Language::Nodes::EnumTypeDefinition.new(
|
99
104
|
name: enum_type.graphql_name,
|
105
|
+
comment: enum_type.comment,
|
100
106
|
values: @types.enum_values(enum_type).sort_by(&:graphql_name).map do |enum_value|
|
101
107
|
build_enum_value_node(enum_value)
|
102
108
|
end,
|
@@ -108,6 +114,7 @@ module GraphQL
|
|
108
114
|
def build_enum_value_node(enum_value)
|
109
115
|
GraphQL::Language::Nodes::EnumValueDefinition.new(
|
110
116
|
name: enum_value.graphql_name,
|
117
|
+
comment: enum_value.comment,
|
111
118
|
description: enum_value.description,
|
112
119
|
directives: directives(enum_value),
|
113
120
|
)
|
@@ -116,6 +123,7 @@ module GraphQL
|
|
116
123
|
def build_scalar_type_node(scalar_type)
|
117
124
|
GraphQL::Language::Nodes::ScalarTypeDefinition.new(
|
118
125
|
name: scalar_type.graphql_name,
|
126
|
+
comment: scalar_type.comment,
|
119
127
|
description: scalar_type.description,
|
120
128
|
directives: directives(scalar_type),
|
121
129
|
)
|
@@ -130,6 +138,7 @@ module GraphQL
|
|
130
138
|
|
131
139
|
argument_node = GraphQL::Language::Nodes::InputValueDefinition.new(
|
132
140
|
name: argument.graphql_name,
|
141
|
+
comment: argument.comment,
|
133
142
|
description: argument.description,
|
134
143
|
type: build_type_name_node(argument.type),
|
135
144
|
default_value: default_value,
|
@@ -142,6 +151,7 @@ module GraphQL
|
|
142
151
|
def build_input_object_node(input_object)
|
143
152
|
GraphQL::Language::Nodes::InputObjectTypeDefinition.new(
|
144
153
|
name: input_object.graphql_name,
|
154
|
+
comment: input_object.comment,
|
145
155
|
fields: build_argument_nodes(@types.arguments(input_object)),
|
146
156
|
description: input_object.description,
|
147
157
|
directives: directives(input_object),
|
@@ -259,7 +269,33 @@ module GraphQL
|
|
259
269
|
end
|
260
270
|
definitions = build_directive_nodes(dirs_to_build)
|
261
271
|
all_types = @types.all_types
|
262
|
-
type_nodes = build_type_definition_nodes(all_types
|
272
|
+
type_nodes = build_type_definition_nodes(all_types)
|
273
|
+
|
274
|
+
if (ex_t = schema.extra_types).any?
|
275
|
+
dummy_query = Class.new(GraphQL::Schema::Object) do
|
276
|
+
graphql_name "DummyQuery"
|
277
|
+
(all_types + ex_t).each_with_index do |type, idx|
|
278
|
+
if !type.kind.input_object? && !type.introspection?
|
279
|
+
field "f#{idx}", type
|
280
|
+
end
|
281
|
+
end
|
282
|
+
end
|
283
|
+
|
284
|
+
extra_types_schema = Class.new(GraphQL::Schema) do
|
285
|
+
query(dummy_query)
|
286
|
+
end
|
287
|
+
|
288
|
+
extra_types_types = GraphQL::Query.new(extra_types_schema, "{ __typename }", context: @context).types # rubocop:disable Development/ContextIsPassedCop
|
289
|
+
# Temporarily replace `@types` with something from this example schema.
|
290
|
+
# It'd be much nicer to pass this in, but that would be a big refactor :S
|
291
|
+
prev_types = @types
|
292
|
+
@types = extra_types_types
|
293
|
+
type_nodes += build_type_definition_nodes(ex_t)
|
294
|
+
@types = prev_types
|
295
|
+
end
|
296
|
+
|
297
|
+
type_nodes.sort_by!(&:name)
|
298
|
+
|
263
299
|
if @include_one_of
|
264
300
|
# This may have been set to true when iterating over all types
|
265
301
|
definitions.concat(build_directive_nodes([GraphQL::Schema::Directive::OneOf]))
|
@@ -282,9 +318,7 @@ module GraphQL
|
|
282
318
|
types = types.reject { |type| type.kind.scalar? && type.default_scalar? }
|
283
319
|
end
|
284
320
|
|
285
|
-
types
|
286
|
-
.map { |type| build_type_definition_node(type) }
|
287
|
-
.sort_by(&:name)
|
321
|
+
types.map { |type| build_type_definition_node(type) }
|
288
322
|
end
|
289
323
|
|
290
324
|
def build_field_nodes(fields)
|
@@ -19,7 +19,7 @@ module GraphQL
|
|
19
19
|
@scanner.eos?
|
20
20
|
end
|
21
21
|
|
22
|
-
attr_reader :pos
|
22
|
+
attr_reader :pos, :tokens_count
|
23
23
|
|
24
24
|
def advance
|
25
25
|
@scanner.skip(IGNORE_REGEXP)
|
@@ -57,20 +57,23 @@ module GraphQL
|
|
57
57
|
@scanner.skip(IDENTIFIER_REGEXP)
|
58
58
|
:IDENTIFIER
|
59
59
|
when ByteFor::NUMBER
|
60
|
-
@scanner.skip(NUMERIC_REGEXP)
|
60
|
+
if len = @scanner.skip(NUMERIC_REGEXP)
|
61
61
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
62
|
+
if GraphQL.reject_numbers_followed_by_names
|
63
|
+
new_pos = @scanner.pos
|
64
|
+
peek_byte = @string.getbyte(new_pos)
|
65
|
+
next_first_byte = FIRST_BYTES[peek_byte]
|
66
|
+
if next_first_byte == ByteFor::NAME || next_first_byte == ByteFor::IDENTIFIER
|
67
|
+
number_part = token_value
|
68
|
+
name_part = @scanner.scan(IDENTIFIER_REGEXP)
|
69
|
+
raise_parse_error("Name after number is not allowed (in `#{number_part}#{name_part}`)")
|
70
|
+
end
|
70
71
|
end
|
72
|
+
# Check for a matched decimal:
|
73
|
+
@scanner[1] ? :FLOAT : :INT
|
74
|
+
else
|
75
|
+
raise_parse_error("Expected a number, but it was malformed (#{@string[@pos].inspect})")
|
71
76
|
end
|
72
|
-
# Check for a matched decimal:
|
73
|
-
@scanner[1] ? :FLOAT : :INT
|
74
77
|
when ByteFor::ELLIPSIS
|
75
78
|
if @string.getbyte(@pos + 1) != 46 || @string.getbyte(@pos + 2) != 46
|
76
79
|
raise_parse_error("Expected `...`, actual: #{@string[@pos..@pos + 2].inspect}")
|
@@ -270,15 +270,17 @@ module GraphQL
|
|
270
270
|
"col: nil",
|
271
271
|
"pos: nil",
|
272
272
|
"filename: nil",
|
273
|
-
"source: nil"
|
273
|
+
"source: nil"
|
274
274
|
]
|
275
275
|
|
276
|
+
IGNORED_MARSHALLING_KEYWORDS = [:comment]
|
277
|
+
|
276
278
|
def generate_initialize
|
277
279
|
return if method_defined?(:marshal_load, false) # checking for `:initialize` doesn't work right
|
278
280
|
|
279
281
|
scalar_method_names = @scalar_methods
|
280
282
|
# TODO: These probably should be scalar methods, but `types` returns an array
|
281
|
-
[:types, :description].each do |extra_method|
|
283
|
+
[:types, :description, :comment].each do |extra_method|
|
282
284
|
if method_defined?(extra_method)
|
283
285
|
scalar_method_names += [extra_method]
|
284
286
|
end
|
@@ -307,6 +309,12 @@ module GraphQL
|
|
307
309
|
keywords = scalar_method_names.map { |m| "#{m}: #{m}"} +
|
308
310
|
children_method_names.map { |m| "#{m}: #{m}" }
|
309
311
|
|
312
|
+
ignored_keywords = IGNORED_MARSHALLING_KEYWORDS.map do |keyword|
|
313
|
+
"#{keyword.to_s}: nil"
|
314
|
+
end
|
315
|
+
|
316
|
+
marshalling_method_names = all_method_names - IGNORED_MARSHALLING_KEYWORDS
|
317
|
+
|
310
318
|
module_eval <<-RUBY, __FILE__, __LINE__
|
311
319
|
def initialize(#{arguments.join(", ")})
|
312
320
|
@line = line
|
@@ -317,7 +325,7 @@ module GraphQL
|
|
317
325
|
#{assignments.join("\n")}
|
318
326
|
end
|
319
327
|
|
320
|
-
def self.from_a(filename, line, col, #{
|
328
|
+
def self.from_a(filename, line, col, #{marshalling_method_names.join(", ")}, #{ignored_keywords.join(", ")})
|
321
329
|
self.new(filename: filename, line: line, col: col, #{keywords.join(", ")})
|
322
330
|
end
|
323
331
|
|
@@ -325,12 +333,12 @@ module GraphQL
|
|
325
333
|
[
|
326
334
|
line, col, # use methods here to force them to be calculated
|
327
335
|
@filename,
|
328
|
-
#{
|
336
|
+
#{marshalling_method_names.map { |n| "@#{n}," }.join}
|
329
337
|
]
|
330
338
|
end
|
331
339
|
|
332
340
|
def marshal_load(values)
|
333
|
-
@line, @col, @filename #{
|
341
|
+
@line, @col, @filename #{marshalling_method_names.map { |n| ", @#{n}"}.join} = values
|
334
342
|
end
|
335
343
|
RUBY
|
336
344
|
end
|
@@ -635,7 +643,7 @@ module GraphQL
|
|
635
643
|
end
|
636
644
|
|
637
645
|
class ScalarTypeDefinition < AbstractNode
|
638
|
-
attr_reader :description
|
646
|
+
attr_reader :description, :comment
|
639
647
|
scalar_methods :name
|
640
648
|
children_methods({
|
641
649
|
directives: GraphQL::Language::Nodes::Directive,
|
@@ -652,7 +660,7 @@ module GraphQL
|
|
652
660
|
end
|
653
661
|
|
654
662
|
class InputValueDefinition < AbstractNode
|
655
|
-
attr_reader :description
|
663
|
+
attr_reader :description, :comment
|
656
664
|
scalar_methods :name, :type, :default_value
|
657
665
|
children_methods({
|
658
666
|
directives: GraphQL::Language::Nodes::Directive,
|
@@ -661,7 +669,7 @@ module GraphQL
|
|
661
669
|
end
|
662
670
|
|
663
671
|
class FieldDefinition < AbstractNode
|
664
|
-
attr_reader :description
|
672
|
+
attr_reader :description, :comment
|
665
673
|
scalar_methods :name, :type
|
666
674
|
children_methods({
|
667
675
|
arguments: GraphQL::Language::Nodes::InputValueDefinition,
|
@@ -681,7 +689,7 @@ module GraphQL
|
|
681
689
|
end
|
682
690
|
|
683
691
|
class ObjectTypeDefinition < AbstractNode
|
684
|
-
attr_reader :description
|
692
|
+
attr_reader :description, :comment
|
685
693
|
scalar_methods :name, :interfaces
|
686
694
|
children_methods({
|
687
695
|
directives: GraphQL::Language::Nodes::Directive,
|
@@ -700,7 +708,7 @@ module GraphQL
|
|
700
708
|
end
|
701
709
|
|
702
710
|
class InterfaceTypeDefinition < AbstractNode
|
703
|
-
attr_reader :description
|
711
|
+
attr_reader :description, :comment
|
704
712
|
scalar_methods :name
|
705
713
|
children_methods({
|
706
714
|
interfaces: GraphQL::Language::Nodes::TypeName,
|
@@ -721,7 +729,7 @@ module GraphQL
|
|
721
729
|
end
|
722
730
|
|
723
731
|
class UnionTypeDefinition < AbstractNode
|
724
|
-
attr_reader :description, :types
|
732
|
+
attr_reader :description, :comment, :types
|
725
733
|
scalar_methods :name
|
726
734
|
children_methods({
|
727
735
|
directives: GraphQL::Language::Nodes::Directive,
|
@@ -739,7 +747,7 @@ module GraphQL
|
|
739
747
|
end
|
740
748
|
|
741
749
|
class EnumValueDefinition < AbstractNode
|
742
|
-
attr_reader :description
|
750
|
+
attr_reader :description, :comment
|
743
751
|
scalar_methods :name
|
744
752
|
children_methods({
|
745
753
|
directives: GraphQL::Language::Nodes::Directive,
|
@@ -748,7 +756,7 @@ module GraphQL
|
|
748
756
|
end
|
749
757
|
|
750
758
|
class EnumTypeDefinition < AbstractNode
|
751
|
-
attr_reader :description
|
759
|
+
attr_reader :description, :comment
|
752
760
|
scalar_methods :name
|
753
761
|
children_methods({
|
754
762
|
directives: GraphQL::Language::Nodes::Directive,
|
@@ -767,7 +775,7 @@ module GraphQL
|
|
767
775
|
end
|
768
776
|
|
769
777
|
class InputObjectTypeDefinition < AbstractNode
|
770
|
-
attr_reader :description
|
778
|
+
attr_reader :description, :comment
|
771
779
|
scalar_methods :name
|
772
780
|
children_methods({
|
773
781
|
directives: GraphQL::Language::Nodes::Directive,
|
@@ -255,14 +255,14 @@ module GraphQL
|
|
255
255
|
|
256
256
|
|
257
257
|
def print_scalar_type_definition(scalar_type, extension: false)
|
258
|
-
extension ? print_string("extend ") :
|
258
|
+
extension ? print_string("extend ") : print_description_and_comment(scalar_type)
|
259
259
|
print_string("scalar ")
|
260
260
|
print_string(scalar_type.name)
|
261
261
|
print_directives(scalar_type.directives)
|
262
262
|
end
|
263
263
|
|
264
264
|
def print_object_type_definition(object_type, extension: false)
|
265
|
-
extension ? print_string("extend ") :
|
265
|
+
extension ? print_string("extend ") : print_description_and_comment(object_type)
|
266
266
|
print_string("type ")
|
267
267
|
print_string(object_type.name)
|
268
268
|
print_implements(object_type) unless object_type.interfaces.empty?
|
@@ -294,7 +294,7 @@ module GraphQL
|
|
294
294
|
end
|
295
295
|
|
296
296
|
def print_arguments(arguments, indent: "")
|
297
|
-
if arguments.all? { |arg| !arg.description }
|
297
|
+
if arguments.all? { |arg| !arg.description && !arg.comment }
|
298
298
|
print_string("(")
|
299
299
|
arguments.each_with_index do |arg, i|
|
300
300
|
print_input_value_definition(arg)
|
@@ -306,6 +306,7 @@ module GraphQL
|
|
306
306
|
|
307
307
|
print_string("(\n")
|
308
308
|
arguments.each_with_index do |arg, i|
|
309
|
+
print_comment(arg, indent: " " + indent, first_in_block: i == 0)
|
309
310
|
print_description(arg, indent: " " + indent, first_in_block: i == 0)
|
310
311
|
print_string(" ")
|
311
312
|
print_string(indent)
|
@@ -328,7 +329,7 @@ module GraphQL
|
|
328
329
|
end
|
329
330
|
|
330
331
|
def print_interface_type_definition(interface_type, extension: false)
|
331
|
-
extension ? print_string("extend ") :
|
332
|
+
extension ? print_string("extend ") : print_description_and_comment(interface_type)
|
332
333
|
print_string("interface ")
|
333
334
|
print_string(interface_type.name)
|
334
335
|
print_implements(interface_type) if interface_type.interfaces.any?
|
@@ -337,7 +338,7 @@ module GraphQL
|
|
337
338
|
end
|
338
339
|
|
339
340
|
def print_union_type_definition(union_type, extension: false)
|
340
|
-
extension ? print_string("extend ") :
|
341
|
+
extension ? print_string("extend ") : print_description_and_comment(union_type)
|
341
342
|
print_string("union ")
|
342
343
|
print_string(union_type.name)
|
343
344
|
print_directives(union_type.directives)
|
@@ -355,7 +356,7 @@ module GraphQL
|
|
355
356
|
end
|
356
357
|
|
357
358
|
def print_enum_type_definition(enum_type, extension: false)
|
358
|
-
extension ? print_string("extend ") :
|
359
|
+
extension ? print_string("extend ") : print_description_and_comment(enum_type)
|
359
360
|
print_string("enum ")
|
360
361
|
print_string(enum_type.name)
|
361
362
|
print_directives(enum_type.directives)
|
@@ -363,6 +364,7 @@ module GraphQL
|
|
363
364
|
print_string(" {\n")
|
364
365
|
enum_type.values.each.with_index do |value, i|
|
365
366
|
print_description(value, indent: " ", first_in_block: i == 0)
|
367
|
+
print_comment(value, indent: " ", first_in_block: i == 0)
|
366
368
|
print_enum_value_definition(value)
|
367
369
|
end
|
368
370
|
print_string("}")
|
@@ -377,7 +379,7 @@ module GraphQL
|
|
377
379
|
end
|
378
380
|
|
379
381
|
def print_input_object_type_definition(input_object_type, extension: false)
|
380
|
-
extension ? print_string("extend ") :
|
382
|
+
extension ? print_string("extend ") : print_description_and_comment(input_object_type)
|
381
383
|
print_string("input ")
|
382
384
|
print_string(input_object_type.name)
|
383
385
|
print_directives(input_object_type.directives)
|
@@ -385,6 +387,7 @@ module GraphQL
|
|
385
387
|
print_string(" {\n")
|
386
388
|
input_object_type.fields.each.with_index do |field, i|
|
387
389
|
print_description(field, indent: " ", first_in_block: i == 0)
|
390
|
+
print_comment(field, indent: " ", first_in_block: i == 0)
|
388
391
|
print_string(" ")
|
389
392
|
print_input_value_definition(field)
|
390
393
|
print_string("\n")
|
@@ -424,6 +427,18 @@ module GraphQL
|
|
424
427
|
print_string(GraphQL::Language::BlockString.print(node.description, indent: indent))
|
425
428
|
end
|
426
429
|
|
430
|
+
def print_comment(node, indent: "", first_in_block: true)
|
431
|
+
return unless node.comment
|
432
|
+
|
433
|
+
print_string("\n") if indent != "" && !first_in_block
|
434
|
+
print_string(GraphQL::Language::Comment.print(node.comment, indent: indent))
|
435
|
+
end
|
436
|
+
|
437
|
+
def print_description_and_comment(node)
|
438
|
+
print_description(node)
|
439
|
+
print_comment(node)
|
440
|
+
end
|
441
|
+
|
427
442
|
def print_field_definitions(fields)
|
428
443
|
return if fields.empty?
|
429
444
|
|
@@ -431,6 +446,7 @@ module GraphQL
|
|
431
446
|
i = 0
|
432
447
|
fields.each do |field|
|
433
448
|
print_description(field, indent: " ", first_in_block: i == 0)
|
449
|
+
print_comment(field, indent: " ", first_in_block: i == 0)
|
434
450
|
print_string(" ")
|
435
451
|
print_field_definition(field)
|
436
452
|
print_string("\n")
|
data/lib/graphql/language.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
require "graphql/language/block_string"
|
3
|
+
require "graphql/language/comment"
|
3
4
|
require "graphql/language/printer"
|
4
5
|
require "graphql/language/sanitized_printer"
|
5
6
|
require "graphql/language/document_from_schema_definition"
|
@@ -48,19 +49,19 @@ module GraphQL
|
|
48
49
|
inside_single_quoted_string = false
|
49
50
|
new_query_str = nil
|
50
51
|
while !scanner.eos?
|
51
|
-
if
|
52
|
-
new_query_str <<
|
53
|
-
elsif scanner.
|
52
|
+
if scanner.skip(/(?:\\"|[^"\n\r]|""")+/m)
|
53
|
+
new_query_str && (new_query_str << scanner.matched)
|
54
|
+
elsif scanner.skip('"')
|
54
55
|
new_query_str && (new_query_str << '"')
|
55
56
|
inside_single_quoted_string = !inside_single_quoted_string
|
56
|
-
elsif scanner.
|
57
|
+
elsif scanner.skip("\n")
|
57
58
|
if inside_single_quoted_string
|
58
59
|
new_query_str ||= query_str[0, scanner.pos - 1]
|
59
60
|
new_query_str << '\\n'
|
60
61
|
else
|
61
62
|
new_query_str && (new_query_str << "\n")
|
62
63
|
end
|
63
|
-
elsif scanner.
|
64
|
+
elsif scanner.skip("\r")
|
64
65
|
if inside_single_quoted_string
|
65
66
|
new_query_str ||= query_str[0, scanner.pos - 1]
|
66
67
|
new_query_str << '\\r'
|
data/lib/graphql/query.rb
CHANGED
@@ -102,7 +102,7 @@ module GraphQL
|
|
102
102
|
@context = schema.context_class.new(query: self, values: context)
|
103
103
|
|
104
104
|
if use_schema_subset.nil?
|
105
|
-
use_schema_subset = warden ? false : schema.
|
105
|
+
use_schema_subset = warden ? false : schema.use_schema_visibility?
|
106
106
|
end
|
107
107
|
|
108
108
|
if use_schema_subset
|
@@ -110,7 +110,15 @@ module GraphQL
|
|
110
110
|
end
|
111
111
|
|
112
112
|
def determine_field_indent(send_node)
|
113
|
-
surrounding_node = send_node.parent
|
113
|
+
surrounding_node = send_node.parent
|
114
|
+
if !surrounding_node.is_a?(RuboCop::AST::ClassNode)
|
115
|
+
surrounding_node = surrounding_node.parent
|
116
|
+
end
|
117
|
+
|
118
|
+
if !surrounding_node.is_a?(RuboCop::AST::ClassNode)
|
119
|
+
raise "Invariant: Something went wrong in GraphQL-Ruby, couldn't find surrounding class definition for field (#{send_node}).\n\nPlease report this error on GitHub."
|
120
|
+
end
|
121
|
+
|
114
122
|
surrounding_source = surrounding_node.source
|
115
123
|
indent_test_idx = send_node.location.expression.begin_pos - surrounding_node.source_range.begin_pos - 1
|
116
124
|
field_indent = "".dup
|
@@ -50,11 +50,12 @@ module GraphQL
|
|
50
50
|
# @param deprecation_reason [String]
|
51
51
|
# @param validates [Hash, nil] Options for building validators, if any should be applied
|
52
52
|
# @param replace_null_with_default [Boolean] if `true`, incoming values of `null` will be replaced with the configured `default_value`
|
53
|
-
def initialize(arg_name = nil, type_expr = nil, desc = nil, required: true, type: nil, name: nil, loads: nil, description: nil, ast_node: nil, default_value: NOT_CONFIGURED, as: nil, from_resolver: false, camelize: true, prepare: nil, owner:, validates: nil, directives: nil, deprecation_reason: nil, replace_null_with_default: false, &definition_block)
|
53
|
+
def initialize(arg_name = nil, type_expr = nil, desc = nil, required: true, type: nil, name: nil, loads: nil, description: nil, comment: nil, ast_node: nil, default_value: NOT_CONFIGURED, as: nil, from_resolver: false, camelize: true, prepare: nil, owner:, validates: nil, directives: nil, deprecation_reason: nil, replace_null_with_default: false, &definition_block)
|
54
54
|
arg_name ||= name
|
55
55
|
@name = -(camelize ? Member::BuildType.camelize(arg_name.to_s) : arg_name.to_s)
|
56
56
|
@type_expr = type_expr || type
|
57
57
|
@description = desc || description
|
58
|
+
@comment = comment
|
58
59
|
@null = required != true
|
59
60
|
@default_value = default_value
|
60
61
|
if replace_null_with_default
|
@@ -129,6 +130,17 @@ module GraphQL
|
|
129
130
|
end
|
130
131
|
end
|
131
132
|
|
133
|
+
attr_writer :comment
|
134
|
+
|
135
|
+
# @return [String] Comment for this argument
|
136
|
+
def comment(text = nil)
|
137
|
+
if text
|
138
|
+
@comment = text
|
139
|
+
else
|
140
|
+
@comment
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
132
144
|
# @return [String] Deprecation reason for this argument
|
133
145
|
def deprecation_reason(text = nil)
|
134
146
|
if text
|
data/lib/graphql/schema/enum.rb
CHANGED
@@ -59,6 +59,7 @@ module GraphQL
|
|
59
59
|
# Define a value for this enum
|
60
60
|
# @option kwargs [String, Symbol] :graphql_name the GraphQL value for this, usually `SCREAMING_CASE`
|
61
61
|
# @option kwargs [String] :description, the GraphQL description for this value, present in documentation
|
62
|
+
# @option kwargs [String] :comment, the GraphQL comment for this value, present in documentation
|
62
63
|
# @option kwargs [::Object] :value the translated Ruby value for this object (defaults to `graphql_name`)
|
63
64
|
# @option kwargs [String] :deprecation_reason if this object is deprecated, include a message here
|
64
65
|
# @return [void]
|
@@ -30,10 +30,11 @@ module GraphQL
|
|
30
30
|
# @return [Class] The enum type that owns this value
|
31
31
|
attr_reader :owner
|
32
32
|
|
33
|
-
def initialize(graphql_name, desc = nil, owner:, ast_node: nil, directives: nil, description: nil, value: NOT_CONFIGURED, deprecation_reason: nil, &block)
|
33
|
+
def initialize(graphql_name, desc = nil, owner:, ast_node: nil, directives: nil, description: nil, comment: nil, value: NOT_CONFIGURED, deprecation_reason: nil, &block)
|
34
34
|
@graphql_name = graphql_name.to_s
|
35
35
|
GraphQL::NameValidator.validate!(@graphql_name)
|
36
36
|
@description = desc || description
|
37
|
+
@comment = comment
|
37
38
|
@value = value == NOT_CONFIGURED ? @graphql_name : value
|
38
39
|
if deprecation_reason
|
39
40
|
self.deprecation_reason = deprecation_reason
|
@@ -58,6 +59,13 @@ module GraphQL
|
|
58
59
|
@description
|
59
60
|
end
|
60
61
|
|
62
|
+
def comment(new_comment = nil)
|
63
|
+
if new_comment
|
64
|
+
@comment = new_comment
|
65
|
+
end
|
66
|
+
@comment
|
67
|
+
end
|
68
|
+
|
61
69
|
def value(new_val = nil)
|
62
70
|
unless new_val.nil?
|
63
71
|
@value = new_val
|