graphql 2.0.13 → 2.3.10
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/install/mutation_root_generator.rb +2 -2
- data/lib/generators/graphql/install/templates/base_mutation.erb +2 -0
- data/lib/generators/graphql/install/templates/mutation_type.erb +2 -0
- data/lib/generators/graphql/install_generator.rb +3 -0
- data/lib/generators/graphql/mutation_delete_generator.rb +1 -1
- data/lib/generators/graphql/mutation_update_generator.rb +1 -1
- data/lib/generators/graphql/relay.rb +18 -1
- data/lib/generators/graphql/templates/base_argument.erb +2 -0
- data/lib/generators/graphql/templates/base_connection.erb +2 -0
- data/lib/generators/graphql/templates/base_edge.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_object.erb +2 -0
- data/lib/generators/graphql/templates/base_resolver.erb +6 -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/graphql_controller.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/node_type.erb +2 -0
- data/lib/generators/graphql/templates/query_type.erb +2 -0
- data/lib/generators/graphql/templates/schema.erb +8 -0
- data/lib/graphql/analysis/analyzer.rb +89 -0
- data/lib/graphql/analysis/field_usage.rb +82 -0
- data/lib/graphql/analysis/max_query_complexity.rb +20 -0
- data/lib/graphql/analysis/max_query_depth.rb +20 -0
- data/lib/graphql/analysis/query_complexity.rb +183 -0
- data/lib/graphql/analysis/query_depth.rb +58 -0
- data/lib/graphql/analysis/visitor.rb +283 -0
- data/lib/graphql/analysis.rb +92 -1
- data/lib/graphql/backtrace/inspect_result.rb +0 -12
- data/lib/graphql/backtrace/table.rb +2 -2
- data/lib/graphql/backtrace/trace.rb +93 -0
- data/lib/graphql/backtrace/tracer.rb +1 -1
- data/lib/graphql/backtrace.rb +2 -1
- data/lib/graphql/coercion_error.rb +1 -9
- data/lib/graphql/dataloader/async_dataloader.rb +88 -0
- data/lib/graphql/dataloader/null_dataloader.rb +1 -1
- data/lib/graphql/dataloader/request.rb +5 -0
- data/lib/graphql/dataloader/source.rb +89 -45
- data/lib/graphql/dataloader.rb +115 -142
- data/lib/graphql/duration_encoding_error.rb +16 -0
- data/lib/graphql/execution/interpreter/argument_value.rb +5 -1
- data/lib/graphql/execution/interpreter/arguments.rb +1 -1
- data/lib/graphql/execution/interpreter/arguments_cache.rb +33 -33
- data/lib/graphql/execution/interpreter/resolve.rb +19 -0
- data/lib/graphql/execution/interpreter/runtime/graphql_result.rb +175 -0
- data/lib/graphql/execution/interpreter/runtime.rb +331 -455
- data/lib/graphql/execution/interpreter.rb +125 -61
- data/lib/graphql/execution/lazy.rb +6 -12
- data/lib/graphql/execution/lookahead.rb +124 -46
- data/lib/graphql/execution/multiplex.rb +3 -117
- data/lib/graphql/execution.rb +0 -1
- data/lib/graphql/introspection/directive_type.rb +3 -3
- data/lib/graphql/introspection/dynamic_fields.rb +1 -1
- data/lib/graphql/introspection/entry_points.rb +11 -5
- data/lib/graphql/introspection/field_type.rb +2 -2
- data/lib/graphql/introspection/schema_type.rb +10 -13
- data/lib/graphql/introspection/type_type.rb +17 -10
- data/lib/graphql/introspection.rb +3 -2
- data/lib/graphql/language/block_string.rb +34 -18
- data/lib/graphql/language/definition_slice.rb +1 -1
- data/lib/graphql/language/document_from_schema_definition.rb +75 -59
- data/lib/graphql/language/lexer.rb +358 -1506
- data/lib/graphql/language/nodes.rb +166 -93
- data/lib/graphql/language/parser.rb +795 -1953
- data/lib/graphql/language/printer.rb +340 -160
- data/lib/graphql/language/sanitized_printer.rb +21 -23
- data/lib/graphql/language/static_visitor.rb +167 -0
- data/lib/graphql/language/visitor.rb +188 -141
- data/lib/graphql/language.rb +61 -1
- data/lib/graphql/load_application_object_failed_error.rb +5 -1
- data/lib/graphql/pagination/active_record_relation_connection.rb +0 -8
- data/lib/graphql/pagination/array_connection.rb +6 -6
- data/lib/graphql/pagination/connection.rb +33 -6
- data/lib/graphql/pagination/mongoid_relation_connection.rb +1 -2
- data/lib/graphql/query/context/scoped_context.rb +101 -0
- data/lib/graphql/query/context.rb +117 -112
- data/lib/graphql/query/null_context.rb +12 -25
- data/lib/graphql/query/validation_pipeline.rb +6 -5
- data/lib/graphql/query/variables.rb +3 -3
- data/lib/graphql/query.rb +86 -30
- data/lib/graphql/railtie.rb +9 -6
- data/lib/graphql/rake_task.rb +29 -11
- data/lib/graphql/rubocop/graphql/base_cop.rb +1 -1
- data/lib/graphql/schema/addition.rb +59 -23
- data/lib/graphql/schema/always_visible.rb +11 -0
- data/lib/graphql/schema/argument.rb +55 -26
- data/lib/graphql/schema/base_64_encoder.rb +3 -5
- data/lib/graphql/schema/build_from_definition.rb +56 -32
- data/lib/graphql/schema/directive/one_of.rb +24 -0
- data/lib/graphql/schema/directive/specified_by.rb +14 -0
- data/lib/graphql/schema/directive/transform.rb +1 -1
- data/lib/graphql/schema/directive.rb +15 -3
- data/lib/graphql/schema/enum.rb +35 -24
- data/lib/graphql/schema/enum_value.rb +2 -3
- data/lib/graphql/schema/field/connection_extension.rb +2 -16
- data/lib/graphql/schema/field/scope_extension.rb +8 -1
- data/lib/graphql/schema/field.rb +147 -107
- data/lib/graphql/schema/field_extension.rb +1 -4
- data/lib/graphql/schema/find_inherited_value.rb +2 -7
- data/lib/graphql/schema/has_single_input_argument.rb +158 -0
- data/lib/graphql/schema/input_object.rb +47 -11
- data/lib/graphql/schema/interface.rb +15 -21
- data/lib/graphql/schema/introspection_system.rb +7 -17
- data/lib/graphql/schema/late_bound_type.rb +10 -0
- data/lib/graphql/schema/list.rb +2 -2
- data/lib/graphql/schema/loader.rb +2 -3
- data/lib/graphql/schema/member/base_dsl_methods.rb +18 -14
- data/lib/graphql/schema/member/build_type.rb +11 -3
- data/lib/graphql/schema/member/has_arguments.rb +170 -130
- data/lib/graphql/schema/member/has_ast_node.rb +12 -0
- data/lib/graphql/schema/member/has_deprecation_reason.rb +3 -4
- data/lib/graphql/schema/member/has_directives.rb +81 -61
- data/lib/graphql/schema/member/has_fields.rb +100 -38
- data/lib/graphql/schema/member/has_interfaces.rb +65 -10
- data/lib/graphql/schema/member/has_unresolved_type_error.rb +5 -1
- data/lib/graphql/schema/member/has_validators.rb +32 -6
- data/lib/graphql/schema/member/relay_shortcuts.rb +19 -0
- data/lib/graphql/schema/member/scoped.rb +19 -0
- data/lib/graphql/schema/member/type_system_helpers.rb +16 -0
- data/lib/graphql/schema/member/validates_input.rb +3 -3
- data/lib/graphql/schema/mutation.rb +7 -0
- data/lib/graphql/schema/object.rb +16 -5
- data/lib/graphql/schema/printer.rb +11 -8
- data/lib/graphql/schema/relay_classic_mutation.rb +7 -129
- data/lib/graphql/schema/resolver/has_payload_type.rb +9 -9
- data/lib/graphql/schema/resolver.rb +47 -32
- data/lib/graphql/schema/scalar.rb +3 -3
- data/lib/graphql/schema/subscription.rb +11 -4
- data/lib/graphql/schema/subset.rb +397 -0
- data/lib/graphql/schema/timeout.rb +25 -29
- data/lib/graphql/schema/type_expression.rb +2 -2
- data/lib/graphql/schema/type_membership.rb +3 -0
- data/lib/graphql/schema/union.rb +11 -2
- data/lib/graphql/schema/unique_within_type.rb +1 -1
- data/lib/graphql/schema/validator/all_validator.rb +60 -0
- data/lib/graphql/schema/validator.rb +4 -2
- data/lib/graphql/schema/warden.rb +238 -93
- data/lib/graphql/schema.rb +498 -103
- data/lib/graphql/static_validation/all_rules.rb +2 -1
- data/lib/graphql/static_validation/base_visitor.rb +7 -6
- data/lib/graphql/static_validation/definition_dependencies.rb +7 -1
- data/lib/graphql/static_validation/literal_validator.rb +24 -7
- data/lib/graphql/static_validation/rules/argument_literals_are_compatible.rb +1 -1
- data/lib/graphql/static_validation/rules/arguments_are_defined.rb +1 -1
- data/lib/graphql/static_validation/rules/directives_are_defined.rb +1 -2
- data/lib/graphql/static_validation/rules/fields_are_defined_on_type.rb +1 -1
- data/lib/graphql/static_validation/rules/fields_have_appropriate_selections.rb +12 -4
- data/lib/graphql/static_validation/rules/fields_will_merge.rb +10 -10
- data/lib/graphql/static_validation/rules/fragment_spreads_are_possible.rb +3 -3
- data/lib/graphql/static_validation/rules/fragment_types_exist.rb +1 -1
- data/lib/graphql/static_validation/rules/fragments_are_on_composite_types.rb +1 -1
- data/lib/graphql/static_validation/rules/mutation_root_exists.rb +1 -1
- data/lib/graphql/static_validation/rules/one_of_input_objects_are_valid.rb +66 -0
- data/lib/graphql/static_validation/rules/one_of_input_objects_are_valid_error.rb +29 -0
- data/lib/graphql/static_validation/rules/query_root_exists.rb +1 -1
- data/lib/graphql/static_validation/rules/required_arguments_are_present.rb +4 -4
- data/lib/graphql/static_validation/rules/required_input_object_attributes_are_present.rb +5 -5
- data/lib/graphql/static_validation/rules/subscription_root_exists.rb +1 -1
- data/lib/graphql/static_validation/rules/variable_default_values_are_correctly_typed.rb +18 -27
- data/lib/graphql/static_validation/rules/variable_usages_are_allowed.rb +1 -1
- data/lib/graphql/static_validation/rules/variables_are_input_types.rb +1 -1
- data/lib/graphql/static_validation/validation_context.rb +5 -5
- data/lib/graphql/static_validation/validator.rb +4 -1
- data/lib/graphql/static_validation.rb +0 -1
- data/lib/graphql/subscriptions/action_cable_subscriptions.rb +11 -4
- data/lib/graphql/subscriptions/broadcast_analyzer.rb +11 -5
- data/lib/graphql/subscriptions/event.rb +11 -10
- data/lib/graphql/subscriptions/serialize.rb +2 -0
- data/lib/graphql/subscriptions.rb +20 -13
- data/lib/graphql/testing/helpers.rb +151 -0
- data/lib/graphql/testing.rb +2 -0
- data/lib/graphql/tracing/active_support_notifications_trace.rb +16 -0
- data/lib/graphql/tracing/appoptics_trace.rb +251 -0
- data/lib/graphql/tracing/appoptics_tracing.rb +2 -2
- data/lib/graphql/tracing/appsignal_trace.rb +77 -0
- data/lib/graphql/tracing/data_dog_trace.rb +183 -0
- data/lib/graphql/tracing/data_dog_tracing.rb +9 -21
- data/lib/graphql/{execution/instrumentation.rb → tracing/legacy_hooks_trace.rb} +10 -28
- data/lib/graphql/tracing/legacy_trace.rb +69 -0
- data/lib/graphql/tracing/new_relic_trace.rb +75 -0
- data/lib/graphql/tracing/notifications_trace.rb +45 -0
- data/lib/graphql/tracing/platform_trace.rb +118 -0
- data/lib/graphql/tracing/platform_tracing.rb +17 -3
- data/lib/graphql/tracing/{prometheus_tracing → prometheus_trace}/graphql_collector.rb +4 -2
- data/lib/graphql/tracing/prometheus_trace.rb +89 -0
- data/lib/graphql/tracing/prometheus_tracing.rb +3 -3
- data/lib/graphql/tracing/scout_trace.rb +72 -0
- data/lib/graphql/tracing/sentry_trace.rb +112 -0
- data/lib/graphql/tracing/statsd_trace.rb +56 -0
- data/lib/graphql/tracing/trace.rb +76 -0
- data/lib/graphql/tracing.rb +20 -40
- data/lib/graphql/type_kinds.rb +7 -4
- data/lib/graphql/types/iso_8601_duration.rb +77 -0
- data/lib/graphql/types/relay/base_connection.rb +1 -1
- data/lib/graphql/types/relay/connection_behaviors.rb +68 -6
- data/lib/graphql/types/relay/edge_behaviors.rb +33 -5
- data/lib/graphql/types/relay/node_behaviors.rb +8 -2
- data/lib/graphql/types/relay/page_info_behaviors.rb +11 -2
- data/lib/graphql/types/relay.rb +0 -1
- data/lib/graphql/types/string.rb +1 -1
- data/lib/graphql/types.rb +1 -0
- data/lib/graphql/version.rb +1 -1
- data/lib/graphql.rb +27 -20
- data/readme.md +13 -3
- metadata +96 -47
- data/lib/graphql/analysis/ast/analyzer.rb +0 -84
- data/lib/graphql/analysis/ast/field_usage.rb +0 -57
- data/lib/graphql/analysis/ast/max_query_complexity.rb +0 -22
- data/lib/graphql/analysis/ast/max_query_depth.rb +0 -22
- data/lib/graphql/analysis/ast/query_complexity.rb +0 -230
- data/lib/graphql/analysis/ast/query_depth.rb +0 -55
- data/lib/graphql/analysis/ast/visitor.rb +0 -269
- data/lib/graphql/analysis/ast.rb +0 -81
- data/lib/graphql/deprecation.rb +0 -9
- data/lib/graphql/filter.rb +0 -53
- data/lib/graphql/language/lexer.rl +0 -280
- data/lib/graphql/language/parser.y +0 -554
- data/lib/graphql/language/token.rb +0 -34
- data/lib/graphql/schema/base_64_bp.rb +0 -26
- data/lib/graphql/schema/invalid_type_error.rb +0 -7
- data/lib/graphql/static_validation/type_stack.rb +0 -216
- data/lib/graphql/subscriptions/instrumentation.rb +0 -28
- data/lib/graphql/types/relay/default_relay.rb +0 -21
@@ -2,7 +2,7 @@
|
|
2
2
|
module GraphQL
|
3
3
|
module Introspection
|
4
4
|
class DynamicFields < Introspection::BaseObject
|
5
|
-
field :__typename, String, "The name of this type", null: false
|
5
|
+
field :__typename, String, "The name of this type", null: false, dynamic_introspection: true
|
6
6
|
|
7
7
|
def __typename
|
8
8
|
object.class.graphql_name
|
@@ -2,20 +2,26 @@
|
|
2
2
|
module GraphQL
|
3
3
|
module Introspection
|
4
4
|
class EntryPoints < Introspection::BaseObject
|
5
|
-
field :__schema, GraphQL::Schema::LateBoundType.new("__Schema"), "This GraphQL schema", null: false
|
6
|
-
field :__type, GraphQL::Schema::LateBoundType.new("__Type"), "A type in the GraphQL system" do
|
5
|
+
field :__schema, GraphQL::Schema::LateBoundType.new("__Schema"), "This GraphQL schema", null: false, dynamic_introspection: true
|
6
|
+
field :__type, GraphQL::Schema::LateBoundType.new("__Type"), "A type in the GraphQL system", dynamic_introspection: true do
|
7
7
|
argument :name, String
|
8
8
|
end
|
9
9
|
|
10
10
|
def __schema
|
11
11
|
# Apply wrapping manually since this field isn't wrapped by instrumentation
|
12
|
-
schema =
|
12
|
+
schema = context.schema
|
13
13
|
schema_type = schema.introspection_system.types["__Schema"]
|
14
|
-
schema_type.
|
14
|
+
schema_type.wrap(schema, context)
|
15
15
|
end
|
16
16
|
|
17
17
|
def __type(name:)
|
18
|
-
context.
|
18
|
+
if context.types.reachable_type?(name)
|
19
|
+
context.types.type(name)
|
20
|
+
elsif (type = context.schema.extra_types.find { |t| t.graphql_name == name })
|
21
|
+
type
|
22
|
+
else
|
23
|
+
nil
|
24
|
+
end
|
19
25
|
end
|
20
26
|
end
|
21
27
|
end
|
@@ -7,7 +7,7 @@ module GraphQL
|
|
7
7
|
"a name, potentially a list of arguments, and a return type."
|
8
8
|
field :name, String, null: false
|
9
9
|
field :description, String
|
10
|
-
field :args, [GraphQL::Schema::LateBoundType.new("__InputValue")], null: false do
|
10
|
+
field :args, [GraphQL::Schema::LateBoundType.new("__InputValue")], null: false, scope: false do
|
11
11
|
argument :include_deprecated, Boolean, required: false, default_value: false
|
12
12
|
end
|
13
13
|
field :type, GraphQL::Schema::LateBoundType.new("__Type"), null: false
|
@@ -19,7 +19,7 @@ module GraphQL
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def args(include_deprecated:)
|
22
|
-
args = @context.
|
22
|
+
args = @context.types.arguments(@object)
|
23
23
|
args = args.reject(&:deprecation_reason) unless include_deprecated
|
24
24
|
args
|
25
25
|
end
|
@@ -8,11 +8,11 @@ module GraphQL
|
|
8
8
|
"available types and directives on the server, as well as the entry points for "\
|
9
9
|
"query, mutation, and subscription operations."
|
10
10
|
|
11
|
-
field :types, [GraphQL::Schema::LateBoundType.new("__Type")], "A list of all types supported by this server.", null: false
|
11
|
+
field :types, [GraphQL::Schema::LateBoundType.new("__Type")], "A list of all types supported by this server.", null: false, scope: false
|
12
12
|
field :query_type, GraphQL::Schema::LateBoundType.new("__Type"), "The type that query operations will be rooted at.", null: false
|
13
13
|
field :mutation_type, GraphQL::Schema::LateBoundType.new("__Type"), "If this server supports mutation, the type that mutation operations will be rooted at."
|
14
14
|
field :subscription_type, GraphQL::Schema::LateBoundType.new("__Type"), "If this server support subscription, the type that subscription operations will be rooted at."
|
15
|
-
field :directives, [GraphQL::Schema::LateBoundType.new("__Directive")], "A list of all directives supported by this server.", null: false
|
15
|
+
field :directives, [GraphQL::Schema::LateBoundType.new("__Directive")], "A list of all directives supported by this server.", null: false, scope: false
|
16
16
|
field :description, String, resolver_method: :schema_description
|
17
17
|
|
18
18
|
def schema_description
|
@@ -20,29 +20,26 @@ module GraphQL
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def types
|
23
|
-
|
23
|
+
query_types = context.types.all_types
|
24
|
+
types = query_types + context.schema.extra_types
|
25
|
+
types.sort_by!(&:graphql_name)
|
26
|
+
types
|
24
27
|
end
|
25
28
|
|
26
29
|
def query_type
|
27
|
-
|
30
|
+
@context.types.query_root
|
28
31
|
end
|
29
32
|
|
30
33
|
def mutation_type
|
31
|
-
|
34
|
+
@context.types.mutation_root
|
32
35
|
end
|
33
36
|
|
34
37
|
def subscription_type
|
35
|
-
|
38
|
+
@context.types.subscription_root
|
36
39
|
end
|
37
40
|
|
38
41
|
def directives
|
39
|
-
@context.
|
40
|
-
end
|
41
|
-
|
42
|
-
private
|
43
|
-
|
44
|
-
def permitted_root_type(op_type)
|
45
|
-
@context.warden.root_type_for_operation(op_type)
|
42
|
+
@context.types.directives
|
46
43
|
end
|
47
44
|
end
|
48
45
|
end
|
@@ -14,21 +14,28 @@ module GraphQL
|
|
14
14
|
field :kind, GraphQL::Schema::LateBoundType.new("__TypeKind"), null: false
|
15
15
|
field :name, String, method: :graphql_name
|
16
16
|
field :description, String
|
17
|
-
field :fields, [GraphQL::Schema::LateBoundType.new("__Field")] do
|
17
|
+
field :fields, [GraphQL::Schema::LateBoundType.new("__Field")], scope: false do
|
18
18
|
argument :include_deprecated, Boolean, required: false, default_value: false
|
19
19
|
end
|
20
|
-
field :interfaces, [GraphQL::Schema::LateBoundType.new("__Type")]
|
21
|
-
field :possible_types, [GraphQL::Schema::LateBoundType.new("__Type")]
|
22
|
-
field :enum_values, [GraphQL::Schema::LateBoundType.new("__EnumValue")] do
|
20
|
+
field :interfaces, [GraphQL::Schema::LateBoundType.new("__Type")], scope: false
|
21
|
+
field :possible_types, [GraphQL::Schema::LateBoundType.new("__Type")], scope: false
|
22
|
+
field :enum_values, [GraphQL::Schema::LateBoundType.new("__EnumValue")], scope: false do
|
23
23
|
argument :include_deprecated, Boolean, required: false, default_value: false
|
24
24
|
end
|
25
|
-
field :input_fields, [GraphQL::Schema::LateBoundType.new("__InputValue")] do
|
25
|
+
field :input_fields, [GraphQL::Schema::LateBoundType.new("__InputValue")], scope: false do
|
26
26
|
argument :include_deprecated, Boolean, required: false, default_value: false
|
27
27
|
end
|
28
28
|
field :of_type, GraphQL::Schema::LateBoundType.new("__Type")
|
29
29
|
|
30
30
|
field :specifiedByURL, String, resolver_method: :specified_by_url
|
31
31
|
|
32
|
+
field :is_one_of, Boolean, null: false
|
33
|
+
|
34
|
+
def is_one_of
|
35
|
+
object.kind.input_object? &&
|
36
|
+
object.directives.any? { |d| d.graphql_name == "oneOf" }
|
37
|
+
end
|
38
|
+
|
32
39
|
def specified_by_url
|
33
40
|
if object.kind.scalar?
|
34
41
|
object.specified_by_url
|
@@ -45,7 +52,7 @@ module GraphQL
|
|
45
52
|
if !@object.kind.enum?
|
46
53
|
nil
|
47
54
|
else
|
48
|
-
enum_values = @context.
|
55
|
+
enum_values = @context.types.enum_values(@object)
|
49
56
|
|
50
57
|
if !include_deprecated
|
51
58
|
enum_values = enum_values.select {|f| !f.deprecation_reason }
|
@@ -57,7 +64,7 @@ module GraphQL
|
|
57
64
|
|
58
65
|
def interfaces
|
59
66
|
if @object.kind.object? || @object.kind.interface?
|
60
|
-
@context.
|
67
|
+
@context.types.interfaces(@object).sort_by(&:graphql_name)
|
61
68
|
else
|
62
69
|
nil
|
63
70
|
end
|
@@ -65,7 +72,7 @@ module GraphQL
|
|
65
72
|
|
66
73
|
def input_fields(include_deprecated:)
|
67
74
|
if @object.kind.input_object?
|
68
|
-
args = @context.
|
75
|
+
args = @context.types.arguments(@object)
|
69
76
|
args = args.reject(&:deprecation_reason) unless include_deprecated
|
70
77
|
args
|
71
78
|
else
|
@@ -75,7 +82,7 @@ module GraphQL
|
|
75
82
|
|
76
83
|
def possible_types
|
77
84
|
if @object.kind.abstract?
|
78
|
-
@context.
|
85
|
+
@context.types.possible_types(@object).sort_by(&:graphql_name)
|
79
86
|
else
|
80
87
|
nil
|
81
88
|
end
|
@@ -85,7 +92,7 @@ module GraphQL
|
|
85
92
|
if !@object.kind.fields?
|
86
93
|
nil
|
87
94
|
else
|
88
|
-
fields = @context.
|
95
|
+
fields = @context.types.fields(@object)
|
89
96
|
if !include_deprecated
|
90
97
|
fields = fields.select {|f| !f.deprecation_reason }
|
91
98
|
end
|
@@ -1,10 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
module GraphQL
|
3
3
|
module Introspection
|
4
|
-
def self.query(include_deprecated_args: false, include_schema_description: false, include_is_repeatable: false, include_specified_by_url: false)
|
4
|
+
def self.query(include_deprecated_args: false, include_schema_description: false, include_is_repeatable: false, include_specified_by_url: false, include_is_one_of: false)
|
5
5
|
# The introspection query to end all introspection queries, copied from
|
6
6
|
# https://github.com/graphql/graphql-js/blob/master/src/utilities/introspectionQuery.js
|
7
|
-
<<-QUERY
|
7
|
+
<<-QUERY.gsub(/\n{2,}/, "\n")
|
8
8
|
query IntrospectionQuery {
|
9
9
|
__schema {
|
10
10
|
#{include_schema_description ? "description" : ""}
|
@@ -30,6 +30,7 @@ fragment FullType on __Type {
|
|
30
30
|
name
|
31
31
|
description
|
32
32
|
#{include_specified_by_url ? "specifiedByURL" : ""}
|
33
|
+
#{include_is_one_of ? "isOneOf" : ""}
|
33
34
|
fields(includeDeprecated: true) {
|
34
35
|
name
|
35
36
|
description
|
@@ -47,10 +47,10 @@ module GraphQL
|
|
47
47
|
end
|
48
48
|
|
49
49
|
# Remove leading & trailing blank lines
|
50
|
-
while lines.size > 0 && lines
|
50
|
+
while lines.size > 0 && contains_only_whitespace?(lines.first)
|
51
51
|
lines.shift
|
52
52
|
end
|
53
|
-
while lines.size > 0 && lines
|
53
|
+
while lines.size > 0 && contains_only_whitespace?(lines.last)
|
54
54
|
lines.pop
|
55
55
|
end
|
56
56
|
|
@@ -59,40 +59,56 @@ module GraphQL
|
|
59
59
|
end
|
60
60
|
|
61
61
|
def self.print(str, indent: '')
|
62
|
-
|
62
|
+
line_length = 120 - indent.length
|
63
|
+
block_str = "".dup
|
64
|
+
triple_quotes = "\"\"\"\n"
|
65
|
+
block_str << indent
|
66
|
+
block_str << triple_quotes
|
63
67
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
68
|
+
if str.include?("\n")
|
69
|
+
str.split("\n") do |line|
|
70
|
+
if line == ''
|
71
|
+
block_str << "\n"
|
72
|
+
else
|
73
|
+
break_line(line, line_length) do |subline|
|
74
|
+
block_str << indent
|
75
|
+
block_str << subline
|
76
|
+
block_str << "\n"
|
77
|
+
end
|
73
78
|
end
|
74
79
|
end
|
80
|
+
else
|
81
|
+
break_line(str, line_length) do |subline|
|
82
|
+
block_str << indent
|
83
|
+
block_str << subline
|
84
|
+
block_str << "\n"
|
85
|
+
end
|
75
86
|
end
|
76
87
|
|
77
|
-
block_str <<
|
88
|
+
block_str << indent
|
89
|
+
block_str << triple_quotes
|
78
90
|
end
|
79
91
|
|
80
92
|
private
|
81
93
|
|
82
94
|
def self.break_line(line, length)
|
83
|
-
return
|
95
|
+
return yield(line) if line.length < length + 5
|
84
96
|
|
85
97
|
parts = line.split(Regexp.new("((?: |^).{15,#{length - 40}}(?= |$))"))
|
86
|
-
return
|
98
|
+
return yield(line) if parts.length < 4
|
87
99
|
|
88
|
-
|
100
|
+
yield(parts.slice!(0, 3).join)
|
89
101
|
|
90
102
|
parts.each_with_index do |part, i|
|
91
103
|
next if i % 2 == 1
|
92
|
-
|
104
|
+
yield "#{part[1..-1]}#{parts[i + 1]}"
|
93
105
|
end
|
94
106
|
|
95
|
-
|
107
|
+
nil
|
108
|
+
end
|
109
|
+
|
110
|
+
def self.contains_only_whitespace?(line)
|
111
|
+
line.match?(/^\s*$/)
|
96
112
|
end
|
97
113
|
end
|
98
114
|
end
|
@@ -14,7 +14,7 @@ module GraphQL
|
|
14
14
|
# @param include_built_in_directives [Boolean] Whether or not to include built in directives in the AST
|
15
15
|
class DocumentFromSchemaDefinition
|
16
16
|
def initialize(
|
17
|
-
schema, context: nil,
|
17
|
+
schema, context: nil, include_introspection_types: false,
|
18
18
|
include_built_in_directives: false, include_built_in_scalars: false, always_include_schema: false
|
19
19
|
)
|
20
20
|
@schema = schema
|
@@ -22,19 +22,10 @@ module GraphQL
|
|
22
22
|
@include_introspection_types = include_introspection_types
|
23
23
|
@include_built_in_scalars = include_built_in_scalars
|
24
24
|
@include_built_in_directives = include_built_in_directives
|
25
|
+
@include_one_of = false
|
25
26
|
|
26
|
-
|
27
|
-
|
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)
|
32
|
-
@warden = GraphQL::Schema::Warden.new(
|
33
|
-
filter,
|
34
|
-
schema: @schema,
|
35
|
-
context: schema_context,
|
36
|
-
)
|
37
|
-
schema_context.warden = @warden
|
27
|
+
dummy_query = @schema.query_class.new(@schema, "{ __typename }", validate: false, context: context)
|
28
|
+
@types = dummy_query.types # rubocop:disable Development/ContextIsPassedCop
|
38
29
|
end
|
39
30
|
|
40
31
|
def document
|
@@ -44,23 +35,31 @@ module GraphQL
|
|
44
35
|
end
|
45
36
|
|
46
37
|
def build_schema_node
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
38
|
+
if !schema_respects_root_name_conventions?(@schema)
|
39
|
+
GraphQL::Language::Nodes::SchemaDefinition.new(
|
40
|
+
query: @types.query_root&.graphql_name,
|
41
|
+
mutation: @types.mutation_root&.graphql_name,
|
42
|
+
subscription: @types.subscription_root&.graphql_name,
|
43
|
+
directives: definition_directives(@schema, :schema_directives)
|
44
|
+
)
|
45
|
+
else
|
46
|
+
# A plain `schema ...` _must_ include root type definitions.
|
47
|
+
# If the only difference is directives, then you have to use `extend schema`
|
48
|
+
GraphQL::Language::Nodes::SchemaExtension.new(directives: definition_directives(@schema, :schema_directives))
|
49
|
+
end
|
57
50
|
end
|
58
51
|
|
59
52
|
def build_object_type_node(object_type)
|
53
|
+
ints = @types.interfaces(object_type)
|
54
|
+
if ints.any?
|
55
|
+
ints.sort_by!(&:graphql_name)
|
56
|
+
ints.map! { |iface| build_type_name_node(iface) }
|
57
|
+
end
|
58
|
+
|
60
59
|
GraphQL::Language::Nodes::ObjectTypeDefinition.new(
|
61
60
|
name: object_type.graphql_name,
|
62
|
-
interfaces:
|
63
|
-
fields: build_field_nodes(
|
61
|
+
interfaces: ints,
|
62
|
+
fields: build_field_nodes(@types.fields(object_type)),
|
64
63
|
description: object_type.description,
|
65
64
|
directives: directives(object_type),
|
66
65
|
)
|
@@ -69,7 +68,7 @@ module GraphQL
|
|
69
68
|
def build_field_node(field)
|
70
69
|
GraphQL::Language::Nodes::FieldDefinition.new(
|
71
70
|
name: field.graphql_name,
|
72
|
-
arguments: build_argument_nodes(
|
71
|
+
arguments: build_argument_nodes(@types.arguments(field)),
|
73
72
|
type: build_type_name_node(field.type),
|
74
73
|
description: field.description,
|
75
74
|
directives: directives(field),
|
@@ -80,7 +79,7 @@ module GraphQL
|
|
80
79
|
GraphQL::Language::Nodes::UnionTypeDefinition.new(
|
81
80
|
name: union_type.graphql_name,
|
82
81
|
description: union_type.description,
|
83
|
-
types:
|
82
|
+
types: @types.possible_types(union_type).sort_by(&:graphql_name).map { |type| build_type_name_node(type) },
|
84
83
|
directives: directives(union_type),
|
85
84
|
)
|
86
85
|
end
|
@@ -88,9 +87,9 @@ module GraphQL
|
|
88
87
|
def build_interface_type_node(interface_type)
|
89
88
|
GraphQL::Language::Nodes::InterfaceTypeDefinition.new(
|
90
89
|
name: interface_type.graphql_name,
|
91
|
-
interfaces:
|
90
|
+
interfaces: @types.interfaces(interface_type).sort_by(&:graphql_name).map { |type| build_type_name_node(type) },
|
92
91
|
description: interface_type.description,
|
93
|
-
fields: build_field_nodes(
|
92
|
+
fields: build_field_nodes(@types.fields(interface_type)),
|
94
93
|
directives: directives(interface_type),
|
95
94
|
)
|
96
95
|
end
|
@@ -98,7 +97,7 @@ module GraphQL
|
|
98
97
|
def build_enum_type_node(enum_type)
|
99
98
|
GraphQL::Language::Nodes::EnumTypeDefinition.new(
|
100
99
|
name: enum_type.graphql_name,
|
101
|
-
values:
|
100
|
+
values: @types.enum_values(enum_type).sort_by(&:graphql_name).map do |enum_value|
|
102
101
|
build_enum_value_node(enum_value)
|
103
102
|
end,
|
104
103
|
description: enum_type.description,
|
@@ -143,7 +142,7 @@ module GraphQL
|
|
143
142
|
def build_input_object_node(input_object)
|
144
143
|
GraphQL::Language::Nodes::InputObjectTypeDefinition.new(
|
145
144
|
name: input_object.graphql_name,
|
146
|
-
fields: build_argument_nodes(
|
145
|
+
fields: build_argument_nodes(@types.arguments(input_object)),
|
147
146
|
description: input_object.description,
|
148
147
|
directives: directives(input_object),
|
149
148
|
)
|
@@ -153,7 +152,7 @@ module GraphQL
|
|
153
152
|
GraphQL::Language::Nodes::DirectiveDefinition.new(
|
154
153
|
name: directive.graphql_name,
|
155
154
|
repeatable: directive.repeatable?,
|
156
|
-
arguments: build_argument_nodes(
|
155
|
+
arguments: build_argument_nodes(@types.arguments(directive)),
|
157
156
|
locations: build_directive_location_nodes(directive.locations),
|
158
157
|
description: directive.description,
|
159
158
|
)
|
@@ -180,7 +179,8 @@ module GraphQL
|
|
180
179
|
of_type: build_type_name_node(type.of_type)
|
181
180
|
)
|
182
181
|
else
|
183
|
-
|
182
|
+
@cached_type_name_nodes ||= {}
|
183
|
+
@cached_type_name_nodes[type.graphql_name] ||= GraphQL::Language::Nodes::TypeName.new(name: type.graphql_name)
|
184
184
|
end
|
185
185
|
end
|
186
186
|
|
@@ -197,7 +197,7 @@ module GraphQL
|
|
197
197
|
when "INPUT_OBJECT"
|
198
198
|
GraphQL::Language::Nodes::InputObject.new(
|
199
199
|
arguments: default_value.to_h.map do |arg_name, arg_value|
|
200
|
-
args = @
|
200
|
+
args = @types.arguments(type)
|
201
201
|
arg = args.find { |a| a.keyword.to_s == arg_name.to_s }
|
202
202
|
if arg.nil?
|
203
203
|
raise ArgumentError, "No argument definition on #{type.graphql_name} for argument: #{arg_name.inspect} (expected one of: #{args.map(&:keyword)})"
|
@@ -237,26 +237,39 @@ module GraphQL
|
|
237
237
|
end
|
238
238
|
|
239
239
|
def build_argument_nodes(arguments)
|
240
|
-
arguments
|
241
|
-
.map { |arg| build_argument_node(arg) }
|
242
|
-
.sort_by(&:name)
|
240
|
+
if arguments.any?
|
241
|
+
nodes = arguments.map { |arg| build_argument_node(arg) }
|
242
|
+
nodes.sort_by!(&:name)
|
243
|
+
nodes
|
244
|
+
else
|
245
|
+
arguments
|
246
|
+
end
|
243
247
|
end
|
244
248
|
|
245
249
|
def build_directive_nodes(directives)
|
246
|
-
if !include_built_in_directives
|
247
|
-
directives = directives.reject { |directive| directive.default_directive? }
|
248
|
-
end
|
249
|
-
|
250
250
|
directives
|
251
251
|
.map { |directive| build_directive_node(directive) }
|
252
252
|
.sort_by(&:name)
|
253
253
|
end
|
254
254
|
|
255
255
|
def build_definition_nodes
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
256
|
+
dirs_to_build = @types.directives
|
257
|
+
if !include_built_in_directives
|
258
|
+
dirs_to_build = dirs_to_build.reject { |directive| directive.default_directive? }
|
259
|
+
end
|
260
|
+
definitions = build_directive_nodes(dirs_to_build)
|
261
|
+
all_types = @types.all_types
|
262
|
+
type_nodes = build_type_definition_nodes(all_types + schema.extra_types)
|
263
|
+
if @include_one_of
|
264
|
+
# This may have been set to true when iterating over all types
|
265
|
+
definitions.concat(build_directive_nodes([GraphQL::Schema::Directive::OneOf]))
|
266
|
+
end
|
267
|
+
|
268
|
+
definitions.concat(type_nodes)
|
269
|
+
if include_schema_node?
|
270
|
+
definitions.unshift(build_schema_node)
|
271
|
+
end
|
272
|
+
|
260
273
|
definitions
|
261
274
|
end
|
262
275
|
|
@@ -275,15 +288,17 @@ module GraphQL
|
|
275
288
|
end
|
276
289
|
|
277
290
|
def build_field_nodes(fields)
|
278
|
-
fields
|
279
|
-
|
280
|
-
|
291
|
+
f_nodes = fields.map { |field| build_field_node(field) }
|
292
|
+
f_nodes.sort_by!(&:name)
|
293
|
+
f_nodes
|
281
294
|
end
|
282
295
|
|
283
296
|
private
|
284
297
|
|
285
298
|
def include_schema_node?
|
286
|
-
always_include_schema ||
|
299
|
+
always_include_schema ||
|
300
|
+
!schema_respects_root_name_conventions?(schema) ||
|
301
|
+
!schema.schema_directives.empty?
|
287
302
|
end
|
288
303
|
|
289
304
|
def schema_respects_root_name_conventions?(schema)
|
@@ -293,14 +308,14 @@ module GraphQL
|
|
293
308
|
end
|
294
309
|
|
295
310
|
def directives(member)
|
296
|
-
definition_directives(member)
|
311
|
+
definition_directives(member, :directives)
|
297
312
|
end
|
298
313
|
|
299
|
-
def definition_directives(member)
|
300
|
-
dirs = if !member.respond_to?(
|
301
|
-
|
314
|
+
def definition_directives(member, directives_method)
|
315
|
+
dirs = if !member.respond_to?(directives_method) || member.directives.empty?
|
316
|
+
EmptyObjects::EMPTY_ARRAY
|
302
317
|
else
|
303
|
-
member.
|
318
|
+
member.public_send(directives_method).map do |dir|
|
304
319
|
args = []
|
305
320
|
dir.arguments.argument_values.each_value do |arg_value| # rubocop:disable Development/ContextIsPassedCop -- directive instance method
|
306
321
|
arg_defn = arg_value.definition
|
@@ -314,6 +329,11 @@ module GraphQL
|
|
314
329
|
)
|
315
330
|
end
|
316
331
|
end
|
332
|
+
|
333
|
+
# If this schema uses this built-in directive definition,
|
334
|
+
# include it in the print-out since it's not part of the spec yet.
|
335
|
+
@include_one_of ||= dir.class == GraphQL::Schema::Directive::OneOf
|
336
|
+
|
317
337
|
GraphQL::Language::Nodes::Directive.new(
|
318
338
|
name: dir.class.graphql_name,
|
319
339
|
arguments: args
|
@@ -324,11 +344,7 @@ module GraphQL
|
|
324
344
|
dirs
|
325
345
|
end
|
326
346
|
|
327
|
-
|
328
|
-
member.ast_node ? member.ast_node.directives : []
|
329
|
-
end
|
330
|
-
|
331
|
-
attr_reader :schema, :warden, :always_include_schema,
|
347
|
+
attr_reader :schema, :always_include_schema,
|
332
348
|
:include_introspection_types, :include_built_in_directives, :include_built_in_scalars
|
333
349
|
end
|
334
350
|
end
|