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
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
module Rails
|
4
|
-
module GraphQL
|
3
|
+
module Rails
|
4
|
+
module GraphQL
|
5
5
|
# = GraphQL Argument
|
6
6
|
#
|
7
7
|
# This represents an item from the ArgumentsDefinition, which was supposed
|
@@ -31,6 +31,7 @@ module Rails # :nodoc:
|
|
31
31
|
# (defaults to nil).
|
32
32
|
class Argument
|
33
33
|
include Helpers::WithValidator
|
34
|
+
include Helpers::WithDescription
|
34
35
|
|
35
36
|
# TODO: When arguments are attached to output fields they can have
|
36
37
|
# directives so add this possibility
|
@@ -42,19 +43,21 @@ module Rails # :nodoc:
|
|
42
43
|
|
43
44
|
def initialize(
|
44
45
|
name,
|
45
|
-
type,
|
46
|
+
type = nil,
|
46
47
|
owner:,
|
47
48
|
null: true,
|
48
49
|
full: false,
|
49
50
|
array: false,
|
50
51
|
nullable: true,
|
51
52
|
default: nil,
|
52
|
-
desc: nil
|
53
|
+
desc: nil,
|
54
|
+
description: nil
|
53
55
|
)
|
54
56
|
@owner = owner
|
55
57
|
@name = name.to_s.underscore.to_sym
|
56
58
|
@gql_name = @name.to_s.camelize(:lower)
|
57
59
|
|
60
|
+
type = (name == :id ? :id : :string) if type.nil?
|
58
61
|
if type.is_a?(Module) && type < GraphQL::Type
|
59
62
|
@type_klass = type
|
60
63
|
@type = type.name
|
@@ -67,7 +70,8 @@ module Rails # :nodoc:
|
|
67
70
|
@nullable = full ? false : nullable
|
68
71
|
|
69
72
|
@default = default
|
70
|
-
@
|
73
|
+
@default = deserialize(@default) if @default.is_a?(::GQLParser::Token)
|
74
|
+
self.description = desc || description
|
71
75
|
end
|
72
76
|
|
73
77
|
def initialize_copy(*)
|
@@ -114,14 +118,9 @@ module Rails # :nodoc:
|
|
114
118
|
!!@nullable
|
115
119
|
end
|
116
120
|
|
117
|
-
#
|
118
|
-
def description
|
119
|
-
|
120
|
-
end
|
121
|
-
|
122
|
-
# Checks if a description was provided
|
123
|
-
def description?
|
124
|
-
!!@desc
|
121
|
+
# Override to add the kind
|
122
|
+
def description(namespace = nil, *)
|
123
|
+
super(namespace || owner.try(:namespaces), :argument)
|
125
124
|
end
|
126
125
|
|
127
126
|
# Checks if a given default value was provided
|
@@ -149,7 +148,7 @@ module Rails # :nodoc:
|
|
149
148
|
|
150
149
|
# Turn the given value into a ruby object through deserialization
|
151
150
|
def deserialize(value = nil)
|
152
|
-
value =
|
151
|
+
value = as_json if value.nil?
|
153
152
|
|
154
153
|
return if value.nil?
|
155
154
|
return type_klass.deserialize(value) unless array?
|
@@ -174,19 +173,19 @@ module Rails # :nodoc:
|
|
174
173
|
def validate!(*)
|
175
174
|
super if defined? super
|
176
175
|
|
177
|
-
raise NameError,
|
176
|
+
raise NameError, (+<<~MSG).squish if gql_name.start_with?('__')
|
178
177
|
The name "#{gql_name}" is invalid. Argument names cannot start with "__".
|
179
178
|
MSG
|
180
179
|
|
181
|
-
raise ArgumentError,
|
180
|
+
raise ArgumentError, (+<<~MSG).squish unless type_klass.is_a?(Module)
|
182
181
|
Unable to find the "#{type.inspect}" input type on GraphQL context.
|
183
182
|
MSG
|
184
183
|
|
185
|
-
raise ArgumentError,
|
184
|
+
raise ArgumentError, (+<<~MSG).squish unless type_klass.input_type?
|
186
185
|
The "#{type_klass.gql_name}" is not a valid input type.
|
187
186
|
MSG
|
188
187
|
|
189
|
-
raise ArgumentError,
|
188
|
+
raise ArgumentError, (+<<~MSG).squish unless default.nil? || valid?(as_json(default))
|
190
189
|
The given default value "#{default.inspect}" is not valid for this argument.
|
191
190
|
MSG
|
192
191
|
end
|
@@ -198,14 +197,14 @@ module Rails # :nodoc:
|
|
198
197
|
|
199
198
|
alias_method :&, :+
|
200
199
|
|
201
|
-
def inspect
|
202
|
-
result = "#{name}: "
|
203
|
-
result
|
204
|
-
result
|
205
|
-
result
|
206
|
-
result
|
207
|
-
result
|
208
|
-
result
|
200
|
+
def inspect
|
201
|
+
result = +"#{name}: "
|
202
|
+
result << '[' if array?
|
203
|
+
result << type_klass.gql_name
|
204
|
+
result << '!' if array? && !nullable?
|
205
|
+
result << ']' if array?
|
206
|
+
result << '!' unless null?
|
207
|
+
result << " = #{as_json.inspect}" if default_value?
|
209
208
|
result
|
210
209
|
end
|
211
210
|
|
@@ -1,12 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
module Rails
|
4
|
-
module GraphQL
|
3
|
+
module Rails
|
4
|
+
module GraphQL
|
5
5
|
# = Rails GraphQL Callback
|
6
6
|
#
|
7
|
-
# An extra
|
7
|
+
# An extra powerful proc that can handle way more situations than the
|
8
8
|
# original block caller
|
9
9
|
class Callback
|
10
|
+
EXCLUSIVE_ARGUMENT = :exclusive_callback
|
11
|
+
|
10
12
|
attr_reader :event_name, :block, :target, :filters
|
11
13
|
|
12
14
|
delegate :event_filters, to: :target
|
@@ -19,7 +21,7 @@ module Rails # :nodoc:
|
|
19
21
|
end
|
20
22
|
|
21
23
|
def initialize(target, event_name, *args, **xargs, &block)
|
22
|
-
raise ::ArgumentError,
|
24
|
+
raise ::ArgumentError, (+<<~MSG).squish if block.nil? && !args.first.present?
|
23
25
|
Either provide a block or a method name when setting a #{event_name}
|
24
26
|
callback on #{target.inspect}.
|
25
27
|
MSG
|
@@ -27,7 +29,7 @@ module Rails # :nodoc:
|
|
27
29
|
if block.nil?
|
28
30
|
block = args.shift
|
29
31
|
valid_format = block.is_a?(Symbol) || block.is_a?(Proc)
|
30
|
-
raise ::ArgumentError,
|
32
|
+
raise ::ArgumentError, (+<<~MSG).squish unless valid_format
|
31
33
|
The given #{block.class.name} class is not a valid callback.
|
32
34
|
MSG
|
33
35
|
end
|
@@ -35,11 +37,13 @@ module Rails # :nodoc:
|
|
35
37
|
@target = target
|
36
38
|
@event_name = event_name
|
37
39
|
|
40
|
+
@exclusive = xargs.delete(EXCLUSIVE_ARGUMENT)
|
41
|
+
@exclusive = target.try(:default_exclusive?, event_name) if @exclusive.nil?
|
42
|
+
@exclusive = true if @exclusive.nil?
|
43
|
+
|
38
44
|
@pre_args = args
|
39
45
|
@pre_xargs = xargs.slice!(*event_filters.keys)
|
40
|
-
@filters = xargs
|
41
|
-
[key, event_filters[key][:sanitizer]&.call(value) || value]
|
42
|
-
end.to_h
|
46
|
+
@filters = xargs
|
43
47
|
|
44
48
|
@block = block
|
45
49
|
end
|
@@ -47,19 +51,24 @@ module Rails # :nodoc:
|
|
47
51
|
# This does the whole checking and preparation in order to really execute
|
48
52
|
# the callback method
|
49
53
|
def call(event, *args, _callback_context: nil, **xargs)
|
50
|
-
return unless event.
|
54
|
+
return unless event.event_name === event_name && can_run?(event)
|
51
55
|
|
52
56
|
block.is_a?(Symbol) \
|
53
57
|
? call_symbol(event, *args, **xargs) \
|
54
58
|
: call_proc(event, _callback_context, *args, **xargs)
|
55
59
|
end
|
56
60
|
|
61
|
+
# Return if this event is exclusive, so that only the original source of
|
62
|
+
# the callback will be allowed to receive it
|
63
|
+
def exclusive?
|
64
|
+
@exclusive
|
65
|
+
end
|
66
|
+
|
57
67
|
# Get a described source location for the callback
|
58
68
|
def source_location
|
59
|
-
block.is_a?(Proc) ? block.source_location :
|
60
|
-
"(symbolized-callback/#{target.inspect})",
|
61
|
-
|
62
|
-
]
|
69
|
+
block.is_a?(Proc) ? block.source_location : begin
|
70
|
+
[+"(symbolized-callback/#{target.inspect})", block]
|
71
|
+
end
|
63
72
|
end
|
64
73
|
|
65
74
|
# This basically allows the class to be passed as +&block+
|
@@ -80,10 +89,16 @@ module Rails # :nodoc:
|
|
80
89
|
|
81
90
|
# Using the filters, check if the current callback can be executed
|
82
91
|
def can_run?(event)
|
83
|
-
|
92
|
+
return false if exclusive? && !event.same_source?(target)
|
93
|
+
|
94
|
+
filters.all? do |key, options|
|
95
|
+
target.instance_exec(options, event, &event_filters[key])
|
96
|
+
end
|
84
97
|
end
|
85
98
|
|
86
99
|
# Call the callback block as a symbol
|
100
|
+
# TODO: Maybe block calling non-public events
|
101
|
+
# TODO: This is the only reason why directives needs an owner
|
87
102
|
def call_symbol(event, *args, **xargs)
|
88
103
|
event.on_instance(owner) do |instance|
|
89
104
|
block = instance.method(@block)
|
@@ -95,6 +110,7 @@ module Rails # :nodoc:
|
|
95
110
|
# Call the callback block as a proc
|
96
111
|
def call_proc(event, context = nil, *args, **xargs)
|
97
112
|
args, xargs = collect_parameters(event, [args, xargs])
|
113
|
+
args << event unless inject_arguments? || (block.arity - 1) == args.size
|
98
114
|
(context || event).instance_exec(*args, **xargs, &block)
|
99
115
|
end
|
100
116
|
|
@@ -1,6 +1,10 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Rails
|
4
|
+
module GraphQL
|
5
|
+
module Collectors
|
6
|
+
# = GraphQL Hash Collector
|
7
|
+
#
|
4
8
|
# This collector helps building a JSON response using the hash approach,
|
5
9
|
# where the value is kept as an hash and later turn into a string
|
6
10
|
class HashCollector
|
@@ -24,7 +28,12 @@ module Rails # :nodoc:
|
|
24
28
|
|
25
29
|
# Add the given +value+ to the given +key+.
|
26
30
|
def add(key, value)
|
27
|
-
@data.is_a?(Array) ? @data << value : @data[key.to_s] = value
|
31
|
+
@data.is_a?(::Array) ? @data << value : @data[key.to_s] = value
|
32
|
+
end
|
33
|
+
|
34
|
+
# Check if a given +key+ has already been added to the current data
|
35
|
+
def key?(key)
|
36
|
+
!@data.is_a?(::Array) && @data.key?(key)
|
28
37
|
end
|
29
38
|
|
30
39
|
alias safe_add add
|
@@ -36,16 +45,22 @@ module Rails # :nodoc:
|
|
36
45
|
|
37
46
|
# Mark the start of a new element on the array.
|
38
47
|
def next
|
39
|
-
return unless @stack.last.is_a?(Array)
|
48
|
+
return unless @stack.last.is_a?(::Array)
|
40
49
|
@stack.last << @data
|
41
50
|
@data = {}
|
42
51
|
end
|
43
52
|
|
44
|
-
# Append to the
|
53
|
+
# Append to the response all the errors that happened during the
|
45
54
|
# request process
|
46
55
|
def append_errors(errors)
|
47
56
|
return if errors.empty?
|
48
|
-
@data['errors'] = errors.
|
57
|
+
@data['errors'] = errors.as_json
|
58
|
+
end
|
59
|
+
|
60
|
+
# Append to the response anything added to the extensions
|
61
|
+
def append_extensions(extensions)
|
62
|
+
return if extensions.empty?
|
63
|
+
@data['extensions'] = extensions.as_json
|
49
64
|
end
|
50
65
|
|
51
66
|
# Return the generated object
|
@@ -53,6 +68,8 @@ module Rails # :nodoc:
|
|
53
68
|
@data
|
54
69
|
end
|
55
70
|
|
71
|
+
alias as_json to_h
|
72
|
+
|
56
73
|
# Generate the JSON string result
|
57
74
|
def to_s
|
58
75
|
GraphQL.config.encode_with_active_support? \
|
@@ -60,6 +77,8 @@ module Rails # :nodoc:
|
|
60
77
|
: ::JSON.generate(@data)
|
61
78
|
end
|
62
79
|
|
80
|
+
alias to_json to_s
|
81
|
+
|
63
82
|
private
|
64
83
|
|
65
84
|
# Start a new part of the collector. When set +as_array+, the result
|
@@ -1,11 +1,14 @@
|
|
1
|
-
module Rails
|
2
|
-
module GraphQL
|
3
|
-
module Collectors
|
4
|
-
#
|
1
|
+
module Rails
|
2
|
+
module GraphQL
|
3
|
+
module Collectors
|
4
|
+
# = GraphQL Idented Collector
|
5
|
+
#
|
6
|
+
# This collector helps building a indented string, most used for
|
7
|
+
# displaying a GraphQL schema
|
5
8
|
class IdentedCollector
|
6
9
|
def initialize(initial = 0, size = 2, auto_eol: true)
|
7
10
|
@size = size
|
8
|
-
@val = [[initial, '']]
|
11
|
+
@val = [[initial, +'']]
|
9
12
|
@auto_eol = auto_eol
|
10
13
|
end
|
11
14
|
|
@@ -50,13 +53,13 @@ module Rails # :nodoc:
|
|
50
53
|
|
51
54
|
def indent
|
52
55
|
return @val.last[0] += @size if blank?
|
53
|
-
@val << [last_ident + @size, '']
|
56
|
+
@val << [last_ident + @size, +'']
|
54
57
|
self
|
55
58
|
end
|
56
59
|
|
57
60
|
def unindent
|
58
61
|
return @val.last[0] -= @size if blank?
|
59
|
-
@val << [last_ident - @size, '']
|
62
|
+
@val << [last_ident - @size, +'']
|
60
63
|
self
|
61
64
|
end
|
62
65
|
|
@@ -1,16 +1,21 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
module Rails
|
4
|
-
module GraphQL
|
5
|
-
module Collectors
|
3
|
+
module Rails
|
4
|
+
module GraphQL
|
5
|
+
module Collectors
|
6
|
+
# = GraphQL JSON Collector
|
7
|
+
#
|
6
8
|
# This collector helps building a JSON response using the string approach,
|
7
9
|
# which has better performance, since all the encoding is performed up
|
8
|
-
# front. The drawback is that it can't return
|
10
|
+
# front. The drawback is that it can't return a hash.
|
9
11
|
class JsonCollector
|
10
12
|
def initialize(request)
|
11
13
|
@request = request
|
12
14
|
|
13
|
-
@
|
15
|
+
@current_keys = Set.new
|
16
|
+
@stack_keys = []
|
17
|
+
|
18
|
+
@current_value = StringIO.new
|
14
19
|
@stack_value = []
|
15
20
|
|
16
21
|
@current_array = false
|
@@ -30,31 +35,41 @@ module Rails # :nodoc:
|
|
30
35
|
pop_size = array && !plain ? 2 : 1
|
31
36
|
@current_value = @stack_value.pop(pop_size).first
|
32
37
|
@current_array = @stack_array.pop(pop_size).first
|
38
|
+
@current_keys = @stack_keys.pop
|
33
39
|
raise
|
34
40
|
end
|
35
41
|
|
36
|
-
# Append to the
|
42
|
+
# Append to the response data all the errors that happened during the
|
37
43
|
# request process.
|
38
44
|
def append_errors(errors)
|
39
45
|
return if errors.empty?
|
40
46
|
add('errors', errors.to_json)
|
41
47
|
end
|
42
48
|
|
49
|
+
# Append to the response anything added to the extensions
|
50
|
+
def append_extensions(extensions)
|
51
|
+
return if extensions.empty?
|
52
|
+
add('extensions', extensions.to_json)
|
53
|
+
end
|
54
|
+
|
43
55
|
# Add the given +value+ to the given +key+. Ensure to encode the value
|
44
56
|
# before calling this function.
|
45
57
|
def add(key, value)
|
46
|
-
(@current_value << ',')
|
58
|
+
(@current_value << ',') if @current_value.pos > 0
|
59
|
+
@current_keys << key
|
47
60
|
|
48
61
|
if @current_array
|
49
62
|
@current_value << value
|
50
63
|
else
|
51
|
-
@current_value << '"'
|
52
|
-
@current_value << key.to_s
|
53
|
-
@current_value << '":'
|
54
|
-
@current_value << value.to_s
|
64
|
+
@current_value << '"' << +key.to_s << '"' << ':' << +value.to_s
|
55
65
|
end
|
56
66
|
end
|
57
67
|
|
68
|
+
# Check if the given +key+ has been added already
|
69
|
+
def key?(key)
|
70
|
+
@current_keys.include?(key)
|
71
|
+
end
|
72
|
+
|
58
73
|
# Same as +add+ but this always encode the +value+ beforehand.
|
59
74
|
def safe_add(key, value)
|
60
75
|
add(key, value.nil? ? 'null' : value.to_json)
|
@@ -68,32 +83,42 @@ module Rails # :nodoc:
|
|
68
83
|
# Mark the start of a new element on the array.
|
69
84
|
def next
|
70
85
|
return unless @stack_array.last === :complex
|
71
|
-
(@stack_value.last << ',')
|
86
|
+
(@stack_value.last << ',') if @stack_value.last.pos > 0
|
72
87
|
@stack_value.last << to_s
|
73
|
-
|
88
|
+
|
89
|
+
@current_value = StringIO.new
|
90
|
+
@current_keys = Set.new
|
74
91
|
end
|
75
92
|
|
76
93
|
# Get the current result
|
77
94
|
def to_s
|
78
|
-
@current_array
|
95
|
+
if @current_array
|
96
|
+
+'[' << @current_value.string << ']'
|
97
|
+
else
|
98
|
+
+'{' << @current_value.string << '}'
|
99
|
+
end
|
79
100
|
end
|
80
101
|
|
102
|
+
alias to_json to_s
|
103
|
+
|
81
104
|
private
|
82
105
|
|
83
106
|
# Start a new part of the collector. When set +as_array+, the result
|
84
|
-
# of the stack will be
|
107
|
+
# of the stack will be enclosed by +[]+.
|
85
108
|
def start_stack(as_array = false, plain_array = false)
|
86
109
|
@stack_value << @current_value
|
87
110
|
@stack_array << @current_array
|
111
|
+
@stack_keys << @current_keys
|
88
112
|
|
89
113
|
if as_array && !plain_array
|
90
|
-
@stack_value <<
|
114
|
+
@stack_value << StringIO.new
|
91
115
|
@stack_array << :complex
|
92
116
|
as_array = false
|
93
117
|
end
|
94
118
|
|
95
|
-
@current_value =
|
119
|
+
@current_value = StringIO.new
|
96
120
|
@current_array = as_array
|
121
|
+
@current_keys = Set.new
|
97
122
|
end
|
98
123
|
|
99
124
|
# Finalize a stack and set the result on the given +key+.
|
@@ -106,6 +131,7 @@ module Rails # :nodoc:
|
|
106
131
|
result = to_s
|
107
132
|
@current_value = @stack_value.pop
|
108
133
|
@current_array = @stack_array.pop
|
134
|
+
@current_keys = @stack_keys.pop
|
109
135
|
add(key, result)
|
110
136
|
end
|
111
137
|
end
|
@@ -1,14 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
module Rails
|
4
|
-
module GraphQL
|
5
|
-
|
3
|
+
module Rails
|
4
|
+
module GraphQL
|
5
|
+
# All the possible collectors that uses the reverse visit approach
|
6
|
+
module Collectors
|
6
7
|
extend ActiveSupport::Autoload
|
7
8
|
|
8
9
|
autoload :HashCollector
|
9
10
|
autoload :IdentedCollector
|
10
11
|
autoload :JsonCollector
|
11
|
-
|
12
12
|
end
|
13
13
|
end
|
14
14
|
end
|