rails-graphql 0.2.1 → 1.0.0.rc1
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 +631 -0
- data/ext/gql_parser.h +21 -0
- data/ext/shared.c +477 -0
- data/ext/shared.h +177 -0
- data/lib/generators/graphql/channel_generator.rb +27 -0
- data/lib/generators/graphql/controller_generator.rb +9 -4
- data/lib/generators/graphql/install_generator.rb +49 -0
- data/lib/generators/graphql/schema_generator.rb +9 -4
- data/lib/generators/graphql/templates/channel.erb +7 -0
- data/lib/generators/graphql/templates/config.rb +97 -0
- data/lib/generators/graphql/templates/controller.erb +2 -0
- data/lib/generators/graphql/templates/schema.erb +5 -3
- 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 +48 -0
- data/lib/rails/graphql/alternative/mutation.rb +17 -0
- data/lib/rails/graphql/alternative/query.rb +98 -0
- data/lib/rails/graphql/alternative/subscription.rb +18 -0
- data/lib/rails/graphql/alternative.rb +20 -0
- data/lib/rails/graphql/argument.rb +25 -26
- data/lib/rails/graphql/callback.rb +30 -14
- data/lib/rails/graphql/collectors/hash_collector.rb +26 -7
- data/lib/rails/graphql/collectors/idented_collector.rb +10 -7
- data/lib/rails/graphql/collectors/json_collector.rb +43 -17
- data/lib/rails/graphql/collectors.rb +4 -4
- data/lib/rails/graphql/config.rb +154 -23
- 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 +4 -4
- data/lib/rails/graphql/directive/skip_directive.rb +4 -4
- data/lib/rails/graphql/directive/specified_by_directive.rb +24 -0
- data/lib/rails/graphql/directive.rb +134 -73
- data/lib/rails/graphql/errors.rb +33 -4
- data/lib/rails/graphql/event.rb +21 -9
- data/lib/rails/graphql/field/authorized_field.rb +17 -6
- data/lib/rails/graphql/field/input_field.rb +8 -12
- data/lib/rails/graphql/field/mutation_field.rb +43 -9
- data/lib/rails/graphql/field/output_field.rb +112 -12
- data/lib/rails/graphql/field/proxied_field.rb +35 -26
- data/lib/rails/graphql/field/resolved_field.rb +27 -25
- data/lib/rails/graphql/field/scoped_config.rb +10 -4
- data/lib/rails/graphql/field/subscription_field.rb +123 -0
- data/lib/rails/graphql/field/typed_field.rb +69 -24
- data/lib/rails/graphql/field.rb +89 -74
- data/lib/rails/graphql/global_id.rb +89 -0
- data/lib/rails/graphql/helpers/attribute_delegator.rb +5 -5
- data/lib/rails/graphql/helpers/inherited_collection/array.rb +51 -0
- data/lib/rails/graphql/helpers/inherited_collection/base.rb +45 -0
- data/lib/rails/graphql/helpers/inherited_collection/hash.rb +88 -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 +33 -28
- data/lib/rails/graphql/helpers/with_assignment.rb +6 -6
- data/lib/rails/graphql/helpers/with_callbacks.rb +28 -11
- data/lib/rails/graphql/helpers/with_description.rb +73 -0
- data/lib/rails/graphql/helpers/with_directives.rb +58 -30
- data/lib/rails/graphql/helpers/with_events.rb +22 -23
- data/lib/rails/graphql/helpers/with_fields.rb +86 -26
- data/lib/rails/graphql/helpers/with_global_id.rb +22 -0
- data/lib/rails/graphql/helpers/with_name.rb +44 -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 +162 -56
- 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 +89 -33
- data/lib/rails/graphql/railties/app/base_channel.rb +10 -0
- data/lib/rails/graphql/railties/app/base_controller.rb +12 -0
- data/lib/rails/graphql/railties/app/views/_cable.js.erb +56 -0
- data/lib/rails/graphql/railties/app/views/_fetch.js.erb +20 -0
- data/lib/rails/graphql/railties/app/views/graphiql.html.erb +101 -0
- data/lib/rails/graphql/railties/base_generator.rb +5 -17
- data/lib/rails/graphql/railties/channel.rb +157 -0
- data/lib/rails/graphql/railties/controller.rb +91 -25
- 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 +26 -50
- data/lib/rails/graphql/request/backtrace.rb +212 -0
- data/lib/rails/graphql/request/component/field.rb +98 -70
- data/lib/rails/graphql/request/component/fragment.rb +80 -26
- data/lib/rails/graphql/request/component/operation/subscription.rb +162 -4
- data/lib/rails/graphql/request/component/operation.rb +73 -34
- data/lib/rails/graphql/request/component/spread.rb +79 -27
- data/lib/rails/graphql/request/component/typename.rb +28 -13
- data/lib/rails/graphql/request/component.rb +77 -36
- data/lib/rails/graphql/request/context.rb +19 -9
- data/lib/rails/graphql/request/errors.rb +16 -6
- data/lib/rails/graphql/request/event.rb +23 -8
- data/lib/rails/graphql/request/helpers/directives.rb +69 -27
- data/lib/rails/graphql/request/helpers/selection_set.rb +57 -25
- data/lib/rails/graphql/request/helpers/value_writers.rb +24 -19
- data/lib/rails/graphql/request/prepared_data.rb +100 -0
- data/lib/rails/graphql/request/steps/authorizable.rb +24 -14
- data/lib/rails/graphql/request/steps/organizable.rb +111 -49
- data/lib/rails/graphql/request/steps/{prepareable.rb → preparable.rb} +21 -8
- data/lib/rails/graphql/request/steps/{resolveable.rb → resolvable.rb} +16 -7
- 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 +147 -77
- data/lib/rails/graphql/request/subscription.rb +82 -0
- data/lib/rails/graphql/request.rb +353 -104
- data/lib/rails/graphql/schema.rb +251 -106
- data/lib/rails/graphql/shortcuts.rb +33 -8
- data/lib/rails/graphql/source/active_record/builders.rb +64 -51
- data/lib/rails/graphql/source/active_record_source.rb +158 -82
- data/lib/rails/graphql/source/base.rb +83 -0
- data/lib/rails/graphql/source/builder.rb +115 -0
- data/lib/rails/graphql/source/scoped_arguments.rb +39 -21
- data/lib/rails/graphql/source.rb +90 -228
- data/lib/rails/graphql/subscription/provider/action_cable.rb +113 -0
- data/lib/rails/graphql/subscription/provider/base.rb +192 -0
- data/lib/rails/graphql/subscription/provider.rb +18 -0
- data/lib/rails/graphql/subscription/store/base.rb +141 -0
- data/lib/rails/graphql/subscription/store/memory.rb +136 -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/creator.rb +196 -0
- 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 +44 -50
- data/lib/rails/graphql/type/input.rb +92 -25
- data/lib/rails/graphql/type/interface.rb +29 -28
- data/lib/rails/graphql/type/object/directive_object.rb +10 -9
- 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 +6 -7
- data/lib/rails/graphql/type/object/schema_object.rb +5 -8
- data/lib/rails/graphql/type/object/type_object.rb +62 -25
- data/lib/rails/graphql/type/object.rb +34 -26
- 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 +5 -3
- data/lib/rails/graphql/type/scalar/boolean_scalar.rb +8 -8
- data/lib/rails/graphql/type/scalar/date_scalar.rb +5 -3
- data/lib/rails/graphql/type/scalar/date_time_scalar.rb +5 -3
- data/lib/rails/graphql/type/scalar/decimal_scalar.rb +5 -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 +41 -0
- data/lib/rails/graphql/type/scalar/string_scalar.rb +18 -4
- data/lib/rails/graphql/type/scalar/time_scalar.rb +8 -6
- data/lib/rails/graphql/type/scalar.rb +26 -23
- data/lib/rails/graphql/type/union.rb +21 -18
- data/lib/rails/graphql/type.rb +43 -26
- data/lib/rails/graphql/type_map.rb +268 -165
- data/lib/rails/graphql/uri.rb +167 -0
- data/lib/rails/graphql/version.rb +19 -3
- data/lib/rails/graphql.rake +3 -0
- data/lib/rails/graphql.rb +91 -56
- 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/introspection.gql +2 -0
- data/test/assets/mem.gql +86 -99
- data/test/assets/mysql.gql +406 -0
- data/test/assets/sqlite.gql +96 -73
- data/test/assets/translate.gql +346 -0
- data/test/config.rb +19 -8
- data/test/graphql/schema_test.rb +14 -50
- data/test/graphql/source_test.rb +8 -85
- 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 +12 -9
- data/test/graphql/type/object_test.rb +8 -2
- 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 +63 -81
- 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 +3 -3
- 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 +24 -10
- 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 +89 -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 +73 -0
- data/test/test_ext.rb +16 -13
- metadata +125 -161
- 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
@@ -0,0 +1,88 @@
|
|
1
|
+
module Rails
|
2
|
+
module GraphQL
|
3
|
+
module Helpers
|
4
|
+
# A inherited collection of Hash that can contain simple values, arrays,
|
5
|
+
# or sets
|
6
|
+
class InheritedCollection::Hash < InheritedCollection::Base
|
7
|
+
delegate :transform_values, :transform_keys, to: :to_hash
|
8
|
+
delegate :filter_map, :map, to: :eager
|
9
|
+
|
10
|
+
# Simply go over each definition and check for the given key
|
11
|
+
def key?(value)
|
12
|
+
each_definition.any? { |definition| definition.key?(value) }
|
13
|
+
end
|
14
|
+
|
15
|
+
# Collect all the keys of all the definitions
|
16
|
+
def keys
|
17
|
+
each_definition.reverse_each.flat_map(&:keys).uniq
|
18
|
+
end
|
19
|
+
|
20
|
+
# Go over each key and value
|
21
|
+
def each
|
22
|
+
Enumerator::Lazy.new(keys) do |yielder, key|
|
23
|
+
val = self[key]
|
24
|
+
yield(key, val) if block_given?
|
25
|
+
yielder.yield(key, val)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# Go over each value exclusively
|
30
|
+
def each_value(&block)
|
31
|
+
Enumerator::Lazy.new(keys) do |yielder, key|
|
32
|
+
val = self[key]
|
33
|
+
yield(val) if block_given?
|
34
|
+
yielder.yield(val)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# Go over each key exclusively
|
39
|
+
def each_key(&block)
|
40
|
+
keys.each(&block)
|
41
|
+
end
|
42
|
+
|
43
|
+
# Get all the values by lazy iterating over all the keys
|
44
|
+
def values
|
45
|
+
keys.lazy.map(&method(:[]))
|
46
|
+
end
|
47
|
+
|
48
|
+
# Basically returns the plain result value
|
49
|
+
def to_hash
|
50
|
+
each.to_h
|
51
|
+
end
|
52
|
+
|
53
|
+
# A simple way to get the result of one single key
|
54
|
+
def [](key)
|
55
|
+
lazy[key]
|
56
|
+
end
|
57
|
+
|
58
|
+
# Build a lazy hash
|
59
|
+
def lazy
|
60
|
+
@table ||= Hash.new(&method(_combine? ? :_combined_hash : :_simple_hash))
|
61
|
+
end
|
62
|
+
|
63
|
+
private
|
64
|
+
|
65
|
+
# Check if it has to combine the values
|
66
|
+
def _combine?
|
67
|
+
@type != :hash
|
68
|
+
end
|
69
|
+
|
70
|
+
# Builds a values for a combined hash
|
71
|
+
def _combined_hash(hash, key)
|
72
|
+
hash[key] = each_definition.reverse_each.inject(nil) do |result, definition|
|
73
|
+
next result unless definition.key?(key)
|
74
|
+
next definition[key] if result.nil?
|
75
|
+
result + definition[key]
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
# Builds a values for a simple hash
|
80
|
+
def _simple_hash(hash, key)
|
81
|
+
hash[key] = each_definition.reverse_each do |definition|
|
82
|
+
break definition[key] if definition.key?(key)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -1,15 +1,22 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
module Rails
|
4
|
-
module GraphQL
|
5
|
-
module Helpers
|
6
|
-
module
|
3
|
+
module Rails
|
4
|
+
module GraphQL
|
5
|
+
module Helpers
|
6
|
+
# Helper module that allow classes to have specific type of attributes
|
7
|
+
# that are corretly delt when it is inherited by another class. It keeps
|
8
|
+
# track of its own value and allow access to all values of the property
|
9
|
+
# in the tree,
|
10
|
+
#
|
11
|
+
# TODO: Rewrite this!
|
12
|
+
module InheritedCollection
|
13
|
+
# All possible types of inheritable values
|
7
14
|
DEFAULT_TYPES = {
|
8
15
|
array: '[]',
|
9
16
|
set: 'Set.new',
|
10
17
|
hash: '{}',
|
11
|
-
hash_array: 'Hash.new { |h, k| h[k] = [] }',
|
12
|
-
hash_set: 'Hash.new { |h, k| h[k] = Set.new }',
|
18
|
+
hash_array: '::Hash.new { |h, k| h[k] = [] }',
|
19
|
+
hash_set: '::Hash.new { |h, k| h[k] = Set.new }',
|
13
20
|
}.freeze
|
14
21
|
|
15
22
|
# Declare a class-level attribute whose value is both isolated and also
|
@@ -60,20 +67,19 @@ module Rails # :nodoc:
|
|
60
67
|
type: :set
|
61
68
|
)
|
62
69
|
attrs.each do |name|
|
63
|
-
|
64
|
-
def
|
65
|
-
|
66
|
-
|
67
|
-
end
|
70
|
+
instance_eval(<<~RUBY, __FILE__, __LINE__ + 1)
|
71
|
+
def all_#{name}
|
72
|
+
return superclass.try(:all_#{name}) unless defined?(@#{name})
|
73
|
+
InheritedCollection::Base.handle(self, :@#{name}, :#{type})
|
68
74
|
end
|
69
75
|
|
70
|
-
def
|
76
|
+
def #{name}
|
71
77
|
@#{name} ||= #{DEFAULT_TYPES[type]}
|
72
78
|
end
|
73
79
|
RUBY
|
74
80
|
|
75
|
-
|
76
|
-
def
|
81
|
+
instance_eval(<<~RUBY, __FILE__, __LINE__ + 1) if instance_predicate
|
82
|
+
def #{name}?
|
77
83
|
(defined?(@#{name}) && @#{name}.present?) || superclass.try(:#{name}?)
|
78
84
|
end
|
79
85
|
RUBY
|
@@ -84,69 +90,12 @@ module Rails # :nodoc:
|
|
84
90
|
end
|
85
91
|
end
|
86
92
|
end
|
87
|
-
|
88
|
-
protected
|
89
|
-
|
90
|
-
# Combine an inherited list of arrays
|
91
|
-
def fetch_inherited_array(ivar)
|
92
|
-
inherited_ancestors.each_with_object([]) do |klass, result|
|
93
|
-
next result unless klass.instance_variable_defined?(ivar)
|
94
|
-
val = klass.instance_variable_get(ivar)
|
95
|
-
result.merge(val) unless val.blank?
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
# Combine an inherited list of set objects
|
100
|
-
def fetch_inherited_set(ivar)
|
101
|
-
inherited_ancestors.each_with_object(Set.new) do |klass, result|
|
102
|
-
next result unless klass.instance_variable_defined?(ivar)
|
103
|
-
val = klass.instance_variable_get(ivar)
|
104
|
-
result.merge(val) unless val.blank?
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
# Combine an inherited list of hashes but keeping only the most recent
|
109
|
-
# value, which means that keys might be replaced
|
110
|
-
def fetch_inherited_hash(ivar)
|
111
|
-
inherited_ancestors.each_with_object({}) do |klass, result|
|
112
|
-
next result unless klass.instance_variable_defined?(ivar)
|
113
|
-
val = klass.instance_variable_get(ivar)
|
114
|
-
result.merge!(val) unless val.blank?
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
# Right now we can't use Hash with default proc for equivalency due to
|
119
|
-
# a bug on Ruby https://bugs.ruby-lang.org/issues/17181
|
120
|
-
|
121
|
-
# Combine an inherited list of hashes, which also will combine arrays,
|
122
|
-
# ensuring that same key items will be combined
|
123
|
-
def fetch_inherited_hash_array(ivar)
|
124
|
-
inherited_ancestors.inject({}) do |result, klass|
|
125
|
-
next result unless klass.instance_variable_defined?(ivar)
|
126
|
-
val = klass.instance_variable_get(ivar)
|
127
|
-
Helpers.merge_hash_array(result, val)
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
|
-
# Combine an inherited list of hashes, which also will combine arrays,
|
132
|
-
# ensuring that same key items will be combined
|
133
|
-
def fetch_inherited_hash_set(ivar)
|
134
|
-
inherited_ancestors.inject({}) do |result, klass|
|
135
|
-
next result unless klass.instance_variable_defined?(ivar)
|
136
|
-
val = klass.instance_variable_get(ivar)
|
137
|
-
Helpers.merge_hash_array(result, val)
|
138
|
-
end
|
139
|
-
end
|
140
|
-
|
141
|
-
private
|
142
|
-
|
143
|
-
# Return a list of all the ancestor classes up until object
|
144
|
-
def inherited_ancestors
|
145
|
-
[self].tap do |list|
|
146
|
-
list.unshift(list.first.superclass) until list.first.superclass === Object
|
147
|
-
end
|
148
|
-
end
|
149
93
|
end
|
150
94
|
end
|
151
95
|
end
|
152
96
|
end
|
97
|
+
|
98
|
+
require_relative 'inherited_collection/base'
|
99
|
+
|
100
|
+
require_relative 'inherited_collection/array'
|
101
|
+
require_relative 'inherited_collection/hash'
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Rails
|
4
|
+
module GraphQL
|
5
|
+
module Helpers
|
6
|
+
# This marks an object as instantiable during a requesting, which means it
|
7
|
+
# will be associated with an event and most of it's information comes from
|
8
|
+
# the running event.
|
9
|
+
module Instantiable
|
10
|
+
delegate_missing_to :event
|
11
|
+
attr_reader :event
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
module Rails
|
4
|
-
module GraphQL
|
5
|
-
module Helpers
|
3
|
+
module Rails
|
4
|
+
module GraphQL
|
5
|
+
module Helpers
|
6
6
|
# Helper module allowing leaf values to be collected direct from
|
7
7
|
# ActiveRecord. It also helps AR Adapters to define the necessary
|
8
8
|
# methods and settings to operate with this extractor.
|
@@ -12,10 +12,10 @@ module Rails # :nodoc:
|
|
12
12
|
def self.extended(other)
|
13
13
|
# Defines which type exactly represents the scalar type on the
|
14
14
|
# ActiveRecord adapter for casting purposes
|
15
|
-
other.class_attribute :ar_adapter_type,
|
15
|
+
other.class_attribute :ar_adapter_type, instance_accessor: false, default: {}
|
16
16
|
|
17
17
|
# A list of ActiveRecord aliases per adapter to skip casting
|
18
|
-
other.class_attribute :ar_adapter_aliases,
|
18
|
+
other.class_attribute :ar_adapter_aliases, instance_accessor: false,
|
19
19
|
default: (Hash.new { |h, k| h[k] = Set.new })
|
20
20
|
end
|
21
21
|
|
@@ -87,7 +87,7 @@ module Rails # :nodoc:
|
|
87
87
|
# equivalent
|
88
88
|
def define_for(adapter, **settings)
|
89
89
|
adapter = ar_adapters[adapter] if ar_adapters.key?(adapter)
|
90
|
-
raise ArgumentError,
|
90
|
+
raise ArgumentError, (+<<~MSG).squish unless ar_adapters.values.include?(adapter)
|
91
91
|
The given #{adapter.inspect} adapter is not a valid option.
|
92
92
|
The valid options are: #{ar_adapters.to_a.flatten.map(&:inspect).to_sentence}.
|
93
93
|
MSG
|
@@ -99,7 +99,7 @@ module Rails # :nodoc:
|
|
99
99
|
if settings.key?(:cast)
|
100
100
|
|
101
101
|
ar_adapter_type[adapter] = settings[:type] if settings.key?(:type)
|
102
|
-
ar_adapter_aliases[adapter] += Array.wrap(settings[:aliases]) \
|
102
|
+
ar_adapter_aliases[adapter] += ::Array.wrap(settings[:aliases]) \
|
103
103
|
if settings.key?(:aliases)
|
104
104
|
end
|
105
105
|
|
@@ -1,77 +1,52 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
module Rails
|
4
|
-
module GraphQL
|
5
|
-
module Helpers
|
6
|
-
# Helper module responsible for
|
7
|
-
#
|
8
|
-
# uniqueness of the name of things.
|
3
|
+
module Rails
|
4
|
+
module GraphQL
|
5
|
+
module Helpers
|
6
|
+
# Helper module responsible for registering the objects to the type map,
|
7
|
+
# which also checks for the uniqueness of the name of things.
|
9
8
|
module Registerable
|
10
|
-
NAME_EXP = /GraphQL::(?:Type::\w+::|Directive::)?([:\w]+?)([A-Z][a-z]+)?\z/.freeze
|
11
|
-
|
12
9
|
# Here we define a couple of attributes used by registration
|
13
10
|
def self.extended(other)
|
14
|
-
other.extend(
|
11
|
+
other.extend(Helpers::Unregisterable)
|
15
12
|
other.extend(Helpers::WithNamespace)
|
16
|
-
|
17
|
-
|
18
|
-
# won't appear in the introspection
|
19
|
-
other.class_attribute :abstract, instance_writer: false, default: false
|
13
|
+
other.extend(Helpers::WithName)
|
14
|
+
other.extend(Helpers::WithDescription)
|
20
15
|
|
21
16
|
# Marks if the object is one of those defined on the spec, which
|
22
17
|
# marks the object as part of the introspection system
|
23
|
-
other.class_attribute :spec_object,
|
24
|
-
|
25
|
-
# The given description of the type
|
26
|
-
other.class_attribute :description, instance_writer: false
|
18
|
+
other.class_attribute :spec_object, instance_accessor: false, default: false
|
27
19
|
end
|
28
20
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
return if subclass.try(:abstract)
|
35
|
-
GraphQL.type_map.postpone_registration(subclass)
|
36
|
-
end
|
37
|
-
|
38
|
-
# Check if the class is already registered in the typemap
|
39
|
-
def registered?
|
40
|
-
GraphQL.type_map.object_exist?(self, exclusive: true)
|
41
|
-
end
|
42
|
-
|
43
|
-
# The process to register a class and it's name on the index
|
44
|
-
def register!
|
45
|
-
return if abstract? || gql_name.blank?
|
46
|
-
|
47
|
-
raise DuplicatedError, <<~MSG.squish if registered?
|
48
|
-
The "#{gql_name}" is already defined, the only way to change its
|
49
|
-
definition is by using extensions.
|
50
|
-
MSG
|
51
|
-
|
52
|
-
invalid_internal = !spec_object && gql_name.start_with?('__')
|
53
|
-
raise NameError, <<~MSG.squish if invalid_internal
|
54
|
-
The name "#{gql_name}" is invalid. Only internal objects from the
|
55
|
-
spec can have a name starting with "__".
|
56
|
-
MSG
|
57
|
-
|
58
|
-
super if defined? super
|
59
|
-
GraphQL.type_map.register(self).method(:validate!)
|
60
|
-
end
|
21
|
+
# Here we wait for the class to be fully loaded so that we can
|
22
|
+
# correctly trigger the registration
|
23
|
+
def inherited(subclass)
|
24
|
+
super if defined? super
|
25
|
+
GraphQL.type_map.postpone_registration(subclass)
|
61
26
|
end
|
62
27
|
|
63
|
-
#
|
64
|
-
def
|
65
|
-
|
66
|
-
name.match(NAME_EXP).try(:[], 1)&.tr(':', '')
|
67
|
-
end unless anonymous?
|
28
|
+
# Check if the class is already registered in the type map
|
29
|
+
def registered?
|
30
|
+
GraphQL.type_map.object_exist?(self, exclusive: true)
|
68
31
|
end
|
69
32
|
|
70
|
-
|
33
|
+
# The process to register a class and it's name on the index
|
34
|
+
def register!
|
35
|
+
return if abstract? || gql_name.blank?
|
36
|
+
|
37
|
+
raise DuplicatedError, (+<<~MSG).squish if registered?
|
38
|
+
The "#{gql_name}" is already defined, the only way to change its
|
39
|
+
definition is by using extensions.
|
40
|
+
MSG
|
71
41
|
|
72
|
-
|
73
|
-
|
74
|
-
|
42
|
+
invalid_internal = !spec_object && gql_name.start_with?('__')
|
43
|
+
raise NameError, (+<<~MSG).squish if invalid_internal
|
44
|
+
The name "#{gql_name}" is invalid. Only internal objects from the
|
45
|
+
spec can have a name starting with "__".
|
46
|
+
MSG
|
47
|
+
|
48
|
+
super if defined? super
|
49
|
+
GraphQL.type_map.register(self)
|
75
50
|
end
|
76
51
|
|
77
52
|
# Get or set a list of aliases for this object
|
@@ -85,17 +60,24 @@ module Rails # :nodoc:
|
|
85
60
|
end
|
86
61
|
end
|
87
62
|
|
63
|
+
# TODO: When an object is frozen, it was successfully validated
|
64
|
+
# alias valid? frozen?
|
65
|
+
|
88
66
|
protected
|
89
67
|
|
90
68
|
# An alias for +description = value.strip_heredoc.chomp+ that can be
|
91
69
|
# used as method
|
92
70
|
def desc(value)
|
93
|
-
self.description = value
|
71
|
+
self.description = value
|
94
72
|
end
|
95
73
|
|
96
|
-
|
97
|
-
|
98
|
-
|
74
|
+
def rename!(*)
|
75
|
+
GraphQL.logger.warn((+<<~MSG).squish) if registered?
|
76
|
+
\e[95m[GraphQL] Renaming #{name} after it has being registered
|
77
|
+
may cause unexpected behaviors.\e[0m
|
78
|
+
MSG
|
79
|
+
|
80
|
+
super
|
99
81
|
end
|
100
82
|
end
|
101
83
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Rails
|
4
|
+
module GraphQL
|
5
|
+
module Helpers
|
6
|
+
# Helper that allows unregisterable objects to be both identified and
|
7
|
+
# removed from type map
|
8
|
+
module Unregisterable
|
9
|
+
# Simply remove itself from the type map
|
10
|
+
def unregister!
|
11
|
+
GraphQL.type_map.unregister(self)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
module Rails
|
4
|
-
module GraphQL
|
5
|
-
module Helpers
|
3
|
+
module Rails
|
4
|
+
module GraphQL
|
5
|
+
module Helpers
|
6
6
|
# Helper module that allows other objects to hold arguments
|
7
7
|
module WithArguments
|
8
8
|
def self.extended(other)
|
@@ -13,14 +13,22 @@ module Rails # :nodoc:
|
|
13
13
|
|
14
14
|
def self.included(other)
|
15
15
|
other.define_method(:arguments) do
|
16
|
-
|
16
|
+
@arguments ||= {}
|
17
|
+
end
|
18
|
+
|
19
|
+
other.define_method(:all_arguments) do
|
20
|
+
@arguments if defined?(@arguments)
|
21
|
+
end
|
22
|
+
|
23
|
+
other.define_method(:arguments?) do
|
24
|
+
defined?(@arguments) && @arguments.present?
|
17
25
|
end
|
18
26
|
end
|
19
27
|
|
20
|
-
module ClassMethods
|
28
|
+
module ClassMethods
|
21
29
|
def inherited(subclass)
|
22
30
|
super if defined? super
|
23
|
-
return if arguments.
|
31
|
+
return if arguments.blank?
|
24
32
|
|
25
33
|
new_arguments = Helpers.dup_all_with_owner(arguments.transform_values, subclass)
|
26
34
|
subclass.instance_variable_set(:@arguments, new_arguments)
|
@@ -28,13 +36,13 @@ module Rails # :nodoc:
|
|
28
36
|
end
|
29
37
|
|
30
38
|
def initialize(*args, arguments: nil, **xargs, &block)
|
31
|
-
@arguments =
|
32
|
-
raise ArgumentError,
|
33
|
-
The given "#{
|
39
|
+
@arguments = GraphQL.enumerate(arguments).each_with_object({}) do |item, hash|
|
40
|
+
raise ArgumentError, (+<<~MSG).squish unless item.is_a?(Argument)
|
41
|
+
The given "#{item.inspect}" is not a valid Argument object.
|
34
42
|
MSG
|
35
43
|
|
36
|
-
[
|
37
|
-
end
|
44
|
+
hash[item.name] = Helpers.dup_with_owner(item, self)
|
45
|
+
end unless arguments.nil?
|
38
46
|
|
39
47
|
super(*args, **xargs, &block)
|
40
48
|
end
|
@@ -50,39 +58,34 @@ module Rails # :nodoc:
|
|
50
58
|
super && other.respond_to?(:all_arguments) && match_arguments?(other)
|
51
59
|
end
|
52
60
|
|
53
|
-
# Mostly for correct inheritance on instances
|
54
|
-
def all_arguments
|
55
|
-
defined?(@arguments) ? @arguments : {}
|
56
|
-
end
|
57
|
-
|
58
61
|
# See {Argument}[rdoc-ref:Rails::GraphQL::Argument] class.
|
59
|
-
def argument(name,
|
60
|
-
xargs
|
61
|
-
object = GraphQL::Argument.new(name, base_type, **xargs)
|
62
|
+
def argument(name, type = nil, **xargs)
|
63
|
+
object = GraphQL::Argument.new(name, type, **xargs, owner: self)
|
62
64
|
|
63
|
-
raise DuplicatedError,
|
65
|
+
raise DuplicatedError, (+<<~MSG).squish if has_argument?(object.name)
|
64
66
|
The #{name.inspect} argument is already defined and can't be redefined.
|
65
67
|
MSG
|
66
68
|
|
67
|
-
|
69
|
+
arguments[object.name] = object
|
70
|
+
self
|
68
71
|
rescue DefinitionError => e
|
69
|
-
raise e.class, e.message
|
72
|
+
raise e.class, +"#{e.message}\n Defined at: #{caller(2)[0]}"
|
70
73
|
end
|
71
74
|
|
72
75
|
# Since arguments' owner are more flexible, their instances can be
|
73
76
|
# directly associated to objects that have argument
|
74
77
|
def ref_argument(object)
|
75
|
-
raise ArgumentError,
|
78
|
+
raise ArgumentError, (+<<~MSG).squish unless object.is_a?(GraphQL::Argument)
|
76
79
|
The given object #{object.inspect} is not a valid argument.
|
77
80
|
MSG
|
78
81
|
|
79
|
-
raise DuplicatedError,
|
82
|
+
raise DuplicatedError, (+<<~MSG).squish if has_argument?(object.name)
|
80
83
|
The #{object.name.inspect} argument is already defined and can't be redefined.
|
81
84
|
MSG
|
82
85
|
|
83
86
|
(@arguments ||= {})[object.name] = object
|
84
87
|
rescue DefinitionError => e
|
85
|
-
raise e.class, e.message
|
88
|
+
raise e.class, +"#{e.message}\n Defined at: #{caller(2)[0]}"
|
86
89
|
end
|
87
90
|
|
88
91
|
# A short cute for arguments named and typed as id
|
@@ -110,14 +113,16 @@ module Rails # :nodoc:
|
|
110
113
|
|
111
114
|
# Show all the arguments as their inspect version
|
112
115
|
def inspect_arguments
|
113
|
-
args = all_arguments
|
114
|
-
args.presence && "(#{args.join(', ')})"
|
116
|
+
args = all_arguments&.each_value&.map(&:inspect)
|
117
|
+
args.presence && +"(#{args.join(', ')})"
|
115
118
|
end
|
116
119
|
|
117
120
|
# Check the equivalency of arguments
|
118
121
|
def match_arguments?(other)
|
119
122
|
l_args, r_args = all_arguments, other.all_arguments
|
120
|
-
l_args.
|
123
|
+
l_args.class == r_args.class &&
|
124
|
+
l_args.size <= r_args.size &&
|
125
|
+
l_args.all? { |key, arg| arg =~ r_args[key] }
|
121
126
|
end
|
122
127
|
end
|
123
128
|
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
module Rails
|
4
|
-
module GraphQL
|
5
|
-
module Helpers
|
3
|
+
module Rails
|
4
|
+
module GraphQL
|
5
|
+
module Helpers
|
6
6
|
# Helper module that allows other objects to hold an +assigned_to+ object
|
7
7
|
module WithAssignment
|
8
8
|
# Add extra instance based methods
|
@@ -11,7 +11,7 @@ module Rails # :nodoc:
|
|
11
11
|
:assigned_class, to: :class
|
12
12
|
end
|
13
13
|
|
14
|
-
# Check if the class is
|
14
|
+
# Check if the class is assigned
|
15
15
|
def assigned?
|
16
16
|
assigned_to.present?
|
17
17
|
end
|
@@ -65,7 +65,7 @@ module Rails # :nodoc:
|
|
65
65
|
return result unless (klass = safe_assigned_class)
|
66
66
|
return result if GraphQL.type_map.exist?(klass, namespaces: namespaces)
|
67
67
|
|
68
|
-
GraphQL.type_map.register_alias(klass, namespaces: namespaces
|
68
|
+
GraphQL.type_map.register_alias(klass, to_sym, namespaces: namespaces)
|
69
69
|
result
|
70
70
|
end
|
71
71
|
|
@@ -93,7 +93,7 @@ module Rails # :nodoc:
|
|
93
93
|
klass = klass.superclass
|
94
94
|
end
|
95
95
|
|
96
|
-
message = !block.nil? ? block.call(klass) :
|
96
|
+
message = !block.nil? ? block.call(klass) : (+<<~MSG).squish
|
97
97
|
The "#{klass.name}" is not a subclass of #{base_class.name}.
|
98
98
|
MSG
|
99
99
|
|
@@ -1,15 +1,15 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
module Rails
|
4
|
-
module GraphQL
|
5
|
-
module Helpers
|
3
|
+
module Rails
|
4
|
+
module GraphQL
|
5
|
+
module Helpers
|
6
6
|
# Callbacks is an extension of the events which works with the
|
7
7
|
# {Callback}[rdoc-ref:Rails::GraphQL::Callback] class, then having extra
|
8
|
-
# powers when actually executing the event against
|
9
|
-
#
|
8
|
+
# powers when actually executing the event against Procs or owner-based
|
9
|
+
# methods, when provided a symbol
|
10
10
|
module WithCallbacks
|
11
11
|
DEFAULT_EVENT_TYPES = %i[query mutation subscription request attach
|
12
|
-
authorize organized prepared finalize].freeze
|
12
|
+
authorize organized prepared finalize prepare subscribed].freeze
|
13
13
|
|
14
14
|
def self.extended(other)
|
15
15
|
other.extend(WithCallbacks::Setup)
|
@@ -17,7 +17,7 @@ module Rails # :nodoc:
|
|
17
17
|
|
18
18
|
def self.included(other)
|
19
19
|
other.extend(WithCallbacks::Setup)
|
20
|
-
other.delegate(:event_filters, to: :class)
|
20
|
+
other.delegate(:event_filters, :default_exclusive?, to: :class)
|
21
21
|
end
|
22
22
|
|
23
23
|
# Add the ability to set up filters before the actual execution of the
|
@@ -31,15 +31,32 @@ module Rails # :nodoc:
|
|
31
31
|
# Return the list of event filters hooks
|
32
32
|
def event_filters
|
33
33
|
return @event_filters if defined? @event_filters
|
34
|
-
superclass.try(:event_filters) ||
|
34
|
+
superclass.try(:event_filters) || EMPTY_HASH
|
35
|
+
end
|
36
|
+
|
37
|
+
# Set the default +exclusive+ value for the given +for+ event names
|
38
|
+
def default_exclusive(value, **xargs)
|
39
|
+
new_values = Array.wrap(xargs.fetch(:for)).map(&:to_sym).product([value]).to_h
|
40
|
+
@callback_exclusive ||= superclass.try(:callback_exclusive)&.dup || {}
|
41
|
+
@callback_exclusive.merge!(new_values)
|
42
|
+
end
|
43
|
+
|
44
|
+
# Check if the given +event_name+ should be thread as exclusive or
|
45
|
+
# non-exclusive by default
|
46
|
+
def default_exclusive?(event_name)
|
47
|
+
if defined?(@callback_exclusive)
|
48
|
+
@callback_exclusive[event_name]
|
49
|
+
else
|
50
|
+
superclass.try(:default_exclusive?, event_name)
|
51
|
+
end
|
35
52
|
end
|
36
53
|
|
37
54
|
protected
|
38
55
|
|
39
56
|
# Attach a new key based event filter
|
40
|
-
def event_filter(key,
|
57
|
+
def event_filter(key, &block)
|
41
58
|
@event_filters ||= superclass.try(:event_filters)&.dup || {}
|
42
|
-
@event_filters[key.to_sym] =
|
59
|
+
@event_filters[key.to_sym] = block
|
43
60
|
end
|
44
61
|
end
|
45
62
|
|
@@ -47,7 +64,7 @@ module Rails # :nodoc:
|
|
47
64
|
# {Callback}[rdoc-ref:Rails::GraphQL::Callback] object.
|
48
65
|
def on(event_name, *args, unshift: false, **xargs, &block)
|
49
66
|
block = Callback.new(self, event_name, *args, **xargs, &block)
|
50
|
-
super(event_name, unshift: unshift
|
67
|
+
super(event_name, block, unshift: unshift)
|
51
68
|
end
|
52
69
|
end
|
53
70
|
end
|