rails-graphql 0.2.0 → 1.0.0.beta
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/console.rb +18 -0
- data/ext/extconf.h +3 -0
- data/ext/extconf.rb +1 -54
- data/ext/gql_parser.c +646 -0
- data/ext/shared.c +482 -0
- data/ext/shared.h +177 -0
- data/lib/gql_parser.so +0 -0
- data/lib/rails/graphql/adapters/mysql_adapter.rb +59 -0
- data/lib/rails/graphql/adapters/pg_adapter.rb +25 -22
- data/lib/rails/graphql/adapters/sqlite_adapter.rb +17 -14
- data/lib/rails/graphql/alternative/field_set.rb +36 -0
- data/lib/rails/graphql/alternative/mutation.rb +17 -0
- data/lib/rails/graphql/alternative/query.rb +93 -0
- data/lib/rails/graphql/alternative/subscription.rb +17 -0
- data/lib/rails/graphql/alternative.rb +20 -0
- data/lib/rails/graphql/argument.rb +21 -24
- data/lib/rails/graphql/callback.rb +24 -9
- data/lib/rails/graphql/collectors/hash_collector.rb +14 -6
- data/lib/rails/graphql/collectors/idented_collector.rb +10 -7
- data/lib/rails/graphql/collectors/json_collector.rb +22 -17
- data/lib/rails/graphql/collectors.rb +4 -4
- data/lib/rails/graphql/config.rb +130 -15
- data/lib/rails/graphql/directive/cached_directive.rb +33 -0
- data/lib/rails/graphql/directive/deprecated_directive.rb +10 -10
- data/lib/rails/graphql/directive/include_directive.rb +5 -4
- data/lib/rails/graphql/directive/skip_directive.rb +5 -4
- data/lib/rails/graphql/directive.rb +118 -63
- data/lib/rails/graphql/errors.rb +33 -4
- data/lib/rails/graphql/event.rb +16 -5
- data/lib/rails/graphql/field/authorized_field.rb +19 -3
- data/lib/rails/graphql/field/input_field.rb +11 -10
- data/lib/rails/graphql/field/mutation_field.rb +42 -7
- data/lib/rails/graphql/field/output_field.rb +102 -13
- data/lib/rails/graphql/field/proxied_field.rb +31 -22
- data/lib/rails/graphql/field/resolved_field.rb +26 -24
- data/lib/rails/graphql/field/scoped_config.rb +10 -4
- data/lib/rails/graphql/field/subscription_field.rb +140 -0
- data/lib/rails/graphql/field/typed_field.rb +43 -22
- data/lib/rails/graphql/field.rb +70 -56
- data/lib/rails/graphql/global_id.rb +85 -0
- data/lib/rails/graphql/helpers/attribute_delegator.rb +5 -5
- data/lib/rails/graphql/helpers/inherited_collection/array.rb +50 -0
- data/lib/rails/graphql/helpers/inherited_collection/base.rb +43 -0
- data/lib/rails/graphql/helpers/inherited_collection/hash.rb +87 -0
- data/lib/rails/graphql/helpers/inherited_collection.rb +25 -76
- data/lib/rails/graphql/helpers/instantiable.rb +15 -0
- data/lib/rails/graphql/helpers/leaf_from_ar.rb +7 -7
- data/lib/rails/graphql/helpers/registerable.rb +44 -62
- data/lib/rails/graphql/helpers/unregisterable.rb +16 -0
- data/lib/rails/graphql/helpers/with_arguments.rb +31 -27
- data/lib/rails/graphql/helpers/with_assignment.rb +10 -8
- data/lib/rails/graphql/helpers/with_callbacks.rb +25 -8
- data/lib/rails/graphql/helpers/with_description.rb +71 -0
- data/lib/rails/graphql/helpers/with_directives.rb +54 -30
- data/lib/rails/graphql/helpers/with_events.rb +21 -23
- data/lib/rails/graphql/helpers/with_fields.rb +76 -22
- data/lib/rails/graphql/helpers/with_global_id.rb +22 -0
- data/lib/rails/graphql/helpers/with_name.rb +43 -0
- data/lib/rails/graphql/helpers/with_namespace.rb +7 -4
- data/lib/rails/graphql/helpers/with_owner.rb +8 -7
- data/lib/rails/graphql/helpers/with_schema_fields.rb +137 -55
- data/lib/rails/graphql/helpers/with_validator.rb +9 -9
- data/lib/rails/graphql/helpers.rb +10 -3
- data/lib/rails/graphql/introspection.rb +43 -36
- data/lib/rails/graphql/railtie.rb +88 -33
- data/lib/rails/graphql/railties/base_generator.rb +3 -9
- data/lib/rails/graphql/railties/channel.rb +157 -0
- data/lib/rails/graphql/railties/controller.rb +62 -17
- data/lib/rails/graphql/railties/controller_runtime.rb +5 -5
- data/lib/rails/graphql/railties/log_subscriber.rb +81 -14
- data/lib/rails/graphql/request/arguments.rb +24 -49
- data/lib/rails/graphql/request/backtrace.rb +191 -0
- data/lib/rails/graphql/request/component/field.rb +86 -65
- data/lib/rails/graphql/request/component/fragment.rb +72 -24
- data/lib/rails/graphql/request/component/operation/subscription.rb +164 -4
- data/lib/rails/graphql/request/component/operation.rb +63 -31
- data/lib/rails/graphql/request/component/spread.rb +68 -25
- data/lib/rails/graphql/request/component/typename.rb +27 -12
- data/lib/rails/graphql/request/component.rb +75 -36
- data/lib/rails/graphql/request/context.rb +18 -8
- data/lib/rails/graphql/request/errors.rb +16 -6
- data/lib/rails/graphql/request/event.rb +19 -8
- data/lib/rails/graphql/request/helpers/directives.rb +68 -27
- data/lib/rails/graphql/request/helpers/selection_set.rb +51 -25
- data/lib/rails/graphql/request/helpers/value_writers.rb +18 -16
- data/lib/rails/graphql/request/prepared_data.rb +98 -0
- data/lib/rails/graphql/request/steps/authorizable.rb +24 -14
- data/lib/rails/graphql/request/steps/organizable.rb +110 -48
- data/lib/rails/graphql/request/steps/{prepareable.rb → preparable.rb} +20 -7
- data/lib/rails/graphql/request/steps/{resolveable.rb → resolvable.rb} +15 -6
- data/lib/rails/graphql/request/strategy/cached_strategy.rb +64 -0
- data/lib/rails/graphql/request/strategy/dynamic_instance.rb +6 -6
- data/lib/rails/graphql/request/strategy/multi_query_strategy.rb +6 -13
- data/lib/rails/graphql/request/strategy/sequenced_strategy.rb +9 -9
- data/lib/rails/graphql/request/strategy.rb +131 -75
- data/lib/rails/graphql/request/subscription.rb +80 -0
- data/lib/rails/graphql/request.rb +305 -86
- data/lib/rails/graphql/schema.rb +240 -48
- data/lib/rails/graphql/shortcuts.rb +22 -3
- data/lib/rails/graphql/source/active_record/builders.rb +50 -36
- data/lib/rails/graphql/source/active_record_source.rb +70 -54
- data/lib/rails/graphql/source/base.rb +111 -0
- data/lib/rails/graphql/source/builder.rb +128 -0
- data/lib/rails/graphql/source/scoped_arguments.rb +31 -19
- data/lib/rails/graphql/source.rb +89 -213
- data/lib/rails/graphql/subscription/provider/action_cable.rb +112 -0
- data/lib/rails/graphql/subscription/provider/base.rb +191 -0
- data/lib/rails/graphql/subscription/provider.rb +18 -0
- data/lib/rails/graphql/subscription/store/base.rb +145 -0
- data/lib/rails/graphql/subscription/store/memory.rb +127 -0
- data/lib/rails/graphql/subscription/store.rb +19 -0
- data/lib/rails/graphql/subscription.rb +17 -0
- data/lib/rails/graphql/to_gql.rb +29 -32
- data/lib/rails/graphql/type/enum/directive_location_enum.rb +11 -11
- data/lib/rails/graphql/type/enum/type_kind_enum.rb +3 -3
- data/lib/rails/graphql/type/enum.rb +34 -48
- data/lib/rails/graphql/type/input.rb +74 -23
- data/lib/rails/graphql/type/interface.rb +16 -26
- data/lib/rails/graphql/type/object/directive_object.rb +4 -4
- data/lib/rails/graphql/type/object/enum_value_object.rb +3 -3
- data/lib/rails/graphql/type/object/field_object.rb +24 -6
- data/lib/rails/graphql/type/object/input_value_object.rb +3 -3
- data/lib/rails/graphql/type/object/schema_object.rb +5 -8
- data/lib/rails/graphql/type/object/type_object.rb +29 -19
- data/lib/rails/graphql/type/object.rb +26 -23
- data/lib/rails/graphql/type/scalar/any_scalar.rb +30 -0
- data/lib/rails/graphql/type/scalar/bigint_scalar.rb +5 -5
- data/lib/rails/graphql/type/scalar/binary_scalar.rb +3 -3
- data/lib/rails/graphql/type/scalar/boolean_scalar.rb +8 -8
- data/lib/rails/graphql/type/scalar/date_scalar.rb +3 -3
- data/lib/rails/graphql/type/scalar/date_time_scalar.rb +3 -3
- data/lib/rails/graphql/type/scalar/decimal_scalar.rb +3 -3
- data/lib/rails/graphql/type/scalar/float_scalar.rb +5 -5
- data/lib/rails/graphql/type/scalar/id_scalar.rb +6 -5
- data/lib/rails/graphql/type/scalar/int_scalar.rb +6 -5
- data/lib/rails/graphql/type/scalar/json_scalar.rb +39 -0
- data/lib/rails/graphql/type/scalar/string_scalar.rb +18 -4
- data/lib/rails/graphql/type/scalar/time_scalar.rb +5 -5
- data/lib/rails/graphql/type/scalar.rb +25 -22
- data/lib/rails/graphql/type/union.rb +14 -16
- data/lib/rails/graphql/type.rb +34 -25
- data/lib/rails/graphql/type_map.rb +257 -165
- data/lib/rails/graphql/uri.rb +166 -0
- data/lib/rails/graphql/version.rb +15 -3
- data/lib/rails/graphql.rake +3 -0
- data/lib/rails/graphql.rb +85 -52
- data/lib/rails-graphql.rb +1 -1
- data/test/assets/en.yml +29 -0
- data/test/assets/introspection-mem.txt +1 -1
- data/test/assets/mem.gql +18 -45
- data/test/assets/mysql.gql +392 -0
- data/test/assets/sqlite.gql +21 -12
- data/test/assets/translate.gql +335 -0
- data/test/config.rb +18 -8
- data/test/graphql/schema_test.rb +12 -19
- data/test/graphql/source_test.rb +8 -75
- data/test/graphql/type/enum_test.rb +207 -203
- data/test/graphql/type/input_test.rb +14 -9
- data/test/graphql/type/interface_test.rb +4 -4
- data/test/graphql/type/scalar/any_scalar_test.rb +38 -0
- data/test/graphql/type/scalar/boolean_scalar_test.rb +6 -3
- data/test/graphql/type/scalar/json_scalar_test.rb +23 -0
- data/test/graphql/type_map_test.rb +51 -66
- data/test/graphql/type_test.rb +0 -19
- data/test/graphql_test.rb +1 -1
- data/test/integration/{authorization/authorization_test.rb → authorization_test.rb} +40 -14
- data/test/integration/config.rb +36 -3
- data/test/integration/customization_test.rb +39 -0
- data/test/integration/global_id_test.rb +99 -0
- data/test/integration/memory/star_wars_introspection_test.rb +24 -16
- data/test/integration/memory/star_wars_query_test.rb +54 -3
- data/test/integration/memory/star_wars_validation_test.rb +1 -1
- data/test/integration/mysql/star_wars_introspection_test.rb +25 -0
- data/test/integration/persisted_query_test.rb +87 -0
- data/test/integration/resolver_precedence_test.rb +154 -0
- data/test/integration/schemas/memory.rb +22 -7
- data/test/integration/schemas/mysql.rb +62 -0
- data/test/integration/schemas/sqlite.rb +21 -12
- data/test/integration/sqlite/star_wars_global_id_test.rb +83 -0
- data/test/integration/sqlite/star_wars_introspection_test.rb +10 -0
- data/test/integration/sqlite/star_wars_query_test.rb +14 -1
- data/test/integration/translate_test.rb +61 -0
- data/test/test_ext.rb +16 -13
- metadata +108 -157
- data/ext/depend +0 -3
- data/ext/graphqlparser/Ast.cpp +0 -346
- data/ext/graphqlparser/Ast.h +0 -1214
- data/ext/graphqlparser/AstNode.h +0 -36
- data/ext/graphqlparser/AstVisitor.h +0 -137
- data/ext/graphqlparser/GraphQLParser.cpp +0 -76
- data/ext/graphqlparser/GraphQLParser.h +0 -55
- data/ext/graphqlparser/JsonVisitor.cpp +0 -161
- data/ext/graphqlparser/JsonVisitor.cpp.inc +0 -456
- data/ext/graphqlparser/JsonVisitor.h +0 -121
- data/ext/graphqlparser/JsonVisitor.h.inc +0 -110
- data/ext/graphqlparser/VERSION +0 -1
- data/ext/graphqlparser/c/GraphQLAst.cpp +0 -324
- data/ext/graphqlparser/c/GraphQLAst.h +0 -180
- data/ext/graphqlparser/c/GraphQLAstForEachConcreteType.h +0 -44
- data/ext/graphqlparser/c/GraphQLAstNode.cpp +0 -25
- data/ext/graphqlparser/c/GraphQLAstNode.h +0 -33
- data/ext/graphqlparser/c/GraphQLAstToJSON.cpp +0 -21
- data/ext/graphqlparser/c/GraphQLAstToJSON.h +0 -24
- data/ext/graphqlparser/c/GraphQLAstVisitor.cpp +0 -55
- data/ext/graphqlparser/c/GraphQLAstVisitor.h +0 -53
- data/ext/graphqlparser/c/GraphQLParser.cpp +0 -35
- data/ext/graphqlparser/c/GraphQLParser.h +0 -54
- data/ext/graphqlparser/dump_json_ast.cpp +0 -48
- data/ext/graphqlparser/lexer.lpp +0 -324
- data/ext/graphqlparser/parser.ypp +0 -693
- data/ext/graphqlparser/parsergen/lexer.cpp +0 -2633
- data/ext/graphqlparser/parsergen/lexer.h +0 -528
- data/ext/graphqlparser/parsergen/location.hh +0 -189
- data/ext/graphqlparser/parsergen/parser.tab.cpp +0 -3300
- data/ext/graphqlparser/parsergen/parser.tab.hpp +0 -646
- data/ext/graphqlparser/parsergen/position.hh +0 -179
- data/ext/graphqlparser/parsergen/stack.hh +0 -156
- data/ext/graphqlparser/syntaxdefs.h +0 -19
- data/ext/libgraphqlparser/AstNode.h +0 -36
- data/ext/libgraphqlparser/CMakeLists.txt +0 -148
- data/ext/libgraphqlparser/CONTRIBUTING.md +0 -23
- data/ext/libgraphqlparser/GraphQLParser.cpp +0 -76
- data/ext/libgraphqlparser/GraphQLParser.h +0 -55
- data/ext/libgraphqlparser/JsonVisitor.cpp +0 -161
- data/ext/libgraphqlparser/JsonVisitor.h +0 -121
- data/ext/libgraphqlparser/LICENSE +0 -22
- data/ext/libgraphqlparser/README.clang-tidy +0 -7
- data/ext/libgraphqlparser/README.md +0 -84
- data/ext/libgraphqlparser/ast/ast.ast +0 -203
- data/ext/libgraphqlparser/ast/ast.py +0 -61
- data/ext/libgraphqlparser/ast/c.py +0 -100
- data/ext/libgraphqlparser/ast/c.pyc +0 -0
- data/ext/libgraphqlparser/ast/c_impl.py +0 -61
- data/ext/libgraphqlparser/ast/c_impl.pyc +0 -0
- data/ext/libgraphqlparser/ast/c_visitor_impl.py +0 -39
- data/ext/libgraphqlparser/ast/c_visitor_impl.pyc +0 -0
- data/ext/libgraphqlparser/ast/casing.py +0 -26
- data/ext/libgraphqlparser/ast/casing.pyc +0 -0
- data/ext/libgraphqlparser/ast/cxx.py +0 -197
- data/ext/libgraphqlparser/ast/cxx.pyc +0 -0
- data/ext/libgraphqlparser/ast/cxx_impl.py +0 -61
- data/ext/libgraphqlparser/ast/cxx_impl.pyc +0 -0
- data/ext/libgraphqlparser/ast/cxx_json_visitor_header.py +0 -42
- data/ext/libgraphqlparser/ast/cxx_json_visitor_header.pyc +0 -0
- data/ext/libgraphqlparser/ast/cxx_json_visitor_impl.py +0 -80
- data/ext/libgraphqlparser/ast/cxx_json_visitor_impl.pyc +0 -0
- data/ext/libgraphqlparser/ast/cxx_visitor.py +0 -64
- data/ext/libgraphqlparser/ast/cxx_visitor.pyc +0 -0
- data/ext/libgraphqlparser/ast/js.py +0 -65
- data/ext/libgraphqlparser/ast/license.py +0 -10
- data/ext/libgraphqlparser/ast/license.pyc +0 -0
- data/ext/libgraphqlparser/c/GraphQLAstNode.cpp +0 -25
- data/ext/libgraphqlparser/c/GraphQLAstNode.h +0 -33
- data/ext/libgraphqlparser/c/GraphQLAstToJSON.cpp +0 -21
- data/ext/libgraphqlparser/c/GraphQLAstToJSON.h +0 -24
- data/ext/libgraphqlparser/c/GraphQLAstVisitor.cpp +0 -55
- data/ext/libgraphqlparser/c/GraphQLAstVisitor.h +0 -53
- data/ext/libgraphqlparser/c/GraphQLParser.cpp +0 -35
- data/ext/libgraphqlparser/c/GraphQLParser.h +0 -54
- data/ext/libgraphqlparser/clang-tidy-all.sh +0 -3
- data/ext/libgraphqlparser/cmake/version.cmake +0 -16
- data/ext/libgraphqlparser/dump_json_ast.cpp +0 -48
- data/ext/libgraphqlparser/go/README.md +0 -20
- data/ext/libgraphqlparser/go/callbacks.go +0 -18
- data/ext/libgraphqlparser/go/gotest.go +0 -64
- data/ext/libgraphqlparser/lexer.lpp +0 -324
- data/ext/libgraphqlparser/libgraphqlparser.pc.in +0 -11
- data/ext/libgraphqlparser/parser.ypp +0 -693
- data/ext/libgraphqlparser/parsergen/lexer.cpp +0 -2633
- data/ext/libgraphqlparser/parsergen/lexer.h +0 -528
- data/ext/libgraphqlparser/parsergen/location.hh +0 -189
- data/ext/libgraphqlparser/parsergen/parser.tab.cpp +0 -3300
- data/ext/libgraphqlparser/parsergen/parser.tab.hpp +0 -646
- data/ext/libgraphqlparser/parsergen/position.hh +0 -179
- data/ext/libgraphqlparser/parsergen/stack.hh +0 -156
- data/ext/libgraphqlparser/python/CMakeLists.txt +0 -14
- data/ext/libgraphqlparser/python/README.md +0 -5
- data/ext/libgraphqlparser/python/example.py +0 -31
- data/ext/libgraphqlparser/syntaxdefs.h +0 -19
- data/ext/libgraphqlparser/test/BuildCAPI.c +0 -5
- data/ext/libgraphqlparser/test/CMakeLists.txt +0 -25
- data/ext/libgraphqlparser/test/JsonVisitorTests.cpp +0 -28
- data/ext/libgraphqlparser/test/ParserTests.cpp +0 -352
- data/ext/libgraphqlparser/test/kitchen-sink.graphql +0 -59
- data/ext/libgraphqlparser/test/kitchen-sink.json +0 -1
- data/ext/libgraphqlparser/test/schema-kitchen-sink.graphql +0 -78
- data/ext/libgraphqlparser/test/schema-kitchen-sink.json +0 -1
- data/ext/libgraphqlparser/test/valgrind.supp +0 -33
- data/ext/version.cpp +0 -21
- data/lib/graphqlparser.so +0 -0
- data/lib/rails/graphql/native/functions.rb +0 -38
- data/lib/rails/graphql/native/location.rb +0 -41
- data/lib/rails/graphql/native/pointers.rb +0 -23
- data/lib/rails/graphql/native/visitor.rb +0 -349
- data/lib/rails/graphql/native.rb +0 -56
- data/test/integration/schemas/authorization.rb +0 -12
@@ -15,49 +15,24 @@ class GraphQL_TypeMapTest < GraphQL::TestCase
|
|
15
15
|
@subject ||= DESCRIBED_CLASS.new
|
16
16
|
end
|
17
17
|
|
18
|
-
def test_loaded_bang
|
19
|
-
DESCRIBED_CLASS.stub(:base_classes, { Type: false }) do
|
20
|
-
refute(DESCRIBED_CLASS.base_classes[:Type])
|
21
|
-
DESCRIBED_CLASS.loaded!(:Type)
|
22
|
-
assert(DESCRIBED_CLASS.base_classes[:Type])
|
23
|
-
end
|
24
|
-
|
25
|
-
DESCRIBED_CLASS.stub(:base_classes, { Type: true }) do
|
26
|
-
assert(DESCRIBED_CLASS.base_classes[:Type])
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
18
|
def test_reset_bang
|
31
19
|
checkpoint = registered_double
|
32
20
|
subject.instance_variable_set(:@objects, 1)
|
33
|
-
subject.instance_variable_set(:@
|
34
|
-
subject.instance_variable_set(:@
|
21
|
+
subject.instance_variable_set(:@version, 2)
|
22
|
+
subject.instance_variable_set(:@pending, 3)
|
35
23
|
subject.instance_variable_set(:@skip_register, 4)
|
36
|
-
subject.instance_variable_set(:@
|
37
|
-
subject.instance_variable_set(:@
|
24
|
+
subject.instance_variable_set(:@callbacks, 5)
|
25
|
+
subject.instance_variable_set(:@dependencies, 6)
|
26
|
+
subject.instance_variable_set(:@index, 7)
|
38
27
|
subject.reset!
|
39
28
|
|
40
29
|
refute_equal(1, subject.instance_variable_get(:@objects))
|
41
|
-
refute_equal(2, subject.instance_variable_get(:@
|
42
|
-
refute_equal(3, subject.instance_variable_get(:@
|
30
|
+
refute_equal(2, subject.instance_variable_get(:@version))
|
31
|
+
refute_equal(3, subject.instance_variable_get(:@pending))
|
43
32
|
refute_equal(4, subject.instance_variable_get(:@skip_register))
|
44
|
-
refute_equal(5, subject.instance_variable_get(:@
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
def test_use_checkpoint_bang
|
49
|
-
subject.stub(:objects, [1]) do
|
50
|
-
assert_registered do
|
51
|
-
subject.use_checkpoint!
|
52
|
-
assert_equal([1], subject.instance_variable_get(:@checkpoint))
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
reset = false
|
57
|
-
subject.stub(:reset!, -> { reset = true }) do
|
58
|
-
subject.use_checkpoint!
|
59
|
-
assert(reset)
|
60
|
-
end
|
33
|
+
refute_equal(5, subject.instance_variable_get(:@callbacks))
|
34
|
+
refute_equal(6, subject.instance_variable_get(:@dependencies))
|
35
|
+
refute_equal(7, subject.instance_variable_get(:@index))
|
61
36
|
end
|
62
37
|
|
63
38
|
def test_objects
|
@@ -66,15 +41,23 @@ class GraphQL_TypeMapTest < GraphQL::TestCase
|
|
66
41
|
assert_empty(subject.objects)
|
67
42
|
end
|
68
43
|
|
69
|
-
item =
|
70
|
-
|
44
|
+
item = double(
|
45
|
+
gql_name: 'name',
|
46
|
+
is_a?: ->(klass) { klass == Rails::GraphQL::Helpers::Registerable },
|
47
|
+
)
|
48
|
+
|
49
|
+
other = double(gql_name: 'otherName')
|
50
|
+
|
51
|
+
checker = -> { item }
|
52
|
+
subject.stub_ivar(:@index, { a: { b: { c: checker }, d: { e: checker }, f: { g: other } } }) do
|
71
53
|
assert_empty(subject.objects(namespaces: :z))
|
72
54
|
assert_empty(subject.objects(namespaces: :a, base_classes: :z))
|
73
|
-
assert_empty(subject.objects(namespaces: :a, base_classes: :
|
55
|
+
assert_empty(subject.objects(namespaces: :a, base_classes: :f))
|
74
56
|
|
75
|
-
|
76
|
-
|
77
|
-
|
57
|
+
subject.class.stub(:base_classes, %i[b d f]) do
|
58
|
+
result = subject.objects
|
59
|
+
assert_equal([item], result)
|
60
|
+
end
|
78
61
|
end
|
79
62
|
end
|
80
63
|
|
@@ -86,15 +69,10 @@ class GraphQL_TypeMapTest < GraphQL::TestCase
|
|
86
69
|
|
87
70
|
loaded = false
|
88
71
|
subject.stub(:fetch, ->(*x) { x if loaded }) do
|
89
|
-
|
90
|
-
assert_raises(StandardError) { subject.fetch!(1) }
|
91
|
-
end
|
72
|
+
assert_raises(StandardError) { subject.fetch!(1) }
|
92
73
|
|
93
|
-
subject.stub(:
|
94
|
-
|
95
|
-
assert_equal([1, { base_class: :Type }], subject.fetch!(1))
|
96
|
-
assert(loaded)
|
97
|
-
end
|
74
|
+
subject.stub(:load_dependencies!, ->(*) { loaded = true }) do
|
75
|
+
assert_equal([1, { base_class: :Type }], subject.fetch!(1))
|
98
76
|
end
|
99
77
|
end
|
100
78
|
end
|
@@ -170,7 +148,7 @@ class GraphQL_TypeMapTest < GraphQL::TestCase
|
|
170
148
|
subject.stub(:fetch, passallthrough) do
|
171
149
|
xargs = { base_class: object1, namespaces: :base, exclusive: true }
|
172
150
|
assert_equal([:string, xargs], added[1][-1].call)
|
173
|
-
assert_equal(object1, added[0][-1]
|
151
|
+
assert_equal(object1, added[0][-1])
|
174
152
|
end
|
175
153
|
|
176
154
|
assert_equal(1, subject.instance_variable_get(:@objects))
|
@@ -212,7 +190,7 @@ class GraphQL_TypeMapTest < GraphQL::TestCase
|
|
212
190
|
assert_equal([:base, :Type, :a], added[0][0..-2])
|
213
191
|
|
214
192
|
subject.stub(:fetch, passallthrough) do
|
215
|
-
xargs = { base_class: :Type, namespaces: [:base], exclusive: true }
|
193
|
+
xargs = { base_class: :Type, namespaces: [:base].to_set, exclusive: true }
|
216
194
|
assert_equal([:string, xargs], added[0][-1].call)
|
217
195
|
end
|
218
196
|
|
@@ -229,13 +207,15 @@ class GraphQL_TypeMapTest < GraphQL::TestCase
|
|
229
207
|
|
230
208
|
def test_each_from
|
231
209
|
assert_registered(4) do
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
210
|
+
Integer.stub_imethod(:gql_name, -> { to_s }) do
|
211
|
+
subject.stub_ivar(:@index, SAMPLE_INDEX) do
|
212
|
+
items = [1, 4]
|
213
|
+
subject.each_from(:base) { |x| assert_equal(items.shift, x) }
|
214
|
+
|
215
|
+
assert_equal([2, 3, 1, 4], subject.each_from(:other).entries)
|
216
|
+
assert_equal([2, 3], subject.each_from(:other, exclusive: true).entries)
|
217
|
+
assert_equal([], subject.each_from(:other, base_class: :Other).entries)
|
218
|
+
end
|
239
219
|
end
|
240
220
|
end
|
241
221
|
end
|
@@ -243,7 +223,7 @@ class GraphQL_TypeMapTest < GraphQL::TestCase
|
|
243
223
|
def test_after_register
|
244
224
|
subject.stub(:fetch, passallthrough) do
|
245
225
|
result = subject.after_register(:a, &passthrough)
|
246
|
-
xargs = { prevent_register: true, base_class: :Type
|
226
|
+
xargs = { prevent_register: true, base_class: :Type }
|
247
227
|
assert_equal([:a, xargs], result)
|
248
228
|
end
|
249
229
|
|
@@ -268,15 +248,20 @@ class GraphQL_TypeMapTest < GraphQL::TestCase
|
|
268
248
|
[:other, :Type],
|
269
249
|
[:other, :Type],
|
270
250
|
].each_with_index do |(ns, bc), idx|
|
271
|
-
assert_nil(register[:a][idx].call(:x, bc, :non_called))
|
272
|
-
assert_nil(register[:a][idx].call(ns, :y, :non_called))
|
273
|
-
|
251
|
+
assert_nil(register[:a][3 - idx].call(:x, bc, :non_called))
|
252
|
+
assert_nil(register[:a][3 - idx].call(ns, :y, :non_called))
|
253
|
+
assert(register[:a][3 - idx].call(ns, bc, :called))
|
274
254
|
end
|
275
255
|
end
|
276
256
|
|
277
257
|
def test_inspect
|
278
|
-
assert_equal(<<~INFO.
|
279
|
-
#<Rails::GraphQL::TypeMap [index]
|
258
|
+
assert_equal(<<~INFO.squish, subject.inspect)
|
259
|
+
#<Rails::GraphQL::TypeMap [index]
|
260
|
+
@namespaces=0
|
261
|
+
@base_classes=3
|
262
|
+
@objects=0
|
263
|
+
@pending=0
|
264
|
+
@dependencies={base: 14}>
|
280
265
|
INFO
|
281
266
|
end
|
282
267
|
|
@@ -320,11 +305,11 @@ class GraphQL_TypeMapTest < GraphQL::TestCase
|
|
320
305
|
|
321
306
|
def test_register_pending_bang
|
322
307
|
registered = false
|
323
|
-
object = double(register!: -> {
|
308
|
+
object = double(register!: -> { registered = true }, registered?: false)
|
324
309
|
skipped = double(registered?: false)
|
325
310
|
other = double(registered?: true)
|
326
311
|
|
327
|
-
subject.stub(:skip_register, [skipped]) do
|
312
|
+
subject.stub(:skip_register, [[skipped].to_set]) do
|
328
313
|
subject.stub_ivar(:@pending, [[skipped, :a], [object, :b], [other, :c]]) do
|
329
314
|
subject.send(:register_pending!)
|
330
315
|
assert(registered)
|
data/test/graphql/type_test.rb
CHANGED
@@ -38,25 +38,6 @@ class GraphQL_TypeTest < GraphQL::TestCase
|
|
38
38
|
assert_equal(1, DESCRIBED_CLASS.decorate(1))
|
39
39
|
end
|
40
40
|
|
41
|
-
def test_gql_resolver_ask
|
42
|
-
DESCRIBED_CLASS.stub(:base_object?, false) do
|
43
|
-
refute(DESCRIBED_CLASS.gql_resolver?(:calculate))
|
44
|
-
DESCRIBED_CLASS.send(:define_method, :calculate) {}
|
45
|
-
|
46
|
-
assert(DESCRIBED_CLASS.gql_resolver?(:calculate))
|
47
|
-
|
48
|
-
other_class = unmapped_class(DESCRIBED_CLASS)
|
49
|
-
assert(other_class.gql_resolver?(:calculate))
|
50
|
-
|
51
|
-
other_class.stub(:base_object?, true) do
|
52
|
-
refute(other_class.gql_resolver?(:calculate))
|
53
|
-
end
|
54
|
-
|
55
|
-
DESCRIBED_CLASS.send(:undef_method, :calculate)
|
56
|
-
refute(DESCRIBED_CLASS.gql_resolver?(:calculate))
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
41
|
def test_kind_ask
|
61
42
|
assert_respond_to(DESCRIBED_CLASS, :scalar?)
|
62
43
|
assert_respond_to(DESCRIBED_CLASS, :object?)
|
data/test/graphql_test.rb
CHANGED
@@ -12,7 +12,7 @@ class GraphQLTest < GraphQL::TestCase
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def test_ar_adapter_key
|
15
|
-
DESCRIBED_CLASS.stub(:config, double(ar_adapters: { 'a' => 1 })) do
|
15
|
+
DESCRIBED_CLASS.stub(:config, double(ar_adapters: { 'a' => { key: 1 } })) do
|
16
16
|
assert_equal(1, DESCRIBED_CLASS.ar_adapter_key('a'))
|
17
17
|
assert_nil(DESCRIBED_CLASS.ar_adapter_key('b'))
|
18
18
|
end
|
@@ -1,9 +1,20 @@
|
|
1
1
|
require 'integration/config'
|
2
2
|
|
3
|
-
class
|
4
|
-
|
3
|
+
class Integration_AuthorizationTest < GraphQL::IntegrationTestCase
|
4
|
+
class SCHEMA < GraphQL::Schema
|
5
|
+
namespace :authorization
|
6
|
+
|
7
|
+
configure do |config|
|
8
|
+
config.enable_string_collector = false
|
9
|
+
config.default_response_format = :json
|
10
|
+
end
|
11
|
+
|
12
|
+
query_fields do
|
13
|
+
field(:sample1, :string).resolve { 'Ok 1' }
|
14
|
+
field(:sample2, :string).authorize.resolve { 'Ok 2' }
|
15
|
+
end
|
16
|
+
end
|
5
17
|
|
6
|
-
SCHEMA = ::AuthorizationSchema
|
7
18
|
EXCEPTION_NAME = 'Rails::GraphQL::UnauthorizedFieldError'
|
8
19
|
EXCEPTION_PATH = ['errors', 0, 'extensions', 'exception']
|
9
20
|
|
@@ -22,11 +33,11 @@ class Integration_Memory_AuthorizationTest < GraphQL::IntegrationTestCase
|
|
22
33
|
assert_exception('{ sample2 }')
|
23
34
|
assert_result({ sample1: 'Ok 1', sample2: nil }, '{ sample1 sample2 }', dig: 'data')
|
24
35
|
|
25
|
-
SCHEMA.stub_imethod(:authorize!,
|
36
|
+
SCHEMA.stub_imethod(:authorize!, -> { authorized! }) do
|
26
37
|
assert_result(SAMPLE2, '{ sample2 }')
|
27
38
|
end
|
28
39
|
|
29
|
-
SCHEMA.stub_imethod(:authorize!,
|
40
|
+
SCHEMA.stub_imethod(:authorize!, -> { unauthorized! }) do
|
30
41
|
assert_exception('{ sample2 }')
|
31
42
|
end
|
32
43
|
end
|
@@ -38,7 +49,7 @@ class Integration_Memory_AuthorizationTest < GraphQL::IntegrationTestCase
|
|
38
49
|
assert_executed { assert_result(SAMPLE1, '{ sample1 }') }
|
39
50
|
end
|
40
51
|
|
41
|
-
block = ->(ev) { executed! && ev.
|
52
|
+
block = ->(ev) { executed! && ev.unauthorized! }
|
42
53
|
field.stub_ivar(:@authorizer, [[], {}, block]) do
|
43
54
|
assert_executed { assert_exception('{ sample1 }') }
|
44
55
|
end
|
@@ -51,7 +62,7 @@ class Integration_Memory_AuthorizationTest < GraphQL::IntegrationTestCase
|
|
51
62
|
assert_executed { assert_result(SAMPLE2, '{ sample2 }') }
|
52
63
|
|
53
64
|
assert_executed do
|
54
|
-
field.on(:authorize) { |event| event.
|
65
|
+
field.on(:authorize) { |event| event.unauthorized! }
|
55
66
|
assert_exception('{ sample2 }')
|
56
67
|
end
|
57
68
|
end
|
@@ -64,29 +75,44 @@ class Integration_Memory_AuthorizationTest < GraphQL::IntegrationTestCase
|
|
64
75
|
auth_directive.on(:authorize, &method(:executed!))
|
65
76
|
|
66
77
|
auth_directive.stub_ivar(:@gql_name, 'AuthDirective') do
|
67
|
-
|
78
|
+
instance = auth_directive.new.tap { |dir| dir.instance_variable_set(:@owner, nil) }
|
79
|
+
field.stub_ivar(:@directives, [instance]) do
|
68
80
|
assert_executed { assert_result(SAMPLE2, '{ sample2 }') }
|
69
81
|
end
|
70
82
|
|
71
|
-
|
72
|
-
|
83
|
+
instance = auth_directive.new.tap { |dir| dir.instance_variable_set(:@owner, nil) }
|
84
|
+
SCHEMA.stub_ivar(:@directives, [instance]) do
|
85
|
+
assert_executed(0) { assert_result(SAMPLE2, '{ sample2 }') }
|
86
|
+
end
|
87
|
+
|
88
|
+
auth_directive.events[:authorize][0].stub_ivar(:@exclusive, false) do
|
89
|
+
SCHEMA.stub_ivar(:@directives, [instance]) do
|
90
|
+
assert_executed { assert_result(SAMPLE2, '{ sample2 }') }
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
instance = auth_directive.new.tap { |dir| dir.instance_variable_set(:@owner, nil) }
|
95
|
+
method = ->(*) { @directives = Set.new([instance]) }
|
96
|
+
Rails::GraphQL::Request::Component::Field.stub_imethod(:parse_directives, method) do
|
97
|
+
assert_executed { assert_result(SAMPLE2, '{ sample2 @AuthDirective }') }
|
73
98
|
end
|
74
99
|
end
|
75
100
|
end
|
76
101
|
|
77
102
|
def test_authorize_bypass
|
78
103
|
field = SCHEMA.query_field(:sample2)
|
79
|
-
|
80
|
-
|
104
|
+
counter = method(:executed!)
|
105
|
+
auth_block = ->(ev = nil) { counter.call && (ev || itself).authorized! }
|
106
|
+
unauth_block = ->(ev = nil) { counter.call && (ev || itself).unauthorized! }
|
81
107
|
|
82
108
|
field.stub_ivar(:@events, { authorize: [unauth_block] }) do
|
83
|
-
SCHEMA.stub_imethod(:authorize!,
|
109
|
+
SCHEMA.stub_imethod(:authorize!, auth_block) do
|
84
110
|
assert_executed { assert_result(SAMPLE2, '{ sample2 }') }
|
85
111
|
end
|
86
112
|
end
|
87
113
|
|
88
114
|
field.stub_ivar(:@events, { authorize: [auth_block] }) do
|
89
|
-
SCHEMA.stub_imethod(:authorize!,
|
115
|
+
SCHEMA.stub_imethod(:authorize!, unauth_block) do
|
90
116
|
assert_executed { assert_exception('{ sample2 }') }
|
91
117
|
end
|
92
118
|
end
|
data/test/integration/config.rb
CHANGED
@@ -7,8 +7,28 @@ module GraphQL
|
|
7
7
|
SCHEMAS = Pathname.new(__dir__).join('schemas')
|
8
8
|
ASSETS = Pathname.new(__dir__).join('../assets')
|
9
9
|
|
10
|
+
I18n.load_path << ASSETS.join("en.yml")
|
11
|
+
|
12
|
+
BASE_SCHEMA = ::Rails::GraphQL::Schema
|
13
|
+
|
14
|
+
def run(*)
|
15
|
+
BASE_SCHEMA.send(:introspection_dependencies!)
|
16
|
+
BASE_SCHEMA.type_map.send(:load_dependencies!)
|
17
|
+
|
18
|
+
super
|
19
|
+
end
|
20
|
+
|
10
21
|
def setup
|
11
|
-
|
22
|
+
BASE_SCHEMA.type_map.base_classes.each do |base_class|
|
23
|
+
::GraphQL.const_get(base_class).descendants.each(&:register!)
|
24
|
+
end
|
25
|
+
|
26
|
+
index = BASE_SCHEMA.type_map.instance_variable_get(:@index)[:base][:Type]
|
27
|
+
remove_keys_form_type_map&.each(&index.method(:delete))
|
28
|
+
end
|
29
|
+
|
30
|
+
def teardown
|
31
|
+
BASE_SCHEMA.type_map.reset!
|
12
32
|
end
|
13
33
|
|
14
34
|
protected
|
@@ -17,8 +37,8 @@ module GraphQL
|
|
17
37
|
require(SCHEMAS.join("#{name}"))
|
18
38
|
end
|
19
39
|
|
20
|
-
def
|
21
|
-
|
40
|
+
def remove_keys_form_type_map
|
41
|
+
all_non_spec_keys
|
22
42
|
end
|
23
43
|
|
24
44
|
def named_list(*list, **extra)
|
@@ -52,5 +72,18 @@ module GraphQL
|
|
52
72
|
obj = obj.map(&:deep_stringify_keys) if obj.is_a?(Array)
|
53
73
|
obj.nil? ? assert_nil(result) : assert_equal(obj, result)
|
54
74
|
end
|
75
|
+
|
76
|
+
def all_non_spec_keys
|
77
|
+
[
|
78
|
+
:any, 'Any',
|
79
|
+
:bigint, 'Bigint',
|
80
|
+
:binary, 'Binary', :file,
|
81
|
+
:date_time, 'DateTime', :datetime,
|
82
|
+
:date, 'Date',
|
83
|
+
:decimal, 'Decimal',
|
84
|
+
:time, 'Time',
|
85
|
+
:json, 'JSON',
|
86
|
+
]
|
87
|
+
end
|
55
88
|
end
|
56
89
|
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'integration/config'
|
2
|
+
|
3
|
+
class Integration_CustomizationTest < GraphQL::IntegrationTestCase
|
4
|
+
class SCHEMA < GraphQL::Schema
|
5
|
+
namespace :customization
|
6
|
+
|
7
|
+
configure do |config|
|
8
|
+
config.schema_type_names = {
|
9
|
+
query: 'A',
|
10
|
+
mutation: 'B',
|
11
|
+
subscription: 'C',
|
12
|
+
}
|
13
|
+
end
|
14
|
+
|
15
|
+
query_fields { field(:one, :string) }
|
16
|
+
mutation_fields { field(:two, :string) }
|
17
|
+
subscription_fields { field(:three, :string) }
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_type_name_for
|
21
|
+
assert_equal('A', SCHEMA.type_name_for(:query))
|
22
|
+
assert_equal('B', SCHEMA.type_name_for(:mutation))
|
23
|
+
assert_equal('C', SCHEMA.type_name_for(:subscription))
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_type_map
|
27
|
+
assert_equal(SCHEMA.query_type, SCHEMA.find_type('A'))
|
28
|
+
assert_equal(SCHEMA.mutation_type, SCHEMA.find_type('B'))
|
29
|
+
assert_equal(SCHEMA.subscription_type, SCHEMA.find_type('C'))
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_cache_prefix
|
33
|
+
assert_equal('graphql/customization/', SCHEMA.config.cache_prefix)
|
34
|
+
SCHEMA.config.cache_prefix = 'banana'
|
35
|
+
assert_equal('banana', SCHEMA.config.cache_prefix)
|
36
|
+
SCHEMA.config.cache_prefix = nil
|
37
|
+
assert_equal('graphql/customization/', SCHEMA.config.cache_prefix)
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
require 'integration/config'
|
2
|
+
|
3
|
+
class Integration_GlobalIDTest < GraphQL::IntegrationTestCase
|
4
|
+
load_schema 'memory'
|
5
|
+
|
6
|
+
SCHEMA = ::StartWarsMemSchema
|
7
|
+
|
8
|
+
## CREATE
|
9
|
+
|
10
|
+
def test_create_directive
|
11
|
+
obj = GraphQL::Directive::DeprecatedDirective
|
12
|
+
assert_gid_value('gql://base/Directive/deprecated', obj)
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_create_directive_instance
|
16
|
+
obj = GraphQL::DeprecatedDirective()
|
17
|
+
assert_gid_value('gql://base/Directive/deprecated?', obj)
|
18
|
+
|
19
|
+
obj = GraphQL::DeprecatedDirective(reason: 'A B')
|
20
|
+
assert_gid_value('gql://base/Directive/deprecated?reason=A+B', obj)
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_create_schema
|
24
|
+
assert_gid_value('gql://start-wars-mem/Schema', SCHEMA)
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_create_query_field
|
28
|
+
obj = SCHEMA[:query][:hero]
|
29
|
+
assert_gid_value('gql://start-wars-mem/Schema/query/hero', obj)
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_create_mutation_field
|
33
|
+
obj = SCHEMA[:mutation][:change_human]
|
34
|
+
assert_gid_value('gql://start-wars-mem/Schema/mutation/changeHuman', obj)
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_create_object_field
|
38
|
+
obj = GraphQL::HumanObject[:name]
|
39
|
+
assert_gid_value('gql://start-wars-mem/HumanObject/name', obj)
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_create_scalar_type
|
43
|
+
obj = GraphQL.type_map.fetch(:string)
|
44
|
+
assert_gid_value('gql://base/Type/String', obj)
|
45
|
+
end
|
46
|
+
|
47
|
+
def assert_gid_value(result, object)
|
48
|
+
assert_equal(result, object.to_gid.to_s)
|
49
|
+
end
|
50
|
+
|
51
|
+
## PARSE
|
52
|
+
|
53
|
+
def test_parse_directive
|
54
|
+
obj = find_gid('gql://base/Directive/deprecated')
|
55
|
+
assert_equal(GraphQL::Directive::DeprecatedDirective, obj)
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_parse_directive_instance
|
59
|
+
obj = find_gid('gql://base/Directive/deprecated?')
|
60
|
+
assert_instance_of(GraphQL::Directive::DeprecatedDirective, obj)
|
61
|
+
assert_nil(obj.args[:reason])
|
62
|
+
|
63
|
+
obj = find_gid('gql://base/Directive/deprecated?reason=A+B')
|
64
|
+
assert_instance_of(GraphQL::Directive::DeprecatedDirective, obj)
|
65
|
+
assert_equal('A B', obj.args[:reason])
|
66
|
+
|
67
|
+
obj = find_gid('gql://base/Directive/skip?if=false')
|
68
|
+
assert_instance_of(GraphQL::Directive::SkipDirective, obj)
|
69
|
+
assert_equal(false, obj.args[:if])
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_parse_schema
|
73
|
+
assert_equal(SCHEMA, find_gid('gql://start-wars-mem/Schema'))
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_parse_query_field
|
77
|
+
obj = find_gid('gql://start-wars-mem/Schema/query/hero')
|
78
|
+
assert_equal(SCHEMA[:query][:hero], obj)
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_parse_mutation_field
|
82
|
+
obj = find_gid('gql://start-wars-mem/Schema/mutation/changeHuman')
|
83
|
+
assert_equal(SCHEMA[:mutation][:change_human], obj)
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_parse_object_field
|
87
|
+
obj = find_gid('gql://start-wars-mem/HumanObject/name')
|
88
|
+
assert_equal(GraphQL::HumanObject[:name], obj)
|
89
|
+
end
|
90
|
+
|
91
|
+
def test_parse_scalar_type
|
92
|
+
obj = find_gid('gql://base/Type/String')
|
93
|
+
assert_equal(GraphQL.type_map.fetch(:string), obj)
|
94
|
+
end
|
95
|
+
|
96
|
+
def find_gid(gid)
|
97
|
+
GraphQL::GlobalID.find(gid)
|
98
|
+
end
|
99
|
+
end
|
@@ -6,13 +6,19 @@ class Integration_Memory_StarWarsIntrospectionTest < GraphQL::IntegrationTestCas
|
|
6
6
|
|
7
7
|
SCHEMA = ::StartWarsMemSchema
|
8
8
|
|
9
|
+
def test_auto_introspection
|
10
|
+
assert(SCHEMA.introspection?)
|
11
|
+
assert(SCHEMA.has_field?(:query, :__schema))
|
12
|
+
assert(SCHEMA.has_field?(:query, :__type))
|
13
|
+
end
|
14
|
+
|
9
15
|
def test_query_schema_types
|
10
|
-
types = named_list(*%w[
|
11
|
-
|
12
|
-
|
16
|
+
types = named_list(*%w[Boolean Character Droid Episode Float Human ID Int String
|
17
|
+
_Mutation _Query __Directive __DirectiveLocation __EnumValue __Field __InputValue
|
18
|
+
__Schema __Type __TypeKind])
|
13
19
|
|
14
20
|
sort_items = ->(result) do
|
15
|
-
result.dig('data', '__schema', 'types')
|
21
|
+
result.dig('data', '__schema', 'types')&.sort_by! { |t| t['name'] }
|
16
22
|
end
|
17
23
|
|
18
24
|
assert_result({ data: { __schema: { types: types } } }, <<~GQL, &sort_items)
|
@@ -53,11 +59,11 @@ class Integration_Memory_StarWarsIntrospectionTest < GraphQL::IntegrationTestCas
|
|
53
59
|
def test_query_object_fields
|
54
60
|
fields = [
|
55
61
|
{ name: 'id', type: { name: nil, kind: 'NON_NULL' } },
|
56
|
-
{ name: 'name', type: { name: 'String', kind: 'SCALAR' } },
|
57
|
-
{ name: 'friends', type: { name: nil, kind: 'LIST' } },
|
58
62
|
{ name: 'appearsIn', type: { name: nil, kind: 'LIST' } },
|
59
|
-
{ name: '
|
63
|
+
{ name: 'friends', type: { name: nil, kind: 'LIST' } },
|
64
|
+
{ name: 'name', type: { name: 'String', kind: 'SCALAR' } },
|
60
65
|
{ name: 'primaryFunction', type: { name: 'String', kind: 'SCALAR' } },
|
66
|
+
{ name: 'secretBackstory', type: { name: 'String', kind: 'SCALAR' } },
|
61
67
|
]
|
62
68
|
|
63
69
|
assert_result({ data: { __type: { name: 'Droid', fields: fields } } }, <<~GQL)
|
@@ -68,11 +74,11 @@ class Integration_Memory_StarWarsIntrospectionTest < GraphQL::IntegrationTestCas
|
|
68
74
|
def test_query_object_fields_with_nested_type
|
69
75
|
fields = [
|
70
76
|
{ name: 'id', type: { name: nil, kind: 'NON_NULL', ofType: { name: 'ID', kind: 'SCALAR' } } },
|
71
|
-
{ name: 'name', type: { name: 'String', kind: 'SCALAR', ofType: nil } },
|
72
|
-
{ name: 'friends', type: { name: nil, kind: 'LIST', ofType: { name: 'Character', kind: 'INTERFACE' } } },
|
73
77
|
{ name: 'appearsIn', type: { name: nil, kind: 'LIST', ofType: { name: 'Episode', kind: 'ENUM' } } },
|
74
|
-
{ name: '
|
78
|
+
{ name: 'friends', type: { name: nil, kind: 'LIST', ofType: { name: 'Character', kind: 'INTERFACE' } } },
|
79
|
+
{ name: 'name', type: { name: 'String', kind: 'SCALAR', ofType: nil } },
|
75
80
|
{ name: 'primaryFunction', type: { name: 'String', kind: 'SCALAR', ofType: nil } },
|
81
|
+
{ name: 'secretBackstory', type: { name: 'String', kind: 'SCALAR', ofType: nil } },
|
76
82
|
]
|
77
83
|
|
78
84
|
assert_result({ data: { __type: { name: 'Droid', fields: fields } } }, <<~GQL)
|
@@ -98,11 +104,9 @@ class Integration_Memory_StarWarsIntrospectionTest < GraphQL::IntegrationTestCas
|
|
98
104
|
}, defaultValue: nil }
|
99
105
|
|
100
106
|
fields = [
|
101
|
-
{ name: '
|
102
|
-
{ name: '__type', args: [name_arg] },
|
107
|
+
{ name: 'droid', args: [id_arg.merge(description: 'ID of the droid')] },
|
103
108
|
{ name: 'hero', args: [epi_arg] },
|
104
109
|
{ name: 'human', args: [id_arg.merge(description: 'ID of the human')] },
|
105
|
-
{ name: 'droid', args: [id_arg.merge(description: 'ID of the droid')] },
|
106
110
|
]
|
107
111
|
|
108
112
|
assert_result({ data: { __schema: { queryType: { fields: fields } } } }, <<~GQL)
|
@@ -128,6 +132,8 @@ class Integration_Memory_StarWarsIntrospectionTest < GraphQL::IntegrationTestCas
|
|
128
132
|
# There are some issues with the end sorting, so compare the string result
|
129
133
|
# with sorted characters, which will produce the exact match
|
130
134
|
def test_query_full_introspection
|
135
|
+
SCHEMA.send(:enable_introspection!)
|
136
|
+
|
131
137
|
query = gql_file('introspection')
|
132
138
|
result = text_file('introspection-mem').split('').sort.join
|
133
139
|
assert_result(result, query, as: :string) do |res|
|
@@ -137,8 +143,10 @@ class Integration_Memory_StarWarsIntrospectionTest < GraphQL::IntegrationTestCas
|
|
137
143
|
end
|
138
144
|
|
139
145
|
def test_gql_introspection
|
140
|
-
|
141
|
-
|
142
|
-
|
146
|
+
result = SCHEMA.to_gql
|
147
|
+
expected = gql_file('mem').split('').sort.join.squish
|
148
|
+
|
149
|
+
# File.write('test/assets/mem.gql', result)
|
150
|
+
assert_equal(expected, result.split('').sort.join.squish)
|
143
151
|
end
|
144
152
|
end
|