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
@@ -1,16 +1,18 @@
|
|
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
|
-
@current_value =
|
15
|
+
@current_value = StringIO.new
|
14
16
|
@stack_value = []
|
15
17
|
|
16
18
|
@current_array = false
|
@@ -33,7 +35,7 @@ module Rails # :nodoc:
|
|
33
35
|
raise
|
34
36
|
end
|
35
37
|
|
36
|
-
# Append to the
|
38
|
+
# Append to the response data all the errors that happened during the
|
37
39
|
# request process.
|
38
40
|
def append_errors(errors)
|
39
41
|
return if errors.empty?
|
@@ -43,15 +45,12 @@ module Rails # :nodoc:
|
|
43
45
|
# Add the given +value+ to the given +key+. Ensure to encode the value
|
44
46
|
# before calling this function.
|
45
47
|
def add(key, value)
|
46
|
-
(@current_value << ',')
|
48
|
+
(@current_value << ',') if @current_value.pos > 0
|
47
49
|
|
48
50
|
if @current_array
|
49
51
|
@current_value << value
|
50
52
|
else
|
51
|
-
@current_value << '"'
|
52
|
-
@current_value << key.to_s
|
53
|
-
@current_value << '":'
|
54
|
-
@current_value << value.to_s
|
53
|
+
@current_value << '"' << +key.to_s << '"' << ':' << +value.to_s
|
55
54
|
end
|
56
55
|
end
|
57
56
|
|
@@ -68,31 +67,37 @@ module Rails # :nodoc:
|
|
68
67
|
# Mark the start of a new element on the array.
|
69
68
|
def next
|
70
69
|
return unless @stack_array.last === :complex
|
71
|
-
(@stack_value.last << ',')
|
70
|
+
(@stack_value.last << ',') if @stack_value.last.pos > 0
|
72
71
|
@stack_value.last << to_s
|
73
|
-
@current_value =
|
72
|
+
@current_value = StringIO.new
|
74
73
|
end
|
75
74
|
|
76
75
|
# Get the current result
|
77
76
|
def to_s
|
78
|
-
@current_array
|
77
|
+
if @current_array
|
78
|
+
+'[' << @current_value.string << ']'
|
79
|
+
else
|
80
|
+
+'{' << @current_value.string << '}'
|
81
|
+
end
|
79
82
|
end
|
80
83
|
|
84
|
+
alias to_json to_s
|
85
|
+
|
81
86
|
private
|
82
87
|
|
83
88
|
# Start a new part of the collector. When set +as_array+, the result
|
84
|
-
# of the stack will be
|
89
|
+
# of the stack will be enclosed by +[]+.
|
85
90
|
def start_stack(as_array = false, plain_array = false)
|
86
91
|
@stack_value << @current_value
|
87
92
|
@stack_array << @current_array
|
88
93
|
|
89
94
|
if as_array && !plain_array
|
90
|
-
@stack_value <<
|
95
|
+
@stack_value << StringIO.new
|
91
96
|
@stack_array << :complex
|
92
97
|
as_array = false
|
93
98
|
end
|
94
99
|
|
95
|
-
@current_value =
|
100
|
+
@current_value = StringIO.new
|
96
101
|
@current_array = as_array
|
97
102
|
end
|
98
103
|
|
@@ -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
|
data/lib/rails/graphql/config.rb
CHANGED
@@ -1,61 +1,176 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
module Rails
|
4
|
-
module GraphQL
|
3
|
+
module Rails
|
4
|
+
module GraphQL
|
5
5
|
configure do |config|
|
6
|
-
# This
|
6
|
+
# This helps to keep track of when things were cached and registered.
|
7
|
+
# Cached objects with mismatching versions needs to be upgraded or simply
|
8
|
+
# reloaded. A good way to use this is to set to the commit hash, but
|
9
|
+
# beware to stick to 8 characters.
|
10
|
+
config.version = nil
|
11
|
+
|
12
|
+
# This will be automatically mapped to +Rails.cache+. Manually setting
|
13
|
+
# this property means that the object in it complies with
|
14
|
+
# +ActiveSupport::Cache::Store+.
|
15
|
+
config.cache = nil
|
16
|
+
|
17
|
+
# If Rails cache is not properly defined, by default it is set to a
|
18
|
+
# NullStore, than fallback to this option to get a memory store because
|
19
|
+
# cache is extremely important, especially for subscriptions
|
20
|
+
config.cache_fallback = -> do
|
21
|
+
::ActiveSupport::Cache::MemoryStore.new(max_prune_time: nil)
|
22
|
+
end
|
23
|
+
|
24
|
+
# This is the prefix key of all the cache entries for the GraphQL cached
|
25
|
+
# things.
|
26
|
+
config.cache_prefix = 'graphql/'
|
27
|
+
|
28
|
+
# The list of nested paths inside of the graphql folder that does not
|
29
|
+
# require to be in their own namespace.
|
30
|
+
config.paths = %w[directives fields sources enums inputs interfaces object
|
31
|
+
scalars unions].to_set
|
32
|
+
|
33
|
+
# This exposes the clean path from where a GraphQL request was started.
|
7
34
|
config.verbose_logs = true
|
8
35
|
|
36
|
+
# The list of parameters to omit from logger when running a GraphQL
|
37
|
+
# request. Those values will be better displayed in the internal runtime
|
38
|
+
# logger controller.
|
39
|
+
config.omit_parameters = %w[query operationName operation_name variables graphql]
|
40
|
+
|
41
|
+
# This list will actually affect what is displayed in the logs. When it is
|
42
|
+
# set to nil, it will copy its value from Rails +filter_parameters+.
|
43
|
+
config.filter_parameters = nil
|
44
|
+
|
9
45
|
# A list of ActiveRecord adapters and their specific internal naming used
|
10
|
-
# to compound the accessors for direct query serialization
|
46
|
+
# to compound the accessors for direct query serialization.
|
11
47
|
config.ar_adapters = {
|
12
|
-
'Mysql2' => :mysql,
|
13
|
-
'PostgreSQL' => :pg,
|
14
|
-
'SQLite' => :sqlite,
|
48
|
+
'Mysql2' => { key: :mysql, path: "#{__dir__}/adapters/mysql_adapter" },
|
49
|
+
'PostgreSQL' => { key: :pg, path: "#{__dir__}/adapters/pg_adapter" },
|
50
|
+
'SQLite' => { key: :sqlite, path: "#{__dir__}/adapters/sqlite_adapter" },
|
15
51
|
}
|
16
52
|
|
17
53
|
# For all the input object type defined, auto add the following prefix to
|
18
54
|
# their name, so we don't have to define classes like +PointInputInput+.
|
19
55
|
config.auto_suffix_input_objects = 'Input'
|
20
56
|
|
57
|
+
# Introspection is enabled by default. Changing this will affect all the
|
58
|
+
# schemas off the application and reduce memory usage. This can also be
|
59
|
+
# set at per schema.
|
60
|
+
config.enable_introspection = true
|
61
|
+
|
62
|
+
# Define the names of the schema/operations types. The single "_" is a
|
63
|
+
# suggestion so that in an application that has, most likely, a
|
64
|
+
# Subscription type, it does not generate a conflict. Plus, it is easy to
|
65
|
+
# spot that it is something internal.
|
66
|
+
config.schema_type_names = {
|
67
|
+
query: '_Query',
|
68
|
+
mutation: '_Mutation',
|
69
|
+
subscription: '_Subscription',
|
70
|
+
}
|
71
|
+
|
21
72
|
# For performance purposes, this gem implements a
|
22
73
|
# {JsonCollector}[rdoc-ref:Rails::GraphQL::Collectors::JsonCollector].
|
23
74
|
# If you prefer to use the normal hash to string serialization, you can
|
24
75
|
# disable this option.
|
25
76
|
config.enable_string_collector = true
|
26
77
|
|
78
|
+
# Set what is de default expected output type of GraphQL requests. String
|
79
|
+
# combined with the previous setting has the best performance. On console,
|
80
|
+
# it will automatically shift to hash.
|
81
|
+
config.default_response_format = :string
|
82
|
+
|
27
83
|
# Specifies if the results of operations should be encoded with
|
28
84
|
# +ActiveSupport::JSON#encode+ instead of the default +JSON#generate+.
|
29
85
|
# See also https://github.com/rails/rails/blob/master/activesupport/lib/active_support/json/encoding.rb
|
30
86
|
config.encode_with_active_support = false
|
31
87
|
|
32
|
-
# Enable the ability of a callback to dynamically inject
|
88
|
+
# Enable the ability of a callback to dynamically inject arguments to the
|
33
89
|
# calling method.
|
34
90
|
config.callback_inject_arguments = true
|
35
91
|
|
36
|
-
# Enable the ability of a callback to dynamically inject named
|
92
|
+
# Enable the ability of a callback to dynamically inject named arguments
|
37
93
|
# to the calling method.
|
38
94
|
config.callback_inject_named_arguments = true
|
39
95
|
|
96
|
+
# When importing fields into other places, if the given class is
|
97
|
+
# incompatible it will display an warning. This can make such warning be
|
98
|
+
# silenced.
|
99
|
+
config.silence_import_warnings = false
|
100
|
+
|
101
|
+
# Enable the ability to active custom descriptions using i18n
|
102
|
+
config.enable_i18n_descriptions = true
|
103
|
+
|
104
|
+
# Specify the scopes for I18n translations
|
105
|
+
config.i18n_scopes = [
|
106
|
+
'graphql.%{namespace}.%{kind}.%{parent}.%{name}',
|
107
|
+
'graphql.%{namespace}.%{kind}.%{name}',
|
108
|
+
'graphql.%{namespace}.%{name}',
|
109
|
+
'graphql.%{kind}.%{parent}.%{name}',
|
110
|
+
'graphql.%{kind}.%{name}',
|
111
|
+
'graphql.%{name}'
|
112
|
+
]
|
113
|
+
|
40
114
|
# A list of execution strategies. Each application can add their own by
|
41
115
|
# simply append a class name, preferable as string, in this list.
|
42
116
|
config.request_strategies = [
|
43
117
|
'Rails::GraphQL::Request::Strategy::MultiQueryStrategy',
|
44
118
|
'Rails::GraphQL::Request::Strategy::SequencedStrategy',
|
119
|
+
# 'Rails::GraphQL::Request::Strategy::CachedStrategy',
|
120
|
+
]
|
121
|
+
|
122
|
+
# A list of all possible rails-graphql-compatible sources.
|
123
|
+
config.sources = [
|
124
|
+
'Rails::GraphQL::Source::ActiveRecordSource',
|
125
|
+
]
|
126
|
+
|
127
|
+
# A list of all available subscription providers which bases on
|
128
|
+
# Rails::GraphQL::SubscriptionProvider::Base
|
129
|
+
config.subscription_providers = [
|
130
|
+
'Rails::GraphQL::Subscription::Provider::ActionCable',
|
45
131
|
]
|
46
132
|
|
133
|
+
# The default subscription provider for all the schemas
|
134
|
+
config.default_subscription_provider = config.subscription_providers.first
|
135
|
+
|
136
|
+
# The default value for fields about their ability of being broadcasted
|
137
|
+
config.default_subscription_broadcastable = nil
|
138
|
+
|
139
|
+
# A list of known dependencies that can be requested and included in any
|
140
|
+
# schema. This is the best place for other gems to add their own
|
141
|
+
# dependencies and allow users to pick them.
|
142
|
+
config.known_dependencies = {
|
143
|
+
scalar: {
|
144
|
+
any: "#{__dir__}/type/scalar/any_scalar",
|
145
|
+
bigint: "#{__dir__}/type/scalar/bigint_scalar",
|
146
|
+
binary: "#{__dir__}/type/scalar/binary_scalar",
|
147
|
+
date_time: "#{__dir__}/type/scalar/date_time_scalar",
|
148
|
+
date: "#{__dir__}/type/scalar/date_scalar",
|
149
|
+
decimal: "#{__dir__}/type/scalar/decimal_scalar",
|
150
|
+
time: "#{__dir__}/type/scalar/time_scalar",
|
151
|
+
json: "#{__dir__}/type/scalar/json_scalar",
|
152
|
+
},
|
153
|
+
directive: {
|
154
|
+
# cached: "#{__dir__}/directive/cached_directive",
|
155
|
+
},
|
156
|
+
}
|
157
|
+
|
158
|
+
# The method that should be used to parse literal input values when they
|
159
|
+
# are provided as hash. +JSON.parse+ only supports keys wrapped in quotes,
|
160
|
+
# to support keys without quotes, you can use +Psych.method(:safe_load)+,
|
161
|
+
# which behaves closer to YAML, but the received value is ensure to be
|
162
|
+
# wrapped in "{}". If that produces unexpected results, you can assign a
|
163
|
+
# proc and then parse the value in any other way, like
|
164
|
+
# +->(value) { anything }+
|
165
|
+
config.literal_input_parser = JSON.method(:parse)
|
166
|
+
|
47
167
|
# TODO: To be implemented
|
48
|
-
# enable_i18n_descriptions
|
49
|
-
# enable_auto_descriptions
|
50
168
|
# allow_query_serialization
|
51
|
-
# source_generate_dependencies
|
52
169
|
end
|
53
170
|
|
54
171
|
# This is the logger for all the operations for GraphQL
|
55
172
|
def self.logger
|
56
|
-
config.logger ||= ActiveSupport::TaggedLogging.new(
|
57
|
-
ActiveSupport::Logger.new(STDOUT),
|
58
|
-
)
|
173
|
+
config.logger ||= ActiveSupport::TaggedLogging.new(ActiveSupport::Logger.new(STDOUT))
|
59
174
|
end
|
60
175
|
end
|
61
176
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Rails
|
4
|
+
module GraphQL
|
5
|
+
# = GraphQL Cached Directive
|
6
|
+
#
|
7
|
+
# Indicates that the request has hard cached operations that need to be
|
8
|
+
# collected
|
9
|
+
class Directive::CachedDirective < Directive
|
10
|
+
placed_on :query
|
11
|
+
|
12
|
+
desc 'Indicates that there are hard cached operations.'
|
13
|
+
|
14
|
+
argument :id, :ID, null: false, desc: <<~DESC
|
15
|
+
The unique identifier of the cached operation.
|
16
|
+
DESC
|
17
|
+
|
18
|
+
on(:attach) do |source, request|
|
19
|
+
source.data.selection = nil
|
20
|
+
# TODO: Add the request name back
|
21
|
+
# source.instance_variable_set(:@name, 'here')
|
22
|
+
|
23
|
+
# TODO: Add the arguments and variables
|
24
|
+
field = request.build(Request::Component::Field, source, nil, { name: 'a', alias: 'b' })
|
25
|
+
field.assing_to(ApplicationSchema[:query][:a])
|
26
|
+
field.check_authorization!
|
27
|
+
|
28
|
+
source.instance_variable_set(:@selection, { 'b' => field })
|
29
|
+
# puts source.inspect
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -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 Spec Deprecated Directive
|
6
6
|
#
|
7
7
|
# Mark fields or enum values as deprecated which will include an error
|
@@ -12,7 +12,7 @@ module Rails # :nodoc:
|
|
12
12
|
placed_on :field_definition, :enum_value
|
13
13
|
|
14
14
|
desc <<~DESC
|
15
|
-
Indicate deprecated portions of a GraphQL service
|
15
|
+
Indicate deprecated portions of a GraphQL service's schema, such as deprecated
|
16
16
|
fields on a type or deprecated enum values.
|
17
17
|
DESC
|
18
18
|
|
@@ -22,11 +22,11 @@ module Rails # :nodoc:
|
|
22
22
|
using Markdown syntax (as specified by [CommonMark](http://commonmark.org/)).
|
23
23
|
DESC
|
24
24
|
|
25
|
-
on
|
25
|
+
on(:organized) do |event|
|
26
26
|
report_for_field(event)
|
27
27
|
end
|
28
28
|
|
29
|
-
on
|
29
|
+
on(:finalize, for: Type::Enum) do |event|
|
30
30
|
report_for_enum_value(event)
|
31
31
|
end
|
32
32
|
|
@@ -35,7 +35,7 @@ module Rails # :nodoc:
|
|
35
35
|
# Check if the requested field is marked as deprecated
|
36
36
|
def report_for_field(event)
|
37
37
|
return unless event.field.using?(self.class)
|
38
|
-
item = "#{event.source.gql_name} field"
|
38
|
+
item = +"#{event.source.gql_name} field"
|
39
39
|
event.request.report_error(build_message(item))
|
40
40
|
end
|
41
41
|
|
@@ -44,15 +44,15 @@ module Rails # :nodoc:
|
|
44
44
|
return unless event.current_value.deprecated?
|
45
45
|
|
46
46
|
value = event.current_value.to_s
|
47
|
-
item = "#{value} value for the #{event.source.gql_name} field"
|
47
|
+
item = +"#{value} value for the #{event.source.gql_name} field"
|
48
48
|
event.request.report_error(build_message(item))
|
49
49
|
end
|
50
50
|
|
51
51
|
# Build the error message to display on the result
|
52
52
|
def build_message(item)
|
53
|
-
result = "The #{item} is deprecated"
|
54
|
-
result
|
55
|
-
result
|
53
|
+
result = +"The #{item} is deprecated"
|
54
|
+
result << ", reason: #{args.reason}" if args.reason.present?
|
55
|
+
result << '.'
|
56
56
|
end
|
57
57
|
end
|
58
58
|
end
|
@@ -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 Spec Include Directive
|
6
6
|
#
|
7
7
|
# Allow including fields only +if+ condition is true
|
@@ -16,8 +16,9 @@ module Rails # :nodoc:
|
|
16
16
|
When false, the underlying element will be automatically marked as null.
|
17
17
|
DESC
|
18
18
|
|
19
|
-
|
20
|
-
|
19
|
+
# TODO: On attach does not covers default value per operation variable scenario
|
20
|
+
on(:attach) do |source|
|
21
|
+
source.skip! unless args[:if]
|
21
22
|
end
|
22
23
|
end
|
23
24
|
end
|
@@ -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 Spec Skip Directive
|
6
6
|
#
|
7
7
|
# Allow skipping fields given an +if+ condition
|
@@ -16,8 +16,9 @@ module Rails # :nodoc:
|
|
16
16
|
When true, the underlying element will be automatically marked as null.
|
17
17
|
DESC
|
18
18
|
|
19
|
-
|
20
|
-
|
19
|
+
# TODO: On attach does not covers default value per operation variable scenario
|
20
|
+
on(:attach) do |source|
|
21
|
+
source.skip! if args[:if]
|
21
22
|
end
|
22
23
|
end
|
23
24
|
end
|