graphql 1.9.0.pre1 → 1.9.0.pre2
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 +4 -4
- data/lib/graphql.rb +5 -1
- data/lib/graphql/analysis/ast/analyzer.rb +1 -1
- data/lib/graphql/analysis/ast/visitor.rb +6 -1
- data/lib/graphql/backwards_compatibility.rb +1 -1
- data/lib/graphql/dig.rb +19 -0
- data/lib/graphql/directive.rb +13 -1
- data/lib/graphql/directive/include_directive.rb +1 -7
- data/lib/graphql/directive/skip_directive.rb +1 -8
- data/lib/graphql/execution/interpreter.rb +23 -13
- data/lib/graphql/execution/interpreter/resolve.rb +56 -0
- data/lib/graphql/execution/interpreter/runtime.rb +174 -74
- data/lib/graphql/execution/lazy.rb +7 -1
- data/lib/graphql/execution/lookahead.rb +71 -6
- data/lib/graphql/execution_error.rb +1 -1
- data/lib/graphql/introspection/entry_points.rb +5 -1
- data/lib/graphql/introspection/type_type.rb +4 -4
- data/lib/graphql/language.rb +0 -1
- data/lib/graphql/language/block_string.rb +37 -0
- data/lib/graphql/language/document_from_schema_definition.rb +1 -1
- data/lib/graphql/language/lexer.rb +55 -36
- data/lib/graphql/language/lexer.rl +8 -3
- data/lib/graphql/language/nodes.rb +27 -4
- data/lib/graphql/language/parser.rb +55 -55
- data/lib/graphql/language/parser.y +11 -11
- data/lib/graphql/language/printer.rb +1 -1
- data/lib/graphql/language/visitor.rb +22 -13
- data/lib/graphql/literal_validation_error.rb +6 -0
- data/lib/graphql/query.rb +13 -0
- data/lib/graphql/query/arguments.rb +2 -1
- data/lib/graphql/query/context.rb +3 -10
- data/lib/graphql/query/executor.rb +1 -1
- data/lib/graphql/query/validation_pipeline.rb +1 -1
- data/lib/graphql/relay/connection_resolve.rb +1 -1
- data/lib/graphql/relay/relation_connection.rb +1 -1
- data/lib/graphql/schema.rb +81 -11
- data/lib/graphql/schema/argument.rb +1 -1
- data/lib/graphql/schema/build_from_definition.rb +2 -4
- data/lib/graphql/schema/directive.rb +103 -0
- data/lib/graphql/schema/directive/feature.rb +66 -0
- data/lib/graphql/schema/directive/include.rb +25 -0
- data/lib/graphql/schema/directive/skip.rb +25 -0
- data/lib/graphql/schema/directive/transform.rb +48 -0
- data/lib/graphql/schema/enum_value.rb +2 -2
- data/lib/graphql/schema/field.rb +63 -17
- data/lib/graphql/schema/input_object.rb +1 -0
- data/lib/graphql/schema/member/base_dsl_methods.rb +4 -2
- data/lib/graphql/schema/member/build_type.rb +33 -1
- data/lib/graphql/schema/member/has_fields.rb +8 -73
- data/lib/graphql/schema/relay_classic_mutation.rb +6 -1
- data/lib/graphql/schema/resolver.rb +1 -1
- data/lib/graphql/static_validation.rb +2 -1
- data/lib/graphql/static_validation/all_rules.rb +1 -0
- data/lib/graphql/static_validation/base_visitor.rb +25 -10
- data/lib/graphql/static_validation/definition_dependencies.rb +3 -3
- data/lib/graphql/static_validation/{message.rb → error.rb} +11 -11
- data/lib/graphql/static_validation/interpreter_visitor.rb +14 -0
- data/lib/graphql/static_validation/literal_validator.rb +54 -11
- data/lib/graphql/static_validation/rules/argument_literals_are_compatible.rb +34 -5
- data/lib/graphql/static_validation/rules/argument_literals_are_compatible_error.rb +31 -0
- data/lib/graphql/static_validation/rules/argument_names_are_unique.rb +2 -2
- data/lib/graphql/static_validation/rules/argument_names_are_unique_error.rb +30 -0
- data/lib/graphql/static_validation/rules/arguments_are_defined.rb +7 -1
- data/lib/graphql/static_validation/rules/arguments_are_defined_error.rb +35 -0
- data/lib/graphql/static_validation/rules/directives_are_defined.rb +5 -1
- data/lib/graphql/static_validation/rules/directives_are_defined_error.rb +29 -0
- data/lib/graphql/static_validation/rules/directives_are_in_valid_locations.rb +11 -2
- data/lib/graphql/static_validation/rules/directives_are_in_valid_locations_error.rb +31 -0
- data/lib/graphql/static_validation/rules/fields_are_defined_on_type.rb +11 -2
- data/lib/graphql/static_validation/rules/fields_are_defined_on_type_error.rb +32 -0
- data/lib/graphql/static_validation/rules/fields_have_appropriate_selections.rb +14 -2
- data/lib/graphql/static_validation/rules/fields_have_appropriate_selections_error.rb +31 -0
- data/lib/graphql/static_validation/rules/fields_will_merge.rb +24 -6
- data/lib/graphql/static_validation/rules/fields_will_merge_error.rb +32 -0
- data/lib/graphql/static_validation/rules/fragment_names_are_unique.rb +5 -1
- data/lib/graphql/static_validation/rules/fragment_names_are_unique_error.rb +29 -0
- data/lib/graphql/static_validation/rules/fragment_spreads_are_possible.rb +8 -1
- data/lib/graphql/static_validation/rules/fragment_spreads_are_possible_error.rb +35 -0
- data/lib/graphql/static_validation/rules/fragment_types_exist.rb +5 -1
- data/lib/graphql/static_validation/rules/fragment_types_exist_error.rb +29 -0
- data/lib/graphql/static_validation/rules/fragments_are_finite.rb +6 -1
- data/lib/graphql/static_validation/rules/fragments_are_finite_error.rb +29 -0
- data/lib/graphql/static_validation/rules/fragments_are_named.rb +4 -1
- data/lib/graphql/static_validation/rules/fragments_are_named_error.rb +26 -0
- data/lib/graphql/static_validation/rules/fragments_are_on_composite_types.rb +5 -1
- data/lib/graphql/static_validation/rules/fragments_are_on_composite_types_error.rb +30 -0
- data/lib/graphql/static_validation/rules/fragments_are_used.rb +13 -3
- data/lib/graphql/static_validation/rules/fragments_are_used_error.rb +29 -0
- data/lib/graphql/static_validation/rules/mutation_root_exists.rb +4 -1
- data/lib/graphql/static_validation/rules/mutation_root_exists_error.rb +26 -0
- data/lib/graphql/static_validation/rules/no_definitions_are_present.rb +2 -2
- data/lib/graphql/static_validation/rules/no_definitions_are_present_error.rb +25 -0
- data/lib/graphql/static_validation/rules/operation_names_are_valid.rb +9 -2
- data/lib/graphql/static_validation/rules/operation_names_are_valid_error.rb +28 -0
- data/lib/graphql/static_validation/rules/required_arguments_are_present.rb +7 -1
- data/lib/graphql/static_validation/rules/required_arguments_are_present_error.rb +35 -0
- data/lib/graphql/static_validation/rules/required_input_object_attributes_are_present.rb +47 -0
- data/lib/graphql/static_validation/rules/required_input_object_attributes_are_present_error.rb +35 -0
- data/lib/graphql/static_validation/rules/subscription_root_exists.rb +4 -1
- data/lib/graphql/static_validation/rules/subscription_root_exists_error.rb +26 -0
- data/lib/graphql/static_validation/rules/unique_directives_per_location.rb +4 -3
- data/lib/graphql/static_validation/rules/unique_directives_per_location_error.rb +29 -0
- data/lib/graphql/static_validation/rules/variable_default_values_are_correctly_typed.rb +20 -6
- data/lib/graphql/static_validation/rules/variable_default_values_are_correctly_typed_error.rb +39 -0
- data/lib/graphql/static_validation/rules/variable_names_are_unique.rb +5 -1
- data/lib/graphql/static_validation/rules/variable_names_are_unique_error.rb +29 -0
- data/lib/graphql/static_validation/rules/variable_usages_are_allowed.rb +8 -1
- data/lib/graphql/static_validation/rules/variable_usages_are_allowed_error.rb +38 -0
- data/lib/graphql/static_validation/rules/variables_are_input_types.rb +12 -2
- data/lib/graphql/static_validation/rules/variables_are_input_types_error.rb +32 -0
- data/lib/graphql/static_validation/rules/variables_are_used_and_defined.rb +18 -2
- data/lib/graphql/static_validation/rules/variables_are_used_and_defined_error.rb +37 -0
- data/lib/graphql/static_validation/validator.rb +24 -14
- data/lib/graphql/tracing/new_relic_tracing.rb +2 -2
- data/lib/graphql/tracing/skylight_tracing.rb +2 -2
- data/lib/graphql/unauthorized_field_error.rb +23 -0
- data/lib/graphql/version.rb +1 -1
- data/spec/graphql/analysis/ast_spec.rb +40 -0
- data/spec/graphql/authorization_spec.rb +93 -20
- data/spec/graphql/base_type_spec.rb +3 -1
- data/spec/graphql/execution/interpreter_spec.rb +127 -4
- data/spec/graphql/execution/lazy_spec.rb +49 -0
- data/spec/graphql/execution/lookahead_spec.rb +113 -21
- data/spec/graphql/execution/multiplex_spec.rb +2 -1
- data/spec/graphql/introspection/type_type_spec.rb +1 -1
- data/spec/graphql/language/lexer_spec.rb +72 -3
- data/spec/graphql/language/printer_spec.rb +18 -6
- data/spec/graphql/query/arguments_spec.rb +21 -0
- data/spec/graphql/query/context_spec.rb +10 -0
- data/spec/graphql/schema/build_from_definition_spec.rb +144 -29
- data/spec/graphql/schema/directive/feature_spec.rb +81 -0
- data/spec/graphql/schema/directive/transform_spec.rb +39 -0
- data/spec/graphql/schema/enum_spec.rb +5 -3
- data/spec/graphql/schema/field_extension_spec.rb +3 -3
- data/spec/graphql/schema/field_spec.rb +19 -0
- data/spec/graphql/schema/input_object_spec.rb +81 -0
- data/spec/graphql/schema/member/build_type_spec.rb +46 -0
- data/spec/graphql/schema/member/scoped_spec.rb +3 -3
- data/spec/graphql/schema/printer_spec.rb +244 -96
- data/spec/graphql/schema/relay_classic_mutation_spec.rb +26 -0
- data/spec/graphql/schema/resolver_spec.rb +1 -1
- data/spec/graphql/schema/warden_spec.rb +35 -11
- data/spec/graphql/static_validation/rules/argument_literals_are_compatible_spec.rb +212 -72
- data/spec/graphql/static_validation/rules/argument_names_are_unique_spec.rb +2 -2
- data/spec/graphql/static_validation/rules/arguments_are_defined_spec.rb +72 -29
- data/spec/graphql/static_validation/rules/directives_are_defined_spec.rb +4 -2
- data/spec/graphql/static_validation/rules/directives_are_in_valid_locations_spec.rb +4 -2
- data/spec/graphql/static_validation/rules/fields_are_defined_on_type_spec.rb +10 -5
- data/spec/graphql/static_validation/rules/fields_have_appropriate_selections_spec.rb +10 -5
- data/spec/graphql/static_validation/rules/fields_will_merge_spec.rb +2 -1
- data/spec/graphql/static_validation/rules/fragment_names_are_unique_spec.rb +2 -1
- data/spec/graphql/static_validation/rules/fragment_spreads_are_possible_spec.rb +6 -3
- data/spec/graphql/static_validation/rules/fragment_types_exist_spec.rb +4 -2
- data/spec/graphql/static_validation/rules/fragments_are_finite_spec.rb +4 -2
- data/spec/graphql/static_validation/rules/fragments_are_named_spec.rb +2 -1
- data/spec/graphql/static_validation/rules/fragments_are_on_composite_types_spec.rb +6 -3
- data/spec/graphql/static_validation/rules/fragments_are_used_spec.rb +22 -2
- data/spec/graphql/static_validation/rules/mutation_root_exists_spec.rb +2 -1
- data/spec/graphql/static_validation/rules/operation_names_are_valid_spec.rb +6 -3
- data/spec/graphql/static_validation/rules/required_arguments_are_present_spec.rb +13 -4
- data/spec/graphql/static_validation/rules/required_input_object_attributes_are_present_spec.rb +58 -0
- data/spec/graphql/static_validation/rules/subscription_root_exists_spec.rb +2 -1
- data/spec/graphql/static_validation/rules/unique_directives_per_location_spec.rb +14 -7
- data/spec/graphql/static_validation/rules/variable_default_values_are_correctly_typed_spec.rb +14 -7
- data/spec/graphql/static_validation/rules/variable_usages_are_allowed_spec.rb +8 -4
- data/spec/graphql/static_validation/rules/variables_are_input_types_spec.rb +8 -4
- data/spec/graphql/static_validation/rules/variables_are_used_and_defined_spec.rb +6 -3
- data/spec/graphql/static_validation/validator_spec.rb +6 -4
- data/spec/graphql/tracing/new_relic_tracing_spec.rb +10 -0
- data/spec/graphql/tracing/skylight_tracing_spec.rb +10 -0
- data/spec/graphql/types/iso_8601_date_time_spec.rb +1 -2
- data/spec/integration/mongoid/star_trek/schema.rb +5 -5
- data/spec/integration/rails/graphql/relay/relation_connection_spec.rb +37 -8
- data/spec/integration/rails/graphql/schema_spec.rb +2 -2
- data/spec/integration/rails/spec_helper.rb +10 -0
- data/spec/integration/tmp/app/graphql/types/bird_type.rb +7 -0
- data/spec/integration/tmp/dummy/Gemfile +45 -0
- data/spec/integration/tmp/dummy/README.rdoc +28 -0
- data/spec/integration/tmp/dummy/Rakefile +6 -0
- data/spec/integration/tmp/dummy/app/assets/javascripts/application.js +16 -0
- data/spec/integration/tmp/dummy/app/assets/stylesheets/application.css +15 -0
- data/spec/integration/tmp/dummy/app/controllers/application_controller.rb +5 -0
- data/spec/integration/tmp/dummy/app/controllers/graphql_controller.rb +43 -0
- data/spec/integration/tmp/dummy/app/graphql/dummy_schema.rb +34 -0
- data/spec/integration/tmp/dummy/app/graphql/types/base_enum.rb +4 -0
- data/spec/integration/tmp/dummy/app/graphql/types/base_input_object.rb +4 -0
- data/spec/integration/tmp/dummy/app/graphql/types/base_interface.rb +5 -0
- data/spec/integration/tmp/dummy/app/graphql/types/base_object.rb +4 -0
- data/spec/integration/tmp/dummy/app/graphql/types/base_scalar.rb +4 -0
- data/spec/integration/tmp/dummy/app/graphql/types/base_union.rb +4 -0
- data/spec/integration/tmp/dummy/app/graphql/types/mutation_type.rb +10 -0
- data/spec/integration/tmp/dummy/app/graphql/types/query_type.rb +15 -0
- data/spec/integration/tmp/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/integration/tmp/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/integration/tmp/dummy/bin/bundle +3 -0
- data/spec/integration/tmp/dummy/bin/rails +4 -0
- data/spec/integration/tmp/dummy/bin/rake +4 -0
- data/spec/integration/tmp/dummy/bin/setup +29 -0
- data/spec/integration/tmp/dummy/config.ru +4 -0
- data/spec/integration/tmp/dummy/config/application.rb +32 -0
- data/spec/integration/tmp/dummy/config/boot.rb +3 -0
- data/spec/integration/tmp/dummy/config/environment.rb +5 -0
- data/spec/integration/tmp/dummy/config/environments/development.rb +38 -0
- data/spec/integration/tmp/dummy/config/environments/production.rb +76 -0
- data/spec/integration/tmp/dummy/config/environments/test.rb +42 -0
- data/spec/integration/tmp/dummy/config/initializers/assets.rb +11 -0
- data/spec/integration/tmp/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/integration/tmp/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/spec/integration/tmp/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/integration/tmp/dummy/config/initializers/inflections.rb +16 -0
- data/spec/integration/tmp/dummy/config/initializers/mime_types.rb +4 -0
- data/spec/integration/tmp/dummy/config/initializers/session_store.rb +3 -0
- data/spec/integration/tmp/dummy/config/initializers/to_time_preserves_timezone.rb +10 -0
- data/spec/integration/tmp/dummy/config/initializers/wrap_parameters.rb +9 -0
- data/spec/integration/tmp/dummy/config/locales/en.yml +23 -0
- data/spec/integration/tmp/dummy/config/routes.rb +61 -0
- data/spec/integration/tmp/dummy/config/secrets.yml +22 -0
- data/spec/integration/tmp/dummy/db/seeds.rb +7 -0
- data/spec/integration/tmp/dummy/public/404.html +67 -0
- data/spec/integration/tmp/dummy/public/422.html +67 -0
- data/spec/integration/tmp/dummy/public/500.html +66 -0
- data/spec/integration/tmp/dummy/public/favicon.ico +0 -0
- data/spec/integration/tmp/dummy/public/robots.txt +5 -0
- data/spec/support/dummy/schema.rb +2 -2
- data/spec/support/error_bubbling_helpers.rb +23 -0
- data/spec/support/jazz.rb +53 -6
- data/spec/support/lazy_helpers.rb +26 -8
- data/spec/support/new_relic.rb +3 -0
- data/spec/support/skylight.rb +3 -0
- data/spec/support/star_wars/schema.rb +13 -9
- data/spec/support/static_validation_helpers.rb +3 -1
- metadata +145 -22
- data/lib/graphql/language/comments.rb +0 -45
- data/spec/graphql/schema/member/has_fields_spec.rb +0 -132
- data/spec/integration/tmp/app/graphql/types/family_type.rb +0 -9
@@ -123,6 +123,13 @@ describe GraphQL::Schema::InputObject do
|
|
123
123
|
end
|
124
124
|
end
|
125
125
|
|
126
|
+
describe "when used with default_value" do
|
127
|
+
it "comes as an instance" do
|
128
|
+
res = Jazz::Schema.execute("{ defaultValueTest }")
|
129
|
+
assert_equal "Jazz::InspectableInput -> {:string_value=>\"S\"}", res["data"]["defaultValueTest"]
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
126
133
|
describe "#to_h" do
|
127
134
|
module InputObjectToHTest
|
128
135
|
class TestInput1 < GraphQL::Schema::InputObject
|
@@ -154,4 +161,78 @@ describe GraphQL::Schema::InputObject do
|
|
154
161
|
assert_equal({ a: 1, b: 2, input_object: { d: 3, e: 4 } }, input_object.to_h)
|
155
162
|
end
|
156
163
|
end
|
164
|
+
|
165
|
+
describe "#dig" do
|
166
|
+
module InputObjectDigTest
|
167
|
+
class TestInput1 < GraphQL::Schema::InputObject
|
168
|
+
graphql_name "TestInput1"
|
169
|
+
argument :d, Int, required: true
|
170
|
+
argument :e, Int, required: true
|
171
|
+
end
|
172
|
+
|
173
|
+
class TestInput2 < GraphQL::Schema::InputObject
|
174
|
+
graphql_name "TestInput2"
|
175
|
+
argument :a, Int, required: true
|
176
|
+
argument :b, Int, required: true
|
177
|
+
argument :c, TestInput1, as: :inputObject, required: true
|
178
|
+
end
|
179
|
+
|
180
|
+
TestInput1.to_graphql
|
181
|
+
TestInput2.to_graphql
|
182
|
+
end
|
183
|
+
arg_values = {a: 1, b: 2, c: { d: 3, e: 4 }}
|
184
|
+
|
185
|
+
input_object = InputObjectDigTest::TestInput2.new(
|
186
|
+
arg_values,
|
187
|
+
context: nil,
|
188
|
+
defaults_used: Set.new
|
189
|
+
)
|
190
|
+
it "returns the value at that key" do
|
191
|
+
assert_equal 1, input_object.dig("a")
|
192
|
+
assert_equal 1, input_object.dig(:a)
|
193
|
+
assert input_object.dig("inputObject").is_a?(GraphQL::Schema::InputObject)
|
194
|
+
end
|
195
|
+
|
196
|
+
it "works with nested keys" do
|
197
|
+
assert_equal 3, input_object.dig("inputObject", "d")
|
198
|
+
assert_equal 3, input_object.dig(:inputObject, :d)
|
199
|
+
assert_equal 3, input_object.dig("inputObject", :d)
|
200
|
+
assert_equal 3, input_object.dig(:inputObject, "d")
|
201
|
+
end
|
202
|
+
|
203
|
+
it "returns nil for missing keys" do
|
204
|
+
assert_nil input_object.dig("z")
|
205
|
+
assert_nil input_object.dig(7)
|
206
|
+
end
|
207
|
+
|
208
|
+
it "handles underscored keys" do
|
209
|
+
# TODO - shouldn't this work too?
|
210
|
+
# assert_equal 3, input_object.dig('input_object', 'd')
|
211
|
+
assert_equal 3, input_object.dig(:input_object, :d)
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
describe "introspection" do
|
216
|
+
it "returns input fields" do
|
217
|
+
res = Jazz::Schema.execute('
|
218
|
+
{
|
219
|
+
__type(name: "InspectableInput") {
|
220
|
+
name
|
221
|
+
inputFields { name }
|
222
|
+
}
|
223
|
+
__schema {
|
224
|
+
types {
|
225
|
+
name
|
226
|
+
inputFields { name }
|
227
|
+
}
|
228
|
+
}
|
229
|
+
}')
|
230
|
+
# Test __type
|
231
|
+
assert_equal ["stringValue", "nestedInput", "legacyInput"], res["data"]["__type"]["inputFields"].map { |f| f["name"] }
|
232
|
+
# Test __schema { types }
|
233
|
+
# It's upcased to test custom introspection
|
234
|
+
input_type = res["data"]["__schema"]["types"].find { |t| t["name"] == "INSPECTABLEINPUT" }
|
235
|
+
assert_equal ["stringValue", "nestedInput", "legacyInput"], input_type["inputFields"].map { |f| f["name"] }
|
236
|
+
end
|
237
|
+
end
|
157
238
|
end
|
@@ -2,6 +2,52 @@
|
|
2
2
|
require "spec_helper"
|
3
3
|
|
4
4
|
describe GraphQL::Schema::Member::BuildType do
|
5
|
+
describe ".parse_type" do
|
6
|
+
it "resolves a string type from a string" do
|
7
|
+
assert_equal GraphQL::Types::String, GraphQL::Schema::Member::BuildType.parse_type("String", null: true)
|
8
|
+
end
|
9
|
+
|
10
|
+
it "resolves an integer type from a string" do
|
11
|
+
assert_equal GraphQL::Types::Int, GraphQL::Schema::Member::BuildType.parse_type("Integer", null: true)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "resolves a float type from a string" do
|
15
|
+
assert_equal GraphQL::Types::Float, GraphQL::Schema::Member::BuildType.parse_type("Float", null: true)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "resolves a boolean type from a string" do
|
19
|
+
assert_equal GraphQL::Types::Boolean, GraphQL::Schema::Member::BuildType.parse_type("Boolean", null: true)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "resolves an interface type from a string" do
|
23
|
+
assert_equal Jazz::BaseInterface, GraphQL::Schema::Member::BuildType.parse_type("Jazz::BaseInterface", null: true)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "resolves an object type from a class" do
|
27
|
+
assert_equal Jazz::BaseObject, GraphQL::Schema::Member::BuildType.parse_type(Jazz::BaseObject, null: true)
|
28
|
+
end
|
29
|
+
|
30
|
+
it "resolves an object type from a string" do
|
31
|
+
assert_equal Jazz::BaseObject, GraphQL::Schema::Member::BuildType.parse_type("Jazz::BaseObject", null: true)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "resolves a nested object type from a string" do
|
35
|
+
assert_equal Jazz::Introspection::NestedType, GraphQL::Schema::Member::BuildType.parse_type("Jazz::Introspection::NestedType", null: true)
|
36
|
+
end
|
37
|
+
|
38
|
+
it "resolves a deeply nested object type from a string" do
|
39
|
+
assert_equal Jazz::Introspection::NestedType::DeeplyNestedType, GraphQL::Schema::Member::BuildType.parse_type("Jazz::Introspection::NestedType::DeeplyNestedType", null: true)
|
40
|
+
end
|
41
|
+
|
42
|
+
it "resolves a list type from an array of classes" do
|
43
|
+
assert_instance_of GraphQL::Schema::List, GraphQL::Schema::Member::BuildType.parse_type([Jazz::BaseObject], null: true)
|
44
|
+
end
|
45
|
+
|
46
|
+
it "resolves a list type from an array of strings" do
|
47
|
+
assert_instance_of GraphQL::Schema::List, GraphQL::Schema::Member::BuildType.parse_type(["Jazz::BaseObject"], null: true)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
5
51
|
describe ".to_type_name" do
|
6
52
|
it "works with lists and non-nulls" do
|
7
53
|
t = Class.new(GraphQL::Schema::Object) do
|
@@ -54,11 +54,11 @@ describe GraphQL::Schema::Member::Scoped do
|
|
54
54
|
field :items, [Item], null: false
|
55
55
|
field :unscoped_items, [Item], null: false,
|
56
56
|
scope: false,
|
57
|
-
|
57
|
+
resolver_method: :items
|
58
58
|
field :french_items, [FrenchItem], null: false,
|
59
|
-
|
59
|
+
resolver_method: :items
|
60
60
|
field :items_connection, Item.connection_type, null: false,
|
61
|
-
|
61
|
+
resolver_method: :items
|
62
62
|
|
63
63
|
def items
|
64
64
|
[
|
@@ -140,32 +140,46 @@ schema {
|
|
140
140
|
query: Root
|
141
141
|
}
|
142
142
|
|
143
|
-
|
143
|
+
"""
|
144
|
+
Marks an element of a GraphQL schema as no longer supported.
|
145
|
+
"""
|
144
146
|
directive @deprecated(
|
145
|
-
|
146
|
-
|
147
|
-
|
147
|
+
"""
|
148
|
+
Explains why this element was deprecated, usually also including a suggestion
|
149
|
+
for how to access supported similar data. Formatted in
|
150
|
+
[Markdown](https://daringfireball.net/projects/markdown/).
|
151
|
+
"""
|
148
152
|
reason: String = "No longer supported"
|
149
153
|
) on FIELD_DEFINITION | ENUM_VALUE
|
150
154
|
|
151
|
-
|
155
|
+
"""
|
156
|
+
Directs the executor to include this field or fragment only when the `if` argument is true.
|
157
|
+
"""
|
152
158
|
directive @include(
|
153
|
-
|
159
|
+
"""
|
160
|
+
Included when true.
|
161
|
+
"""
|
154
162
|
if: Boolean!
|
155
163
|
) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT
|
156
164
|
|
157
|
-
|
165
|
+
"""
|
166
|
+
Directs the executor to skip this field or fragment when the `if` argument is true.
|
167
|
+
"""
|
158
168
|
directive @skip(
|
159
|
-
|
169
|
+
"""
|
170
|
+
Skipped when true.
|
171
|
+
"""
|
160
172
|
if: Boolean!
|
161
173
|
) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT
|
162
174
|
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
175
|
+
"""
|
176
|
+
A Directive provides a way to describe alternate runtime execution and type validation behavior in a GraphQL document.
|
177
|
+
|
178
|
+
In some cases, you need to provide options to alter GraphQL's execution behavior
|
179
|
+
in ways field arguments will not suffice, such as conditionally including or
|
180
|
+
skipping a field. Directives provide this by describing additional information
|
181
|
+
to the executor.
|
182
|
+
"""
|
169
183
|
type __Directive {
|
170
184
|
args: [__InputValue!]!
|
171
185
|
description: String
|
@@ -176,67 +190,107 @@ type __Directive {
|
|
176
190
|
onOperation: Boolean! @deprecated(reason: "Use `locations`.")
|
177
191
|
}
|
178
192
|
|
179
|
-
|
180
|
-
|
193
|
+
"""
|
194
|
+
A Directive can be adjacent to many parts of the GraphQL language, a
|
195
|
+
__DirectiveLocation describes one such possible adjacencies.
|
196
|
+
"""
|
181
197
|
enum __DirectiveLocation {
|
182
|
-
|
198
|
+
"""
|
199
|
+
Location adjacent to an argument definition.
|
200
|
+
"""
|
183
201
|
ARGUMENT_DEFINITION
|
184
202
|
|
185
|
-
|
203
|
+
"""
|
204
|
+
Location adjacent to an enum definition.
|
205
|
+
"""
|
186
206
|
ENUM
|
187
207
|
|
188
|
-
|
208
|
+
"""
|
209
|
+
Location adjacent to an enum value definition.
|
210
|
+
"""
|
189
211
|
ENUM_VALUE
|
190
212
|
|
191
|
-
|
213
|
+
"""
|
214
|
+
Location adjacent to a field.
|
215
|
+
"""
|
192
216
|
FIELD
|
193
217
|
|
194
|
-
|
218
|
+
"""
|
219
|
+
Location adjacent to a field definition.
|
220
|
+
"""
|
195
221
|
FIELD_DEFINITION
|
196
222
|
|
197
|
-
|
223
|
+
"""
|
224
|
+
Location adjacent to a fragment definition.
|
225
|
+
"""
|
198
226
|
FRAGMENT_DEFINITION
|
199
227
|
|
200
|
-
|
228
|
+
"""
|
229
|
+
Location adjacent to a fragment spread.
|
230
|
+
"""
|
201
231
|
FRAGMENT_SPREAD
|
202
232
|
|
203
|
-
|
233
|
+
"""
|
234
|
+
Location adjacent to an inline fragment.
|
235
|
+
"""
|
204
236
|
INLINE_FRAGMENT
|
205
237
|
|
206
|
-
|
238
|
+
"""
|
239
|
+
Location adjacent to an input object field definition.
|
240
|
+
"""
|
207
241
|
INPUT_FIELD_DEFINITION
|
208
242
|
|
209
|
-
|
243
|
+
"""
|
244
|
+
Location adjacent to an input object type definition.
|
245
|
+
"""
|
210
246
|
INPUT_OBJECT
|
211
247
|
|
212
|
-
|
248
|
+
"""
|
249
|
+
Location adjacent to an interface definition.
|
250
|
+
"""
|
213
251
|
INTERFACE
|
214
252
|
|
215
|
-
|
253
|
+
"""
|
254
|
+
Location adjacent to a mutation operation.
|
255
|
+
"""
|
216
256
|
MUTATION
|
217
257
|
|
218
|
-
|
258
|
+
"""
|
259
|
+
Location adjacent to an object type definition.
|
260
|
+
"""
|
219
261
|
OBJECT
|
220
262
|
|
221
|
-
|
263
|
+
"""
|
264
|
+
Location adjacent to a query operation.
|
265
|
+
"""
|
222
266
|
QUERY
|
223
267
|
|
224
|
-
|
268
|
+
"""
|
269
|
+
Location adjacent to a scalar definition.
|
270
|
+
"""
|
225
271
|
SCALAR
|
226
272
|
|
227
|
-
|
273
|
+
"""
|
274
|
+
Location adjacent to a schema definition.
|
275
|
+
"""
|
228
276
|
SCHEMA
|
229
277
|
|
230
|
-
|
278
|
+
"""
|
279
|
+
Location adjacent to a subscription operation.
|
280
|
+
"""
|
231
281
|
SUBSCRIPTION
|
232
282
|
|
233
|
-
|
283
|
+
"""
|
284
|
+
Location adjacent to a union definition.
|
285
|
+
"""
|
234
286
|
UNION
|
235
287
|
}
|
236
288
|
|
237
|
-
|
238
|
-
|
239
|
-
|
289
|
+
"""
|
290
|
+
One possible value for a given Enum. Enum values are unique values, not a
|
291
|
+
placeholder for a string or numeric value. However an Enum value is returned in
|
292
|
+
a JSON response as a string.
|
293
|
+
"""
|
240
294
|
type __EnumValue {
|
241
295
|
deprecationReason: String
|
242
296
|
description: String
|
@@ -244,8 +298,10 @@ type __EnumValue {
|
|
244
298
|
name: String!
|
245
299
|
}
|
246
300
|
|
247
|
-
|
248
|
-
|
301
|
+
"""
|
302
|
+
Object and Interface types are described by a list of Fields, each of which has
|
303
|
+
a name, potentially a list of arguments, and a return type.
|
304
|
+
"""
|
249
305
|
type __Field {
|
250
306
|
args: [__InputValue!]!
|
251
307
|
deprecationReason: String
|
@@ -255,45 +311,63 @@ type __Field {
|
|
255
311
|
type: __Type!
|
256
312
|
}
|
257
313
|
|
258
|
-
|
259
|
-
|
260
|
-
|
314
|
+
"""
|
315
|
+
Arguments provided to Fields or Directives and the input fields of an
|
316
|
+
InputObject are represented as Input Values which describe their type and
|
317
|
+
optionally a default value.
|
318
|
+
"""
|
261
319
|
type __InputValue {
|
262
|
-
|
320
|
+
"""
|
321
|
+
A GraphQL-formatted string representing the default value for this input value.
|
322
|
+
"""
|
263
323
|
defaultValue: String
|
264
324
|
description: String
|
265
325
|
name: String!
|
266
326
|
type: __Type!
|
267
327
|
}
|
268
328
|
|
269
|
-
|
270
|
-
|
271
|
-
|
329
|
+
"""
|
330
|
+
A GraphQL Schema defines the capabilities of a GraphQL server. It exposes all
|
331
|
+
available types and directives on the server, as well as the entry points for
|
332
|
+
query, mutation, and subscription operations.
|
333
|
+
"""
|
272
334
|
type __Schema {
|
273
|
-
|
335
|
+
"""
|
336
|
+
A list of all directives supported by this server.
|
337
|
+
"""
|
274
338
|
directives: [__Directive!]!
|
275
339
|
|
276
|
-
|
340
|
+
"""
|
341
|
+
If this server supports mutation, the type that mutation operations will be rooted at.
|
342
|
+
"""
|
277
343
|
mutationType: __Type
|
278
344
|
|
279
|
-
|
345
|
+
"""
|
346
|
+
The type that query operations will be rooted at.
|
347
|
+
"""
|
280
348
|
queryType: __Type!
|
281
349
|
|
282
|
-
|
350
|
+
"""
|
351
|
+
If this server support subscription, the type that subscription operations will be rooted at.
|
352
|
+
"""
|
283
353
|
subscriptionType: __Type
|
284
354
|
|
285
|
-
|
355
|
+
"""
|
356
|
+
A list of all types supported by this server.
|
357
|
+
"""
|
286
358
|
types: [__Type!]!
|
287
359
|
}
|
288
360
|
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
361
|
+
"""
|
362
|
+
The fundamental unit of any GraphQL Schema is the type. There are many kinds of
|
363
|
+
types in GraphQL as represented by the `__TypeKind` enum.
|
364
|
+
|
365
|
+
Depending on the kind of a type, certain fields describe information about that
|
366
|
+
type. Scalar types provide no information beyond a name and description, while
|
367
|
+
Enum types provide their values. Object and Interface types provide the fields
|
368
|
+
they describe. Abstract types, Union and Interface, provide the Object types
|
369
|
+
possible at runtime. List and NonNull types compose other types.
|
370
|
+
"""
|
297
371
|
type __Type {
|
298
372
|
description: String
|
299
373
|
enumValues(includeDeprecated: Boolean = false): [__EnumValue!]
|
@@ -306,30 +380,48 @@ type __Type {
|
|
306
380
|
possibleTypes: [__Type!]
|
307
381
|
}
|
308
382
|
|
309
|
-
|
383
|
+
"""
|
384
|
+
An enum describing what kind of type a given `__Type` is.
|
385
|
+
"""
|
310
386
|
enum __TypeKind {
|
311
|
-
|
387
|
+
"""
|
388
|
+
Indicates this type is an enum. `enumValues` is a valid field.
|
389
|
+
"""
|
312
390
|
ENUM
|
313
391
|
|
314
|
-
|
392
|
+
"""
|
393
|
+
Indicates this type is an input object. `inputFields` is a valid field.
|
394
|
+
"""
|
315
395
|
INPUT_OBJECT
|
316
396
|
|
317
|
-
|
397
|
+
"""
|
398
|
+
Indicates this type is an interface. `fields` and `possibleTypes` are valid fields.
|
399
|
+
"""
|
318
400
|
INTERFACE
|
319
401
|
|
320
|
-
|
402
|
+
"""
|
403
|
+
Indicates this type is a list. `ofType` is a valid field.
|
404
|
+
"""
|
321
405
|
LIST
|
322
406
|
|
323
|
-
|
407
|
+
"""
|
408
|
+
Indicates this type is a non-null. `ofType` is a valid field.
|
409
|
+
"""
|
324
410
|
NON_NULL
|
325
411
|
|
326
|
-
|
412
|
+
"""
|
413
|
+
Indicates this type is an object. `fields` and `interfaces` are valid fields.
|
414
|
+
"""
|
327
415
|
OBJECT
|
328
416
|
|
329
|
-
|
417
|
+
"""
|
418
|
+
Indicates this type is a scalar.
|
419
|
+
"""
|
330
420
|
SCALAR
|
331
421
|
|
332
|
-
|
422
|
+
"""
|
423
|
+
Indicates this type is a union. `possibleTypes` is a valid field.
|
424
|
+
"""
|
333
425
|
UNION
|
334
426
|
}
|
335
427
|
SCHEMA
|
@@ -397,23 +489,33 @@ enum Choice {
|
|
397
489
|
WOZ @deprecated
|
398
490
|
}
|
399
491
|
|
400
|
-
|
492
|
+
"""
|
493
|
+
A blog comment
|
494
|
+
"""
|
401
495
|
type Comment implements Node {
|
402
496
|
id: ID!
|
403
497
|
}
|
404
498
|
|
405
|
-
|
499
|
+
"""
|
500
|
+
Autogenerated input type of CreatePost
|
501
|
+
"""
|
406
502
|
input CreatePostInput {
|
407
503
|
body: String!
|
408
504
|
|
409
|
-
|
505
|
+
"""
|
506
|
+
A unique identifier for the client performing the mutation.
|
507
|
+
"""
|
410
508
|
clientMutationId: String
|
411
509
|
title: String!
|
412
510
|
}
|
413
511
|
|
414
|
-
|
512
|
+
"""
|
513
|
+
Autogenerated return type of CreatePost
|
514
|
+
"""
|
415
515
|
type CreatePostPayload {
|
416
|
-
|
516
|
+
"""
|
517
|
+
A unique identifier for the client performing the mutation.
|
518
|
+
"""
|
417
519
|
clientMutationId: String
|
418
520
|
post: Post
|
419
521
|
}
|
@@ -425,11 +527,15 @@ type Image {
|
|
425
527
|
width: Int!
|
426
528
|
}
|
427
529
|
|
428
|
-
|
530
|
+
"""
|
531
|
+
Media objects
|
532
|
+
"""
|
429
533
|
union Media = Audio | Image
|
430
534
|
|
431
535
|
type Mutation {
|
432
|
-
|
536
|
+
"""
|
537
|
+
Create a blog post
|
538
|
+
"""
|
433
539
|
createPost(input: CreatePostInput!): CreatePostPayload
|
434
540
|
}
|
435
541
|
|
@@ -437,7 +543,9 @@ interface Node {
|
|
437
543
|
id: ID!
|
438
544
|
}
|
439
545
|
|
440
|
-
|
546
|
+
"""
|
547
|
+
A blog post
|
548
|
+
"""
|
441
549
|
type Post {
|
442
550
|
body: String!
|
443
551
|
comments: [Comment!]
|
@@ -446,22 +554,32 @@ type Post {
|
|
446
554
|
title: String!
|
447
555
|
}
|
448
556
|
|
449
|
-
|
557
|
+
"""
|
558
|
+
The query root of this schema
|
559
|
+
"""
|
450
560
|
type Query {
|
451
561
|
post(
|
452
|
-
|
562
|
+
"""
|
563
|
+
Post ID
|
564
|
+
"""
|
453
565
|
id: ID!
|
454
566
|
varied: Varied = {id: "123", int: 234, float: 2.3, enum: FOO, sub: [{string: "str"}]}
|
455
567
|
variedWithNulls: Varied = {id: null, int: null, float: null, enum: null, sub: null}
|
456
568
|
): Post
|
457
569
|
}
|
458
570
|
|
459
|
-
|
571
|
+
"""
|
572
|
+
Test
|
573
|
+
"""
|
460
574
|
input Sub {
|
461
|
-
|
575
|
+
"""
|
576
|
+
Something
|
577
|
+
"""
|
462
578
|
int: Int
|
463
579
|
|
464
|
-
|
580
|
+
"""
|
581
|
+
Something
|
582
|
+
"""
|
465
583
|
string: String
|
466
584
|
}
|
467
585
|
|
@@ -553,32 +671,46 @@ enum Choice {
|
|
553
671
|
FOO
|
554
672
|
}
|
555
673
|
|
556
|
-
|
674
|
+
"""
|
675
|
+
A blog comment
|
676
|
+
"""
|
557
677
|
type Comment implements Node {
|
558
678
|
id: ID!
|
559
679
|
}
|
560
680
|
|
561
|
-
|
681
|
+
"""
|
682
|
+
Autogenerated input type of CreatePost
|
683
|
+
"""
|
562
684
|
input CreatePostInput {
|
563
685
|
body: String!
|
564
686
|
|
565
|
-
|
687
|
+
"""
|
688
|
+
A unique identifier for the client performing the mutation.
|
689
|
+
"""
|
566
690
|
clientMutationId: String
|
567
691
|
title: String!
|
568
692
|
}
|
569
693
|
|
570
|
-
|
694
|
+
"""
|
695
|
+
Autogenerated return type of CreatePost
|
696
|
+
"""
|
571
697
|
type CreatePostPayload {
|
572
|
-
|
698
|
+
"""
|
699
|
+
A unique identifier for the client performing the mutation.
|
700
|
+
"""
|
573
701
|
clientMutationId: String
|
574
702
|
post: Post
|
575
703
|
}
|
576
704
|
|
577
|
-
|
705
|
+
"""
|
706
|
+
Media objects
|
707
|
+
"""
|
578
708
|
union Media = Audio
|
579
709
|
|
580
710
|
type Mutation {
|
581
|
-
|
711
|
+
"""
|
712
|
+
Create a blog post
|
713
|
+
"""
|
582
714
|
createPost(input: CreatePostInput!): CreatePostPayload
|
583
715
|
}
|
584
716
|
|
@@ -586,7 +718,9 @@ interface Node {
|
|
586
718
|
id: ID!
|
587
719
|
}
|
588
720
|
|
589
|
-
|
721
|
+
"""
|
722
|
+
A blog post
|
723
|
+
"""
|
590
724
|
type Post {
|
591
725
|
body: String!
|
592
726
|
comments: [Comment!]
|
@@ -594,10 +728,14 @@ type Post {
|
|
594
728
|
title: String!
|
595
729
|
}
|
596
730
|
|
597
|
-
|
731
|
+
"""
|
732
|
+
The query root of this schema
|
733
|
+
"""
|
598
734
|
type Query {
|
599
735
|
post(
|
600
|
-
|
736
|
+
"""
|
737
|
+
Post ID
|
738
|
+
"""
|
601
739
|
id: ID!
|
602
740
|
): Post
|
603
741
|
}
|
@@ -618,7 +756,9 @@ SCHEMA
|
|
618
756
|
describe "#print_type" do
|
619
757
|
it "returns the type schema as a string" do
|
620
758
|
expected = <<SCHEMA
|
621
|
-
|
759
|
+
"""
|
760
|
+
A blog post
|
761
|
+
"""
|
622
762
|
type Post {
|
623
763
|
body: String!
|
624
764
|
comments: [Comment!]
|
@@ -632,12 +772,18 @@ SCHEMA
|
|
632
772
|
|
633
773
|
it "can print non-object types" do
|
634
774
|
expected = <<SCHEMA
|
635
|
-
|
775
|
+
"""
|
776
|
+
Test
|
777
|
+
"""
|
636
778
|
input Sub {
|
637
|
-
|
779
|
+
"""
|
780
|
+
Something
|
781
|
+
"""
|
638
782
|
int: Int
|
639
783
|
|
640
|
-
|
784
|
+
"""
|
785
|
+
Something
|
786
|
+
"""
|
641
787
|
string: String
|
642
788
|
}
|
643
789
|
SCHEMA
|
@@ -669,7 +815,9 @@ SCHEMA
|
|
669
815
|
end
|
670
816
|
|
671
817
|
expected = <<SCHEMA
|
672
|
-
|
818
|
+
"""
|
819
|
+
The query root of this schema
|
820
|
+
"""
|
673
821
|
type Query {
|
674
822
|
example(input: SomeType = "Howdy"): SomeType
|
675
823
|
}
|