graphql 1.9.17 → 1.11.7
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/core.rb +18 -2
- data/lib/generators/graphql/install_generator.rb +27 -0
- data/lib/generators/graphql/object_generator.rb +52 -8
- data/lib/generators/graphql/templates/base_argument.erb +2 -0
- data/lib/generators/graphql/templates/base_enum.erb +2 -0
- data/lib/generators/graphql/templates/base_field.erb +2 -0
- data/lib/generators/graphql/templates/base_input_object.erb +2 -0
- data/lib/generators/graphql/templates/base_interface.erb +2 -0
- data/lib/generators/graphql/templates/base_mutation.erb +2 -0
- data/lib/generators/graphql/templates/base_object.erb +2 -0
- data/lib/generators/graphql/templates/base_scalar.erb +2 -0
- data/lib/generators/graphql/templates/base_union.erb +2 -0
- data/lib/generators/graphql/templates/enum.erb +2 -0
- data/lib/generators/graphql/templates/graphql_controller.erb +14 -10
- data/lib/generators/graphql/templates/interface.erb +2 -0
- data/lib/generators/graphql/templates/loader.erb +2 -0
- data/lib/generators/graphql/templates/mutation.erb +2 -0
- data/lib/generators/graphql/templates/mutation_type.erb +2 -0
- data/lib/generators/graphql/templates/object.erb +2 -0
- data/lib/generators/graphql/templates/query_type.erb +2 -0
- data/lib/generators/graphql/templates/scalar.erb +2 -0
- data/lib/generators/graphql/templates/schema.erb +10 -0
- data/lib/generators/graphql/templates/union.erb +3 -1
- data/lib/graphql/analysis/ast/field_usage.rb +1 -1
- data/lib/graphql/analysis/ast/query_complexity.rb +178 -67
- data/lib/graphql/analysis/ast/visitor.rb +3 -3
- data/lib/graphql/analysis/ast.rb +12 -11
- data/lib/graphql/argument.rb +10 -38
- data/lib/graphql/backtrace/table.rb +10 -2
- data/lib/graphql/backtrace/tracer.rb +2 -1
- data/lib/graphql/base_type.rb +4 -0
- data/lib/graphql/compatibility/execution_specification/specification_schema.rb +2 -2
- data/lib/graphql/compatibility/query_parser_specification/parse_error_specification.rb +5 -9
- data/lib/graphql/define/assign_enum_value.rb +1 -1
- data/lib/graphql/define/assign_global_id_field.rb +2 -2
- data/lib/graphql/define/assign_object_field.rb +3 -3
- data/lib/graphql/define/defined_object_proxy.rb +3 -0
- data/lib/graphql/define/instance_definable.rb +18 -108
- data/lib/graphql/directive/deprecated_directive.rb +1 -12
- data/lib/graphql/directive.rb +8 -1
- data/lib/graphql/enum_type.rb +5 -71
- data/lib/graphql/execution/directive_checks.rb +2 -2
- data/lib/graphql/execution/errors.rb +2 -3
- data/lib/graphql/execution/execute.rb +1 -1
- data/lib/graphql/execution/instrumentation.rb +1 -1
- data/lib/graphql/execution/interpreter/argument_value.rb +28 -0
- data/lib/graphql/execution/interpreter/arguments.rb +51 -0
- data/lib/graphql/execution/interpreter/arguments_cache.rb +79 -0
- data/lib/graphql/execution/interpreter/handles_raw_value.rb +25 -0
- data/lib/graphql/execution/interpreter/runtime.rb +227 -254
- data/lib/graphql/execution/interpreter.rb +34 -11
- data/lib/graphql/execution/lazy/lazy_method_map.rb +4 -0
- data/lib/graphql/execution/lookahead.rb +39 -114
- data/lib/graphql/execution/multiplex.rb +14 -5
- data/lib/graphql/field.rb +14 -118
- data/lib/graphql/filter.rb +1 -1
- data/lib/graphql/function.rb +1 -30
- data/lib/graphql/input_object_type.rb +6 -24
- data/lib/graphql/integer_decoding_error.rb +17 -0
- data/lib/graphql/interface_type.rb +7 -23
- data/lib/graphql/internal_representation/scope.rb +2 -2
- data/lib/graphql/internal_representation/visit.rb +2 -2
- data/lib/graphql/introspection/base_object.rb +2 -5
- data/lib/graphql/introspection/directive_type.rb +1 -1
- data/lib/graphql/introspection/entry_points.rb +7 -7
- data/lib/graphql/introspection/field_type.rb +7 -3
- data/lib/graphql/introspection/input_value_type.rb +33 -9
- data/lib/graphql/introspection/introspection_query.rb +6 -92
- data/lib/graphql/introspection/schema_type.rb +4 -9
- data/lib/graphql/introspection/type_type.rb +11 -7
- data/lib/graphql/introspection.rb +96 -0
- data/lib/graphql/invalid_null_error.rb +18 -0
- data/lib/graphql/language/block_string.rb +24 -5
- data/lib/graphql/language/definition_slice.rb +21 -10
- data/lib/graphql/language/document_from_schema_definition.rb +89 -64
- data/lib/graphql/language/lexer.rb +7 -3
- data/lib/graphql/language/lexer.rl +7 -3
- data/lib/graphql/language/nodes.rb +52 -91
- data/lib/graphql/language/parser.rb +719 -717
- data/lib/graphql/language/parser.y +104 -98
- data/lib/graphql/language/printer.rb +1 -1
- data/lib/graphql/language/sanitized_printer.rb +222 -0
- data/lib/graphql/language/visitor.rb +2 -2
- data/lib/graphql/language.rb +2 -1
- data/lib/graphql/name_validator.rb +6 -7
- data/lib/graphql/non_null_type.rb +0 -10
- data/lib/graphql/object_type.rb +45 -56
- data/lib/graphql/pagination/active_record_relation_connection.rb +41 -0
- data/lib/graphql/pagination/array_connection.rb +77 -0
- data/lib/graphql/pagination/connection.rb +208 -0
- data/lib/graphql/pagination/connections.rb +145 -0
- data/lib/graphql/pagination/mongoid_relation_connection.rb +25 -0
- data/lib/graphql/pagination/relation_connection.rb +185 -0
- data/lib/graphql/pagination/sequel_dataset_connection.rb +28 -0
- data/lib/graphql/pagination.rb +6 -0
- data/lib/graphql/query/arguments.rb +4 -2
- data/lib/graphql/query/context.rb +36 -9
- data/lib/graphql/query/fingerprint.rb +26 -0
- data/lib/graphql/query/input_validation_result.rb +23 -6
- data/lib/graphql/query/literal_input.rb +30 -10
- data/lib/graphql/query/null_context.rb +5 -1
- data/lib/graphql/query/validation_pipeline.rb +4 -1
- data/lib/graphql/query/variable_validation_error.rb +1 -1
- data/lib/graphql/query/variables.rb +16 -7
- data/lib/graphql/query.rb +64 -15
- data/lib/graphql/rake_task/validate.rb +3 -0
- data/lib/graphql/rake_task.rb +9 -9
- data/lib/graphql/relay/array_connection.rb +10 -12
- data/lib/graphql/relay/base_connection.rb +23 -13
- data/lib/graphql/relay/connection_type.rb +2 -1
- data/lib/graphql/relay/edge_type.rb +1 -0
- data/lib/graphql/relay/edges_instrumentation.rb +1 -1
- data/lib/graphql/relay/mutation.rb +1 -86
- data/lib/graphql/relay/node.rb +2 -2
- data/lib/graphql/relay/range_add.rb +14 -5
- data/lib/graphql/relay/relation_connection.rb +8 -10
- data/lib/graphql/scalar_type.rb +15 -59
- data/lib/graphql/schema/argument.rb +113 -11
- data/lib/graphql/schema/base_64_encoder.rb +2 -0
- data/lib/graphql/schema/build_from_definition/resolve_map/default_resolve.rb +1 -1
- data/lib/graphql/schema/build_from_definition/resolve_map.rb +13 -5
- data/lib/graphql/schema/build_from_definition.rb +212 -190
- data/lib/graphql/schema/built_in_types.rb +5 -5
- data/lib/graphql/schema/default_type_error.rb +2 -0
- data/lib/graphql/schema/directive/deprecated.rb +18 -0
- data/lib/graphql/schema/directive/include.rb +1 -1
- data/lib/graphql/schema/directive/skip.rb +1 -1
- data/lib/graphql/schema/directive.rb +34 -3
- data/lib/graphql/schema/enum.rb +52 -4
- data/lib/graphql/schema/enum_value.rb +6 -1
- data/lib/graphql/schema/field/connection_extension.rb +44 -20
- data/lib/graphql/schema/field/scope_extension.rb +1 -1
- data/lib/graphql/schema/field.rb +200 -129
- data/lib/graphql/schema/find_inherited_value.rb +13 -0
- data/lib/graphql/schema/finder.rb +13 -11
- data/lib/graphql/schema/input_object.rb +131 -22
- data/lib/graphql/schema/interface.rb +26 -8
- data/lib/graphql/schema/introspection_system.rb +108 -37
- data/lib/graphql/schema/late_bound_type.rb +3 -2
- data/lib/graphql/schema/list.rb +47 -0
- data/lib/graphql/schema/loader.rb +134 -96
- data/lib/graphql/schema/member/base_dsl_methods.rb +29 -12
- data/lib/graphql/schema/member/build_type.rb +19 -5
- data/lib/graphql/schema/member/cached_graphql_definition.rb +5 -0
- data/lib/graphql/schema/member/has_arguments.rb +105 -5
- data/lib/graphql/schema/member/has_ast_node.rb +20 -0
- data/lib/graphql/schema/member/has_fields.rb +20 -10
- data/lib/graphql/schema/member/has_unresolved_type_error.rb +15 -0
- data/lib/graphql/schema/member/type_system_helpers.rb +2 -2
- data/lib/graphql/schema/member/validates_input.rb +33 -0
- data/lib/graphql/schema/member.rb +6 -0
- data/lib/graphql/schema/mutation.rb +5 -1
- data/lib/graphql/schema/non_null.rb +30 -0
- data/lib/graphql/schema/object.rb +65 -12
- data/lib/graphql/schema/possible_types.rb +9 -4
- data/lib/graphql/schema/printer.rb +0 -15
- data/lib/graphql/schema/relay_classic_mutation.rb +5 -3
- data/lib/graphql/schema/resolver/has_payload_type.rb +5 -2
- data/lib/graphql/schema/resolver.rb +26 -18
- data/lib/graphql/schema/scalar.rb +27 -3
- data/lib/graphql/schema/subscription.rb +8 -18
- data/lib/graphql/schema/timeout.rb +29 -15
- data/lib/graphql/schema/traversal.rb +1 -1
- data/lib/graphql/schema/type_expression.rb +21 -13
- data/lib/graphql/schema/type_membership.rb +2 -2
- data/lib/graphql/schema/union.rb +37 -3
- data/lib/graphql/schema/unique_within_type.rb +1 -2
- data/lib/graphql/schema/validation.rb +10 -2
- data/lib/graphql/schema/warden.rb +115 -29
- data/lib/graphql/schema.rb +903 -195
- data/lib/graphql/static_validation/all_rules.rb +1 -0
- data/lib/graphql/static_validation/base_visitor.rb +10 -6
- data/lib/graphql/static_validation/literal_validator.rb +52 -27
- data/lib/graphql/static_validation/rules/argument_literals_are_compatible.rb +43 -83
- data/lib/graphql/static_validation/rules/argument_literals_are_compatible_error.rb +17 -5
- data/lib/graphql/static_validation/rules/arguments_are_defined.rb +33 -25
- data/lib/graphql/static_validation/rules/directives_are_in_valid_locations.rb +1 -1
- data/lib/graphql/static_validation/rules/fields_are_defined_on_type.rb +4 -4
- data/lib/graphql/static_validation/rules/fields_have_appropriate_selections.rb +5 -5
- data/lib/graphql/static_validation/rules/fields_will_merge.rb +29 -21
- data/lib/graphql/static_validation/rules/fragment_spreads_are_possible.rb +3 -3
- data/lib/graphql/static_validation/rules/input_object_names_are_unique.rb +30 -0
- data/lib/graphql/static_validation/rules/input_object_names_are_unique_error.rb +30 -0
- data/lib/graphql/static_validation/rules/required_arguments_are_present.rb +2 -2
- data/lib/graphql/static_validation/rules/required_input_object_attributes_are_present.rb +4 -5
- data/lib/graphql/static_validation/rules/variable_default_values_are_correctly_typed.rb +12 -13
- data/lib/graphql/static_validation/rules/variable_usages_are_allowed.rb +5 -6
- data/lib/graphql/static_validation/rules/variables_are_input_types.rb +1 -1
- data/lib/graphql/static_validation/rules/variables_are_used_and_defined.rb +5 -3
- data/lib/graphql/static_validation/type_stack.rb +2 -2
- data/lib/graphql/static_validation/validation_context.rb +1 -1
- data/lib/graphql/static_validation/validation_timeout_error.rb +25 -0
- data/lib/graphql/static_validation/validator.rb +30 -8
- data/lib/graphql/static_validation.rb +1 -0
- data/lib/graphql/subscriptions/action_cable_subscriptions.rb +89 -19
- data/lib/graphql/subscriptions/broadcast_analyzer.rb +84 -0
- data/lib/graphql/subscriptions/default_subscription_resolve_extension.rb +21 -0
- data/lib/graphql/subscriptions/event.rb +23 -5
- data/lib/graphql/subscriptions/instrumentation.rb +10 -5
- data/lib/graphql/subscriptions/serialize.rb +22 -4
- data/lib/graphql/subscriptions/subscription_root.rb +15 -5
- data/lib/graphql/subscriptions.rb +108 -35
- data/lib/graphql/tracing/active_support_notifications_tracing.rb +14 -10
- data/lib/graphql/tracing/appoptics_tracing.rb +171 -0
- data/lib/graphql/tracing/appsignal_tracing.rb +8 -0
- data/lib/graphql/tracing/data_dog_tracing.rb +8 -0
- data/lib/graphql/tracing/new_relic_tracing.rb +9 -12
- data/lib/graphql/tracing/platform_tracing.rb +53 -9
- data/lib/graphql/tracing/prometheus_tracing/graphql_collector.rb +4 -1
- data/lib/graphql/tracing/prometheus_tracing.rb +8 -0
- data/lib/graphql/tracing/scout_tracing.rb +19 -0
- data/lib/graphql/tracing/skylight_tracing.rb +8 -0
- data/lib/graphql/tracing/statsd_tracing.rb +42 -0
- data/lib/graphql/tracing.rb +14 -34
- data/lib/graphql/types/big_int.rb +1 -1
- data/lib/graphql/types/int.rb +9 -2
- data/lib/graphql/types/iso_8601_date.rb +3 -3
- data/lib/graphql/types/iso_8601_date_time.rb +25 -10
- data/lib/graphql/types/relay/base_connection.rb +11 -7
- data/lib/graphql/types/relay/base_edge.rb +2 -1
- data/lib/graphql/types/string.rb +7 -1
- data/lib/graphql/unauthorized_error.rb +1 -1
- data/lib/graphql/union_type.rb +13 -28
- data/lib/graphql/unresolved_type_error.rb +2 -2
- data/lib/graphql/version.rb +1 -1
- data/lib/graphql.rb +31 -6
- data/readme.md +1 -1
- metadata +34 -9
- data/lib/graphql/literal_validation_error.rb +0 -6
@@ -23,10 +23,16 @@ module GraphQL
|
|
23
23
|
@include_built_in_scalars = include_built_in_scalars
|
24
24
|
@include_built_in_directives = include_built_in_directives
|
25
25
|
|
26
|
+
filter = GraphQL::Filter.new(only: only, except: except)
|
27
|
+
if @schema.respond_to?(:visible?)
|
28
|
+
filter = filter.merge(only: @schema.method(:visible?))
|
29
|
+
end
|
30
|
+
|
31
|
+
schema_context = schema.context_class.new(query: nil, object: nil, schema: schema, values: context)
|
26
32
|
@warden = GraphQL::Schema::Warden.new(
|
27
|
-
|
33
|
+
filter,
|
28
34
|
schema: @schema,
|
29
|
-
context:
|
35
|
+
context: schema_context,
|
30
36
|
)
|
31
37
|
end
|
32
38
|
|
@@ -38,88 +44,77 @@ module GraphQL
|
|
38
44
|
|
39
45
|
def build_schema_node
|
40
46
|
GraphQL::Language::Nodes::SchemaDefinition.new(
|
41
|
-
query: warden.root_type_for_operation("query"),
|
42
|
-
mutation: warden.root_type_for_operation("mutation"),
|
43
|
-
subscription: warden.root_type_for_operation("subscription"),
|
47
|
+
query: (q = warden.root_type_for_operation("query")) && q.graphql_name,
|
48
|
+
mutation: (m = warden.root_type_for_operation("mutation")) && m.graphql_name,
|
49
|
+
subscription: (s = warden.root_type_for_operation("subscription")) && s.graphql_name,
|
44
50
|
# This only supports directives from parsing,
|
45
51
|
# use a custom printer to add to this list.
|
46
|
-
directives: @schema
|
52
|
+
directives: ast_directives(@schema),
|
47
53
|
)
|
48
54
|
end
|
49
55
|
|
50
56
|
def build_object_type_node(object_type)
|
51
57
|
GraphQL::Language::Nodes::ObjectTypeDefinition.new(
|
52
|
-
name: object_type.
|
53
|
-
interfaces: warden.interfaces(object_type).sort_by(&:
|
58
|
+
name: object_type.graphql_name,
|
59
|
+
interfaces: warden.interfaces(object_type).sort_by(&:graphql_name).map { |iface| build_type_name_node(iface) },
|
54
60
|
fields: build_field_nodes(warden.fields(object_type)),
|
55
61
|
description: object_type.description,
|
62
|
+
directives: ast_directives(object_type),
|
56
63
|
)
|
57
64
|
end
|
58
65
|
|
59
66
|
def build_field_node(field)
|
60
|
-
|
61
|
-
name: field.
|
67
|
+
GraphQL::Language::Nodes::FieldDefinition.new(
|
68
|
+
name: field.graphql_name,
|
62
69
|
arguments: build_argument_nodes(warden.arguments(field)),
|
63
70
|
type: build_type_name_node(field.type),
|
64
71
|
description: field.description,
|
72
|
+
directives: ast_directives(field),
|
65
73
|
)
|
66
|
-
|
67
|
-
if field.deprecation_reason
|
68
|
-
field_node = field_node.merge_directive(
|
69
|
-
name: GraphQL::Directive::DeprecatedDirective.name,
|
70
|
-
arguments: [GraphQL::Language::Nodes::Argument.new(name: "reason", value: field.deprecation_reason)]
|
71
|
-
)
|
72
|
-
end
|
73
|
-
|
74
|
-
field_node
|
75
74
|
end
|
76
75
|
|
77
76
|
def build_union_type_node(union_type)
|
78
77
|
GraphQL::Language::Nodes::UnionTypeDefinition.new(
|
79
|
-
name: union_type.
|
78
|
+
name: union_type.graphql_name,
|
80
79
|
description: union_type.description,
|
81
|
-
types: warden.possible_types(union_type).sort_by(&:
|
80
|
+
types: warden.possible_types(union_type).sort_by(&:graphql_name).map { |type| build_type_name_node(type) },
|
81
|
+
directives: ast_directives(union_type),
|
82
82
|
)
|
83
83
|
end
|
84
84
|
|
85
85
|
def build_interface_type_node(interface_type)
|
86
86
|
GraphQL::Language::Nodes::InterfaceTypeDefinition.new(
|
87
|
-
name: interface_type.
|
87
|
+
name: interface_type.graphql_name,
|
88
88
|
description: interface_type.description,
|
89
|
-
fields: build_field_nodes(warden.fields(interface_type))
|
89
|
+
fields: build_field_nodes(warden.fields(interface_type)),
|
90
|
+
directives: ast_directives(interface_type),
|
90
91
|
)
|
91
92
|
end
|
92
93
|
|
93
94
|
def build_enum_type_node(enum_type)
|
94
95
|
GraphQL::Language::Nodes::EnumTypeDefinition.new(
|
95
|
-
name: enum_type.
|
96
|
-
values: warden.enum_values(enum_type).sort_by(&:
|
96
|
+
name: enum_type.graphql_name,
|
97
|
+
values: warden.enum_values(enum_type).sort_by(&:graphql_name).map do |enum_value|
|
97
98
|
build_enum_value_node(enum_value)
|
98
99
|
end,
|
99
100
|
description: enum_type.description,
|
101
|
+
directives: ast_directives(enum_type),
|
100
102
|
)
|
101
103
|
end
|
102
104
|
|
103
105
|
def build_enum_value_node(enum_value)
|
104
|
-
|
105
|
-
name: enum_value.
|
106
|
+
GraphQL::Language::Nodes::EnumValueDefinition.new(
|
107
|
+
name: enum_value.graphql_name,
|
106
108
|
description: enum_value.description,
|
109
|
+
directives: ast_directives(enum_value),
|
107
110
|
)
|
108
|
-
|
109
|
-
if enum_value.deprecation_reason
|
110
|
-
enum_value_node = enum_value_node.merge_directive(
|
111
|
-
name: GraphQL::Directive::DeprecatedDirective.name,
|
112
|
-
arguments: [GraphQL::Language::Nodes::Argument.new(name: "reason", value: enum_value.deprecation_reason)]
|
113
|
-
)
|
114
|
-
end
|
115
|
-
|
116
|
-
enum_value_node
|
117
111
|
end
|
118
112
|
|
119
113
|
def build_scalar_type_node(scalar_type)
|
120
114
|
GraphQL::Language::Nodes::ScalarTypeDefinition.new(
|
121
|
-
name: scalar_type.
|
115
|
+
name: scalar_type.graphql_name,
|
122
116
|
description: scalar_type.description,
|
117
|
+
directives: ast_directives(scalar_type),
|
123
118
|
)
|
124
119
|
end
|
125
120
|
|
@@ -131,10 +126,11 @@ module GraphQL
|
|
131
126
|
end
|
132
127
|
|
133
128
|
argument_node = GraphQL::Language::Nodes::InputValueDefinition.new(
|
134
|
-
name: argument.
|
129
|
+
name: argument.graphql_name,
|
135
130
|
description: argument.description,
|
136
131
|
type: build_type_name_node(argument.type),
|
137
132
|
default_value: default_value,
|
133
|
+
directives: ast_directives(argument),
|
138
134
|
)
|
139
135
|
|
140
136
|
argument_node
|
@@ -142,15 +138,16 @@ module GraphQL
|
|
142
138
|
|
143
139
|
def build_input_object_node(input_object)
|
144
140
|
GraphQL::Language::Nodes::InputObjectTypeDefinition.new(
|
145
|
-
name: input_object.
|
141
|
+
name: input_object.graphql_name,
|
146
142
|
fields: build_argument_nodes(warden.arguments(input_object)),
|
147
143
|
description: input_object.description,
|
144
|
+
directives: ast_directives(input_object),
|
148
145
|
)
|
149
146
|
end
|
150
147
|
|
151
148
|
def build_directive_node(directive)
|
152
149
|
GraphQL::Language::Nodes::DirectiveDefinition.new(
|
153
|
-
name: directive.
|
150
|
+
name: directive.graphql_name,
|
154
151
|
arguments: build_argument_nodes(warden.arguments(directive)),
|
155
152
|
locations: build_directive_location_nodes(directive.locations),
|
156
153
|
description: directive.description,
|
@@ -168,17 +165,17 @@ module GraphQL
|
|
168
165
|
end
|
169
166
|
|
170
167
|
def build_type_name_node(type)
|
171
|
-
case type
|
172
|
-
when
|
168
|
+
case type.kind.name
|
169
|
+
when "LIST"
|
173
170
|
GraphQL::Language::Nodes::ListType.new(
|
174
171
|
of_type: build_type_name_node(type.of_type)
|
175
172
|
)
|
176
|
-
when
|
173
|
+
when "NON_NULL"
|
177
174
|
GraphQL::Language::Nodes::NonNullType.new(
|
178
175
|
of_type: build_type_name_node(type.of_type)
|
179
176
|
)
|
180
177
|
else
|
181
|
-
GraphQL::Language::Nodes::TypeName.new(name: type.
|
178
|
+
GraphQL::Language::Nodes::TypeName.new(name: type.graphql_name)
|
182
179
|
end
|
183
180
|
end
|
184
181
|
|
@@ -187,24 +184,24 @@ module GraphQL
|
|
187
184
|
return GraphQL::Language::Nodes::NullValue.new(name: "null")
|
188
185
|
end
|
189
186
|
|
190
|
-
case type
|
191
|
-
when
|
187
|
+
case type.kind.name
|
188
|
+
when "SCALAR"
|
192
189
|
type.coerce_isolated_result(default_value)
|
193
|
-
when
|
190
|
+
when "ENUM"
|
194
191
|
GraphQL::Language::Nodes::Enum.new(name: type.coerce_isolated_result(default_value))
|
195
|
-
when
|
192
|
+
when "INPUT_OBJECT"
|
196
193
|
GraphQL::Language::Nodes::InputObject.new(
|
197
194
|
arguments: default_value.to_h.map do |arg_name, arg_value|
|
198
|
-
arg_type = type.
|
195
|
+
arg_type = type.arguments.fetch(arg_name.to_s).type
|
199
196
|
GraphQL::Language::Nodes::Argument.new(
|
200
|
-
name: arg_name,
|
197
|
+
name: arg_name.to_s,
|
201
198
|
value: build_default_value(arg_value, arg_type)
|
202
199
|
)
|
203
200
|
end
|
204
201
|
)
|
205
|
-
when
|
202
|
+
when "NON_NULL"
|
206
203
|
build_default_value(default_value, type.of_type)
|
207
|
-
when
|
204
|
+
when "LIST"
|
208
205
|
default_value.to_a.map { |v| build_default_value(v, type.of_type) }
|
209
206
|
else
|
210
207
|
raise GraphQL::RequiredImplementationMissingError, "Unexpected default value type #{type.inspect}"
|
@@ -212,18 +209,18 @@ module GraphQL
|
|
212
209
|
end
|
213
210
|
|
214
211
|
def build_type_definition_node(type)
|
215
|
-
case type
|
216
|
-
when
|
212
|
+
case type.kind.name
|
213
|
+
when "OBJECT"
|
217
214
|
build_object_type_node(type)
|
218
|
-
when
|
215
|
+
when "UNION"
|
219
216
|
build_union_type_node(type)
|
220
|
-
when
|
217
|
+
when "INTERFACE"
|
221
218
|
build_interface_type_node(type)
|
222
|
-
when
|
219
|
+
when "SCALAR"
|
223
220
|
build_scalar_type_node(type)
|
224
|
-
when
|
221
|
+
when "ENUM"
|
225
222
|
build_enum_type_node(type)
|
226
|
-
when
|
223
|
+
when "INPUT_OBJECT"
|
227
224
|
build_input_object_node(type)
|
228
225
|
else
|
229
226
|
raise TypeError
|
@@ -250,7 +247,7 @@ module GraphQL
|
|
250
247
|
definitions = []
|
251
248
|
definitions << build_schema_node if include_schema_node?
|
252
249
|
definitions += build_directive_nodes(warden.directives)
|
253
|
-
definitions += build_type_definition_nodes(warden.
|
250
|
+
definitions += build_type_definition_nodes(warden.reachable_types)
|
254
251
|
definitions
|
255
252
|
end
|
256
253
|
|
@@ -260,7 +257,7 @@ module GraphQL
|
|
260
257
|
end
|
261
258
|
|
262
259
|
if !include_built_in_scalars
|
263
|
-
types = types.reject { |type| type.default_scalar? }
|
260
|
+
types = types.reject { |type| type.kind.scalar? && type.default_scalar? }
|
264
261
|
end
|
265
262
|
|
266
263
|
types
|
@@ -281,9 +278,37 @@ module GraphQL
|
|
281
278
|
end
|
282
279
|
|
283
280
|
def schema_respects_root_name_conventions?(schema)
|
284
|
-
(schema.query.nil? || schema.query.
|
285
|
-
(schema.mutation.nil? || schema.mutation.
|
286
|
-
(schema.subscription.nil? || schema.subscription.
|
281
|
+
(schema.query.nil? || schema.query.graphql_name == 'Query') &&
|
282
|
+
(schema.mutation.nil? || schema.mutation.graphql_name == 'Mutation') &&
|
283
|
+
(schema.subscription.nil? || schema.subscription.graphql_name == 'Subscription')
|
284
|
+
end
|
285
|
+
|
286
|
+
def ast_directives(member)
|
287
|
+
ast_directives = member.ast_node ? member.ast_node.directives : []
|
288
|
+
|
289
|
+
# If this schema was built from IDL, it will already have `@deprecated` in `ast_node.directives`
|
290
|
+
if member.respond_to?(:deprecation_reason) &&
|
291
|
+
(reason = member.deprecation_reason) &&
|
292
|
+
ast_directives.none? { |d| d.name == "deprecated" }
|
293
|
+
|
294
|
+
arguments = []
|
295
|
+
|
296
|
+
if reason != GraphQL::Schema::Directive::DEFAULT_DEPRECATION_REASON
|
297
|
+
arguments << GraphQL::Language::Nodes::Argument.new(
|
298
|
+
name: "reason",
|
299
|
+
value: reason
|
300
|
+
)
|
301
|
+
end
|
302
|
+
|
303
|
+
ast_directives += [
|
304
|
+
GraphQL::Language::Nodes::Directive.new(
|
305
|
+
name: GraphQL::Directive::DeprecatedDirective.graphql_name,
|
306
|
+
arguments: arguments
|
307
|
+
)
|
308
|
+
]
|
309
|
+
end
|
310
|
+
|
311
|
+
ast_directives
|
287
312
|
end
|
288
313
|
|
289
314
|
attr_reader :schema, :warden, :always_include_schema,
|
@@ -3,6 +3,10 @@
|
|
3
3
|
module GraphQL
|
4
4
|
module Language
|
5
5
|
module Lexer
|
6
|
+
if !String.method_defined?(:match?)
|
7
|
+
using GraphQL::StringMatchBackport
|
8
|
+
end
|
9
|
+
|
6
10
|
def self.tokenize(query_string)
|
7
11
|
run_lexer(query_string)
|
8
12
|
end
|
@@ -163,7 +167,7 @@ end
|
|
163
167
|
self.graphql_lexer_en_main = 23;
|
164
168
|
|
165
169
|
def self.run_lexer(query_string)
|
166
|
-
data = query_string.unpack(
|
170
|
+
data = query_string.unpack(PACK_DIRECTIVE)
|
167
171
|
eof = data.length
|
168
172
|
|
169
173
|
# Since `Lexer` is a module, store all lexer state
|
@@ -1421,13 +1425,13 @@ def self.emit_string(ts, te, meta, block:)
|
|
1421
1425
|
quotes_length = block ? 3 : 1
|
1422
1426
|
value = meta[:data][ts + quotes_length, te - ts - 2 * quotes_length].pack(PACK_DIRECTIVE).force_encoding(UTF_8_ENCODING) || ''
|
1423
1427
|
line_incr = 0
|
1424
|
-
if block && !value.
|
1428
|
+
if block && !value.empty?
|
1425
1429
|
line_incr = value.count("\n")
|
1426
1430
|
value = GraphQL::Language::BlockString.trim_whitespace(value)
|
1427
1431
|
end
|
1428
1432
|
# TODO: replace with `String#match?` when we support only Ruby 2.4+
|
1429
1433
|
# (It's faster: https://bugs.ruby-lang.org/issues/8110)
|
1430
|
-
if !value.valid_encoding? || value
|
1434
|
+
if !value.valid_encoding? || !value.match?(VALID_STRING)
|
1431
1435
|
meta[:tokens] << token = GraphQL::Language::Token.new(
|
1432
1436
|
:BAD_UNICODE_ESCAPE,
|
1433
1437
|
value,
|
@@ -121,6 +121,10 @@
|
|
121
121
|
module GraphQL
|
122
122
|
module Language
|
123
123
|
module Lexer
|
124
|
+
if !String.method_defined?(:match?)
|
125
|
+
using GraphQL::StringMatchBackport
|
126
|
+
end
|
127
|
+
|
124
128
|
def self.tokenize(query_string)
|
125
129
|
run_lexer(query_string)
|
126
130
|
end
|
@@ -138,7 +142,7 @@ module GraphQL
|
|
138
142
|
%% write data;
|
139
143
|
|
140
144
|
def self.run_lexer(query_string)
|
141
|
-
data = query_string.unpack(
|
145
|
+
data = query_string.unpack(PACK_DIRECTIVE)
|
142
146
|
eof = data.length
|
143
147
|
|
144
148
|
# Since `Lexer` is a module, store all lexer state
|
@@ -213,13 +217,13 @@ module GraphQL
|
|
213
217
|
quotes_length = block ? 3 : 1
|
214
218
|
value = meta[:data][ts + quotes_length, te - ts - 2 * quotes_length].pack(PACK_DIRECTIVE).force_encoding(UTF_8_ENCODING) || ''
|
215
219
|
line_incr = 0
|
216
|
-
if block && !value.
|
220
|
+
if block && !value.empty?
|
217
221
|
line_incr = value.count("\n")
|
218
222
|
value = GraphQL::Language::BlockString.trim_whitespace(value)
|
219
223
|
end
|
220
224
|
# TODO: replace with `String#match?` when we support only Ruby 2.4+
|
221
225
|
# (It's faster: https://bugs.ruby-lang.org/issues/8110)
|
222
|
-
if !value.valid_encoding? || value
|
226
|
+
if !value.valid_encoding? || !value.match?(VALID_STRING)
|
223
227
|
meta[:tokens] << token = GraphQL::Language::Token.new(
|
224
228
|
:BAD_UNICODE_ESCAPE,
|
225
229
|
value,
|