graphql 1.7.6 → 1.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/generators/graphql/function_generator.rb +1 -1
- data/lib/generators/graphql/install_generator.rb +14 -8
- data/lib/generators/graphql/loader_generator.rb +1 -1
- data/lib/generators/graphql/mutation_generator.rb +6 -1
- data/lib/generators/graphql/templates/function.erb +2 -2
- data/lib/generators/graphql/templates/loader.erb +2 -2
- data/lib/generators/graphql/templates/schema.erb +1 -1
- data/lib/graphql/argument.rb +25 -19
- data/lib/graphql/backtrace/tracer.rb +16 -22
- data/lib/graphql/backtrace.rb +1 -1
- data/lib/graphql/backwards_compatibility.rb +2 -3
- data/lib/graphql/base_type.rb +31 -31
- data/lib/graphql/compatibility/query_parser_specification/parse_error_specification.rb +14 -0
- data/lib/graphql/compatibility/query_parser_specification.rb +117 -0
- data/lib/graphql/define/assign_object_field.rb +5 -12
- data/lib/graphql/deprecated_dsl.rb +42 -0
- data/lib/graphql/directive.rb +1 -0
- data/lib/graphql/enum_type.rb +3 -1
- data/lib/graphql/execution/execute.rb +21 -13
- data/lib/graphql/execution/instrumentation.rb +82 -0
- data/lib/graphql/execution/lazy/lazy_method_map.rb +1 -1
- data/lib/graphql/execution/lazy/resolve.rb +1 -3
- data/lib/graphql/execution/multiplex.rb +12 -29
- data/lib/graphql/execution.rb +1 -0
- data/lib/graphql/field.rb +21 -4
- data/lib/graphql/function.rb +14 -0
- data/lib/graphql/input_object_type.rb +3 -1
- data/lib/graphql/interface_type.rb +5 -3
- data/lib/graphql/internal_representation/node.rb +26 -14
- data/lib/graphql/internal_representation/visit.rb +3 -6
- data/lib/graphql/introspection/base_object.rb +16 -0
- data/lib/graphql/introspection/directive_location_enum.rb +11 -7
- data/lib/graphql/introspection/directive_type.rb +23 -16
- data/lib/graphql/introspection/dynamic_fields.rb +11 -0
- data/lib/graphql/introspection/entry_points.rb +29 -0
- data/lib/graphql/introspection/enum_value_type.rb +16 -11
- data/lib/graphql/introspection/field_type.rb +21 -12
- data/lib/graphql/introspection/input_value_type.rb +26 -23
- data/lib/graphql/introspection/schema_field.rb +7 -2
- data/lib/graphql/introspection/schema_type.rb +36 -22
- data/lib/graphql/introspection/type_by_name_field.rb +10 -2
- data/lib/graphql/introspection/type_kind_enum.rb +10 -6
- data/lib/graphql/introspection/type_type.rb +85 -23
- data/lib/graphql/introspection/typename_field.rb +1 -0
- data/lib/graphql/introspection.rb +3 -10
- data/lib/graphql/language/block_string.rb +47 -0
- data/lib/graphql/language/document_from_schema_definition.rb +280 -0
- data/lib/graphql/language/generation.rb +3 -182
- data/lib/graphql/language/lexer.rb +144 -69
- data/lib/graphql/language/lexer.rl +15 -4
- data/lib/graphql/language/nodes.rb +141 -78
- data/lib/graphql/language/parser.rb +677 -630
- data/lib/graphql/language/parser.y +18 -12
- data/lib/graphql/language/printer.rb +361 -0
- data/lib/graphql/language/token.rb +10 -3
- data/lib/graphql/language.rb +3 -0
- data/lib/graphql/non_null_type.rb +1 -1
- data/lib/graphql/object_type.rb +1 -6
- data/lib/graphql/query/arguments.rb +63 -32
- data/lib/graphql/query/context.rb +32 -2
- data/lib/graphql/query/literal_input.rb +4 -1
- data/lib/graphql/query/null_context.rb +1 -1
- data/lib/graphql/query/result.rb +1 -1
- data/lib/graphql/query/variables.rb +21 -3
- data/lib/graphql/query.rb +19 -6
- data/lib/graphql/railtie.rb +109 -0
- data/lib/graphql/relay/connection_resolve.rb +3 -0
- data/lib/graphql/relay/connection_type.rb +5 -3
- data/lib/graphql/relay/edge_type.rb +2 -1
- data/lib/graphql/relay/global_id_resolve.rb +5 -1
- data/lib/graphql/relay/mongo_relation_connection.rb +40 -0
- data/lib/graphql/relay/mutation/instrumentation.rb +1 -1
- data/lib/graphql/relay/mutation/resolve.rb +5 -1
- data/lib/graphql/relay/relation_connection.rb +14 -19
- data/lib/graphql/relay/type_extensions.rb +30 -0
- data/lib/graphql/relay.rb +2 -0
- data/lib/graphql/scalar_type.rb +14 -2
- data/lib/graphql/schema/argument.rb +92 -0
- data/lib/graphql/schema/build_from_definition.rb +64 -18
- data/lib/graphql/schema/enum.rb +85 -0
- data/lib/graphql/schema/enum_value.rb +74 -0
- data/lib/graphql/schema/field.rb +372 -0
- data/lib/graphql/schema/finder.rb +153 -0
- data/lib/graphql/schema/input_object.rb +87 -0
- data/lib/graphql/schema/interface.rb +105 -0
- data/lib/graphql/schema/introspection_system.rb +93 -0
- data/lib/graphql/schema/late_bound_type.rb +32 -0
- data/lib/graphql/schema/list.rb +32 -0
- data/lib/graphql/schema/loader.rb +2 -2
- data/lib/graphql/schema/member/accepts_definition.rb +152 -0
- data/lib/graphql/schema/member/base_dsl_methods.rb +100 -0
- data/lib/graphql/schema/member/build_type.rb +137 -0
- data/lib/graphql/schema/member/cached_graphql_definition.rb +26 -0
- data/lib/graphql/schema/member/graphql_type_names.rb +21 -0
- data/lib/graphql/schema/member/has_arguments.rb +50 -0
- data/lib/graphql/schema/member/has_fields.rb +130 -0
- data/lib/graphql/schema/member/instrumentation.rb +115 -0
- data/lib/graphql/schema/member/type_system_helpers.rb +34 -0
- data/lib/graphql/schema/member.rb +28 -0
- data/lib/graphql/schema/middleware_chain.rb +5 -1
- data/lib/graphql/schema/mutation.rb +138 -0
- data/lib/graphql/schema/non_null.rb +38 -0
- data/lib/graphql/schema/object.rb +81 -0
- data/lib/graphql/schema/printer.rb +33 -266
- data/lib/graphql/schema/relay_classic_mutation.rb +87 -0
- data/lib/graphql/schema/rescue_middleware.rb +8 -7
- data/lib/graphql/schema/resolver.rb +122 -0
- data/lib/graphql/schema/scalar.rb +35 -0
- data/lib/graphql/schema/traversal.rb +102 -22
- data/lib/graphql/schema/union.rb +36 -0
- data/lib/graphql/schema/validation.rb +3 -2
- data/lib/graphql/schema.rb +381 -12
- data/lib/graphql/static_validation/definition_dependencies.rb +1 -1
- data/lib/graphql/static_validation/literal_validator.rb +16 -4
- data/lib/graphql/static_validation/rules/fields_are_defined_on_type.rb +6 -6
- data/lib/graphql/static_validation/rules/fields_have_appropriate_selections.rb +5 -1
- data/lib/graphql/static_validation/rules/fields_will_merge.rb +15 -8
- data/lib/graphql/static_validation/rules/variables_are_used_and_defined.rb +11 -1
- data/lib/graphql/static_validation/validation_context.rb +1 -1
- data/lib/graphql/subscriptions/action_cable_subscriptions.rb +7 -5
- data/lib/graphql/subscriptions/instrumentation.rb +5 -1
- data/lib/graphql/subscriptions/serialize.rb +2 -0
- data/lib/graphql/subscriptions.rb +90 -16
- data/lib/graphql/tracing/data_dog_tracing.rb +49 -0
- data/lib/graphql/tracing/new_relic_tracing.rb +26 -0
- data/lib/graphql/tracing/platform_tracing.rb +20 -7
- data/lib/graphql/tracing/scout_tracing.rb +2 -2
- data/lib/graphql/tracing.rb +1 -0
- data/lib/graphql/unresolved_type_error.rb +3 -2
- data/lib/graphql/upgrader/member.rb +894 -0
- data/lib/graphql/upgrader/schema.rb +37 -0
- data/lib/graphql/version.rb +1 -1
- data/lib/graphql.rb +5 -25
- data/readme.md +2 -2
- data/spec/dummy/app/channels/graphql_channel.rb +23 -2
- data/spec/dummy/log/development.log +239 -0
- data/spec/dummy/log/test.log +410 -0
- data/spec/dummy/test/system/action_cable_subscription_test.rb +4 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/-x/-xYZjAnuuzgR79fcznLTQtSdh6AARxu8FcQ_J6p7L3U.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/13/13HiV12xyoQvT-1L39ZzLwMZxjyaGMiENmfw7f-QTIc.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/3W/3Wtf5pCWdqq0AB-iB0Y9uUNrTkruRxIEf1XFn_BETU0.cache +1 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/5i/5iguGafb4hOn8262Kn8Q37ogNN9MxxQKGKNzHAzUcvI.cache +1 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/8m/8mj2T6yy847Mc2Z7k3Xzh8O91hhVJt3NrPe8ASNDlIA.cache +1 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/DT/DTQyMpr4ABZYQetsdRJ5A7S4jf1r3ie4FGOR7GZBNSs.cache +3 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Dq/DqJ5_yJPrP5iLlOQyTQsjAVI5FE5LCVDkED0f7GgsSo.cache +3 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/F8/F8MUNRzORGFgr329fNM0xLaoWCXdv3BIalT7dsvLfjs.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/KB/KB07ZaKNC5uXJ7TjLi-WqnY6g7dq8wWp_8N3HNjBNxg.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Rw/RwDuCV-XpnCtjNkvhpJfBuxXMk0b5AD3L9eR6M-wcy0.cache +3 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/UL/ULdjhhb0bRuqmaG7XSZlFYzGYCXTDnqZuJBTWRlzqgw.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Up/UpPNgh0yYoUsyMDh5zWqe_U6qJIyTC6-dxMMAs1vvlM.cache +1 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Wg/Wguh-szFGTI1gaL6npYwPekMXflugRei7F_mOyRucXg.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/X-/X-khLYMA9mqFRPg3zAi86mREDxpKl4bdKYp3uF6WHos.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/bi/BIkdhfxsezxM4q-HZ4oCNTq97WEJTigcq0tpX2cDvbY.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/ff/FfxmA4CMHQZT7exx0G7NS1Wpcnny0vzp-Jhc2H36bp8.cache +1 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/gE/gEiiG4GZNy_djEjK2pHm_NgA-gyhLZhdQvo0Yt96GqE.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/gn/gnA9ZSqpjccNL2m8pe_jBvY6SinXlCzXDWyop83Od8s.cache +1 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/lO/lOAan3cMwCE_Hli6gsDML88xFNfn0nxPmvrSkW7eEOw.cache +1 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/m1/M1pv8MJEPLXGLvS8QxVh3DSO9cI4mRt5FHFWdrvUj6o.cache +2 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/m7/m77qH7ZqH0_0SmwJbiKGDd-aLau1Dav847DC6ge46zY.cache +1 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/sj/sjRjnjRB37lH2vrgtkdJ8Cz84__IJ978IuKTM7HcztI.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/um/um1JrirR4hJhK-1rE-HywlyCi5ibgxHVrReiujZBWJM.cache +1 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/v4/v4fwVytD7ITcE0_GDbslZEYud8a5Okm85fV1o7SDl6g.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/v_/v_0PAQt0iipQjFP5zjgkkk9Stnpf4VzvnMv67d1Keuw.cache +1 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/wd/wdT9U4MKxe1PyqNjVuCKMpCl3dxGCIRJIlwUTfh2DQU.cache +1 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/xI/xIaxut_fEIhKBDqljTNwYaADK9kj3gG0ESrfHs-5_og.cache +3 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/y0/y0SJOqIx2fn1SKqOkAihsQow0trRJrSIyAswufVuoA8.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/zg/zgpzeaX-KZErHyGJ1aBH3ZusweNXMneVZule88XsIJI.cache +1 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/zy/zYFltDy-8VC-uKq2BVEiJJyYXNFvVzAKuMlR3ZIYZsk.cache +0 -0
- data/spec/dummy/tmp/screenshots/failures_test_it_handles_subscriptions.png +0 -0
- data/spec/fixtures/upgrader/account.original.rb +19 -0
- data/spec/fixtures/upgrader/account.transformed.rb +20 -0
- data/spec/fixtures/upgrader/blame_range.original.rb +43 -0
- data/spec/fixtures/upgrader/blame_range.transformed.rb +30 -0
- data/spec/fixtures/upgrader/date_time.original.rb +24 -0
- data/spec/fixtures/upgrader/date_time.transformed.rb +23 -0
- data/spec/fixtures/upgrader/delete_project.original.rb +28 -0
- data/spec/fixtures/upgrader/delete_project.transformed.rb +27 -0
- data/spec/fixtures/upgrader/gist_order_field.original.rb +14 -0
- data/spec/fixtures/upgrader/gist_order_field.transformed.rb +13 -0
- data/spec/fixtures/upgrader/increment_count.original.rb +59 -0
- data/spec/fixtures/upgrader/increment_count.transformed.rb +50 -0
- data/spec/fixtures/upgrader/photo.original.rb +10 -0
- data/spec/fixtures/upgrader/photo.transformed.rb +12 -0
- data/spec/fixtures/upgrader/release_order.original.rb +15 -0
- data/spec/fixtures/upgrader/release_order.transformed.rb +14 -0
- data/spec/fixtures/upgrader/starrable.original.rb +49 -0
- data/spec/fixtures/upgrader/starrable.transformed.rb +46 -0
- data/spec/fixtures/upgrader/subscribable.original.rb +55 -0
- data/spec/fixtures/upgrader/subscribable.transformed.rb +51 -0
- data/spec/fixtures/upgrader/type_x.original.rb +65 -0
- data/spec/fixtures/upgrader/type_x.transformed.rb +56 -0
- data/spec/generators/graphql/function_generator_spec.rb +26 -0
- data/spec/generators/graphql/install_generator_spec.rb +1 -1
- data/spec/generators/graphql/loader_generator_spec.rb +24 -0
- data/spec/graphql/analysis/max_query_complexity_spec.rb +3 -3
- data/spec/graphql/analysis/max_query_depth_spec.rb +3 -3
- data/spec/graphql/argument_spec.rb +21 -0
- data/spec/graphql/backtrace_spec.rb +10 -0
- data/spec/graphql/base_type_spec.rb +42 -0
- data/spec/graphql/boolean_type_spec.rb +3 -3
- data/spec/graphql/directive_spec.rb +3 -1
- data/spec/graphql/enum_type_spec.rb +18 -5
- data/spec/graphql/execution/execute_spec.rb +4 -4
- data/spec/graphql/execution/instrumentation_spec.rb +165 -0
- data/spec/graphql/execution/multiplex_spec.rb +2 -2
- data/spec/graphql/execution_error_spec.rb +18 -0
- data/spec/graphql/float_type_spec.rb +2 -2
- data/spec/graphql/id_type_spec.rb +1 -1
- data/spec/graphql/input_object_type_spec.rb +15 -2
- data/spec/graphql/int_type_spec.rb +2 -2
- data/spec/graphql/interface_type_spec.rb +12 -0
- data/spec/graphql/internal_representation/rewrite_spec.rb +2 -2
- data/spec/graphql/introspection/schema_type_spec.rb +2 -0
- data/spec/graphql/language/block_string_spec.rb +70 -0
- data/spec/graphql/language/document_from_schema_definition_spec.rb +770 -0
- data/spec/graphql/language/generation_spec.rb +21 -186
- data/spec/graphql/language/lexer_spec.rb +21 -1
- data/spec/graphql/language/nodes_spec.rb +21 -12
- data/spec/graphql/language/parser_spec.rb +1 -1
- data/spec/graphql/language/printer_spec.rb +203 -0
- data/spec/graphql/object_type_spec.rb +22 -0
- data/spec/graphql/query/arguments_spec.rb +25 -15
- data/spec/graphql/query/context_spec.rb +18 -0
- data/spec/graphql/query/executor_spec.rb +2 -1
- data/spec/graphql/query/serial_execution/value_resolution_spec.rb +2 -8
- data/spec/graphql/query/variables_spec.rb +42 -1
- data/spec/graphql/query_spec.rb +31 -5
- data/spec/graphql/rake_task_spec.rb +3 -1
- data/spec/graphql/relay/base_connection_spec.rb +1 -1
- data/spec/graphql/relay/connection_instrumentation_spec.rb +2 -2
- data/spec/graphql/relay/connection_resolve_spec.rb +1 -1
- data/spec/graphql/relay/connection_type_spec.rb +1 -1
- data/spec/graphql/relay/mongo_relation_connection_spec.rb +474 -0
- data/spec/graphql/relay/mutation_spec.rb +9 -7
- data/spec/graphql/relay/range_add_spec.rb +5 -1
- data/spec/graphql/relay/relation_connection_spec.rb +65 -1
- data/spec/graphql/schema/argument_spec.rb +87 -0
- data/spec/graphql/schema/build_from_definition_spec.rb +89 -5
- data/spec/graphql/schema/enum_spec.rb +74 -0
- data/spec/graphql/schema/field_spec.rb +225 -0
- data/spec/graphql/schema/finder_spec.rb +135 -0
- data/spec/graphql/schema/input_object_spec.rb +111 -0
- data/spec/graphql/schema/instrumentation_spec.rb +40 -0
- data/spec/graphql/schema/interface_spec.rb +185 -0
- data/spec/graphql/schema/introspection_system_spec.rb +39 -0
- data/spec/graphql/schema/member/accepts_definition_spec.rb +111 -0
- data/spec/graphql/schema/member/build_type_spec.rb +17 -0
- data/spec/graphql/schema/member/has_fields_spec.rb +129 -0
- data/spec/graphql/schema/member/type_system_helpers_spec.rb +63 -0
- data/spec/graphql/schema/mutation_spec.rb +148 -0
- data/spec/graphql/schema/object_spec.rb +175 -0
- data/spec/graphql/schema/printer_spec.rb +111 -15
- data/spec/graphql/schema/relay_classic_mutation_spec.rb +38 -0
- data/spec/graphql/schema/rescue_middleware_spec.rb +11 -0
- data/spec/graphql/schema/resolver_spec.rb +131 -0
- data/spec/graphql/schema/scalar_spec.rb +95 -0
- data/spec/graphql/schema/traversal_spec.rb +31 -0
- data/spec/graphql/schema/union_spec.rb +65 -0
- data/spec/graphql/schema/validation_spec.rb +1 -1
- data/spec/graphql/schema/warden_spec.rb +11 -11
- data/spec/graphql/schema_spec.rb +55 -12
- data/spec/graphql/static_validation/rules/fields_have_appropriate_selections_spec.rb +10 -2
- data/spec/graphql/static_validation/rules/fields_will_merge_spec.rb +2 -2
- data/spec/graphql/string_type_spec.rb +3 -3
- data/spec/graphql/subscriptions_spec.rb +273 -184
- data/spec/graphql/tracing/active_support_notifications_tracing_spec.rb +1 -1
- data/spec/graphql/tracing/new_relic_tracing_spec.rb +47 -0
- data/spec/graphql/tracing/platform_tracing_spec.rb +60 -1
- data/spec/graphql/union_type_spec.rb +1 -1
- data/spec/graphql/upgrader/member_spec.rb +516 -0
- data/spec/graphql/upgrader/schema_spec.rb +82 -0
- data/spec/spec_helper.rb +8 -0
- data/spec/support/dummy/schema.rb +53 -24
- data/spec/support/jazz.rb +544 -0
- data/spec/support/lazy_helpers.rb +21 -23
- data/spec/support/new_relic.rb +24 -0
- data/spec/support/star_trek/data.rb +109 -0
- data/spec/support/star_trek/schema.rb +388 -0
- data/spec/support/star_wars/data.rb +6 -7
- data/spec/support/star_wars/schema.rb +127 -171
- metadata +233 -11
- data/lib/graphql/introspection/arguments_field.rb +0 -7
- data/lib/graphql/introspection/enum_values_field.rb +0 -18
- data/lib/graphql/introspection/fields_field.rb +0 -13
- data/lib/graphql/introspection/input_fields_field.rb +0 -12
- data/lib/graphql/introspection/interfaces_field.rb +0 -11
- data/lib/graphql/introspection/of_type_field.rb +0 -6
- data/lib/graphql/introspection/possible_types_field.rb +0 -11
@@ -3,31 +3,28 @@ module StarWars
|
|
3
3
|
# Adapted from graphql-relay-js
|
4
4
|
# https://github.com/graphql/graphql-relay-js/blob/master/src/__tests__/starWarsSchema.js
|
5
5
|
|
6
|
-
Ship
|
7
|
-
|
8
|
-
interfaces [GraphQL::Relay::Node.interface]
|
6
|
+
class Ship < GraphQL::Schema::Object
|
7
|
+
implements GraphQL::Relay::Node.interface
|
9
8
|
global_id_field :id
|
10
|
-
field :name,
|
9
|
+
field :name, String, null: true
|
11
10
|
# Test cyclical connection types:
|
12
|
-
|
11
|
+
field :ships, Ship.connection_type, null: false
|
13
12
|
end
|
14
13
|
|
15
|
-
BaseType
|
16
|
-
|
17
|
-
|
14
|
+
class BaseType < GraphQL::Schema::Object
|
15
|
+
graphql_name "Base"
|
16
|
+
implements GraphQL::Relay::Node.interface
|
18
17
|
global_id_field :id
|
19
|
-
field :name,
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
end
|
27
|
-
}
|
18
|
+
field :name, String, null: false, resolve: ->(obj, args, ctx) {
|
19
|
+
LazyWrapper.new {
|
20
|
+
if obj.id.nil?
|
21
|
+
raise GraphQL::ExecutionError, "Boom!"
|
22
|
+
else
|
23
|
+
obj.name
|
24
|
+
end
|
28
25
|
}
|
29
|
-
|
30
|
-
field :planet,
|
26
|
+
}
|
27
|
+
field :planet, String, null: true
|
31
28
|
end
|
32
29
|
|
33
30
|
# Use an optional block to add fields to the connection type:
|
@@ -90,133 +87,98 @@ module StarWars
|
|
90
87
|
end
|
91
88
|
end
|
92
89
|
|
93
|
-
Faction
|
94
|
-
|
95
|
-
interfaces [GraphQL::Relay::Node.interface]
|
96
|
-
|
97
|
-
field :id, !types.ID, resolve: GraphQL::Relay::GlobalIdResolve.new(type: Faction)
|
98
|
-
field :name, types.String
|
99
|
-
connection :ships, ShipConnectionWithParentType, max_page_size: 1000 do
|
100
|
-
resolve ->(obj, args, ctx) {
|
101
|
-
all_ships = obj.ships.map {|ship_id| StarWars::DATA["Ship"][ship_id] }
|
102
|
-
if args[:nameIncludes]
|
103
|
-
case args[:nameIncludes]
|
104
|
-
when "error"
|
105
|
-
all_ships = GraphQL::ExecutionError.new("error from within connection")
|
106
|
-
when "raisedError"
|
107
|
-
raise GraphQL::ExecutionError.new("error raised from within connection")
|
108
|
-
when "lazyError"
|
109
|
-
all_ships = LazyWrapper.new { GraphQL::ExecutionError.new("lazy error from within connection") }
|
110
|
-
when "lazyRaisedError"
|
111
|
-
all_ships = LazyWrapper.new { raise GraphQL::ExecutionError.new("lazy raised error from within connection") }
|
112
|
-
when "null"
|
113
|
-
all_ships = nil
|
114
|
-
when "lazyObject"
|
115
|
-
prev_all_ships = all_ships
|
116
|
-
all_ships = LazyWrapper.new { prev_all_ships }
|
117
|
-
else
|
118
|
-
all_ships = all_ships.select { |ship| ship.name.include?(args[:nameIncludes])}
|
119
|
-
end
|
120
|
-
end
|
121
|
-
all_ships
|
122
|
-
}
|
123
|
-
# You can define arguments here and use them in the connection
|
124
|
-
argument :nameIncludes, types.String
|
125
|
-
end
|
126
|
-
|
127
|
-
connection :shipsWithMaxPageSize, max_page_size: 2, function: ShipsWithMaxPageSize.new
|
128
|
-
|
129
|
-
connection :bases, BaseConnectionWithTotalCountType do
|
130
|
-
# Resolve field should return an Array, the Connection
|
131
|
-
# will do the rest!
|
132
|
-
resolve ->(obj, args, ctx) {
|
133
|
-
all_bases = Base.where(id: obj.bases)
|
134
|
-
if args[:nameIncludes]
|
135
|
-
all_bases = all_bases.where("name LIKE ?", "%#{args[:nameIncludes]}%")
|
136
|
-
end
|
137
|
-
all_bases
|
138
|
-
}
|
139
|
-
argument :nameIncludes, types.String
|
140
|
-
end
|
90
|
+
class Faction < GraphQL::Schema::Object
|
91
|
+
implements GraphQL::Relay::Node.interface
|
141
92
|
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
93
|
+
field :id, ID, null: false, resolve: GraphQL::Relay::GlobalIdResolve.new(type: Faction)
|
94
|
+
field :name, String, null: true
|
95
|
+
field :ships, ShipConnectionWithParentType, connection: true, max_page_size: 1000, null: true, resolve: ->(obj, args, ctx) {
|
96
|
+
all_ships = obj.ships.map {|ship_id| StarWars::DATA["Ship"][ship_id] }
|
97
|
+
if args[:nameIncludes]
|
98
|
+
case args[:nameIncludes]
|
99
|
+
when "error"
|
100
|
+
all_ships = GraphQL::ExecutionError.new("error from within connection")
|
101
|
+
when "raisedError"
|
102
|
+
raise GraphQL::ExecutionError.new("error raised from within connection")
|
103
|
+
when "lazyError"
|
104
|
+
all_ships = LazyWrapper.new { GraphQL::ExecutionError.new("lazy error from within connection") }
|
105
|
+
when "lazyRaisedError"
|
106
|
+
all_ships = LazyWrapper.new { raise GraphQL::ExecutionError.new("lazy raised error from within connection") }
|
107
|
+
when "null"
|
108
|
+
all_ships = nil
|
109
|
+
when "lazyObject"
|
110
|
+
prev_all_ships = all_ships
|
111
|
+
all_ships = LazyWrapper.new { prev_all_ships }
|
148
112
|
else
|
149
|
-
|
113
|
+
all_ships = all_ships.select { |ship| ship.name.include?(args[:nameIncludes])}
|
150
114
|
end
|
151
|
-
|
115
|
+
end
|
116
|
+
all_ships
|
117
|
+
} do
|
118
|
+
# You can define arguments here and use them in the connection
|
119
|
+
argument :nameIncludes, String, required: false
|
152
120
|
end
|
153
121
|
|
154
|
-
|
155
|
-
resolve ->(object, args, context) { Base.all }
|
156
|
-
end
|
122
|
+
field :shipsWithMaxPageSize, "Ships with max page size", max_page_size: 2, function: ShipsWithMaxPageSize.new
|
157
123
|
|
158
|
-
|
159
|
-
|
124
|
+
field :bases, BaseConnectionWithTotalCountType, null: true, connection: true, resolve: ->(obj, args, ctx) {
|
125
|
+
all_bases = Base.where(id: obj.bases)
|
126
|
+
if args[:nameIncludes]
|
127
|
+
all_bases = all_bases.where("name LIKE ?", "%#{args[:nameIncludes]}%")
|
128
|
+
end
|
129
|
+
all_bases
|
130
|
+
} do
|
131
|
+
argument :nameIncludes, String, required: false
|
160
132
|
end
|
161
133
|
|
162
|
-
|
163
|
-
|
134
|
+
field :basesClone, BaseType.connection_type, null: true
|
135
|
+
field :basesByName, BaseType.connection_type, null: true do
|
136
|
+
argument :order, String, default_value: "name", required: false
|
164
137
|
end
|
165
|
-
|
166
|
-
|
167
|
-
|
138
|
+
def bases_by_name(order: nil)
|
139
|
+
if order.present?
|
140
|
+
@object.bases.order(order)
|
141
|
+
else
|
142
|
+
@object.bases
|
143
|
+
end
|
168
144
|
end
|
169
145
|
|
170
|
-
|
171
|
-
|
172
|
-
|
146
|
+
field :basesWithMaxLimitRelation, BaseType.connection_type, null: true, max_page_size: 2, resolve: Proc.new { Base.all}
|
147
|
+
field :basesWithMaxLimitArray, BaseType.connection_type, null: true, max_page_size: 2, resolve: Proc.new { Base.all.to_a }
|
148
|
+
field :basesWithDefaultMaxLimitRelation, BaseType.connection_type, null: true, resolve: Proc.new { Base.all }
|
149
|
+
field :basesWithDefaultMaxLimitArray, BaseType.connection_type, null: true, resolve: Proc.new { Base.all.to_a }
|
150
|
+
field :basesWithLargeMaxLimitRelation, BaseType.connection_type, null: true, max_page_size: 1000, resolve: Proc.new { Base.all }
|
173
151
|
|
174
|
-
|
175
|
-
argument :nameIncludes,
|
176
|
-
resolve ->(obj, args, ctx) {
|
177
|
-
all_bases = SequelBase.where(faction_id: obj.id)
|
178
|
-
if args[:nameIncludes]
|
179
|
-
all_bases = all_bases.where(Sequel.like(:name, "%#{args[:nameIncludes]}%"))
|
180
|
-
end
|
181
|
-
all_bases
|
182
|
-
}
|
152
|
+
field :basesAsSequelDataset, BaseConnectionWithTotalCountType, null: true, connection: true, max_page_size: 1000 do
|
153
|
+
argument :nameIncludes, String, required: false
|
183
154
|
end
|
184
155
|
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
156
|
+
def bases_as_sequel_dataset(name_includes: nil)
|
157
|
+
all_bases = SequelBase.where(faction_id: @object.id)
|
158
|
+
if name_includes
|
159
|
+
all_bases = all_bases.where(Sequel.like(:name, "%#{name_includes}%"))
|
160
|
+
end
|
161
|
+
all_bases
|
189
162
|
end
|
163
|
+
|
164
|
+
field :basesWithCustomEdge, CustomEdgeBaseConnectionType, null: true, connection: true, resolve: ->(o, a, c) { LazyNodesWrapper.new(o.bases) }
|
190
165
|
end
|
191
166
|
|
192
|
-
|
193
|
-
# - define a derived InputObjectType
|
194
|
-
# - define a derived ObjectType (for return)
|
195
|
-
# - define a field, accessible from {Mutation#field}
|
196
|
-
#
|
197
|
-
# The resolve proc takes `inputs, ctx`, where:
|
198
|
-
# - `inputs` has the keys defined with `input_field`
|
199
|
-
# - `ctx` is the Query context (like normal fields)
|
200
|
-
#
|
201
|
-
# Notice that you leave out clientMutationId.
|
202
|
-
IntroduceShipMutation = GraphQL::Relay::Mutation.define do
|
203
|
-
# Used as the root for derived types:
|
204
|
-
name "IntroduceShip"
|
167
|
+
class IntroduceShipMutation < GraphQL::Schema::RelayClassicMutation
|
205
168
|
description "Add a ship to this faction"
|
206
169
|
|
207
170
|
# Nested under `input` in the query:
|
208
|
-
|
209
|
-
|
171
|
+
argument :ship_name, String, required: false
|
172
|
+
argument :faction_id, ID, required: true
|
210
173
|
|
211
174
|
# Result may have access to these fields:
|
212
|
-
|
213
|
-
|
214
|
-
|
175
|
+
field :ship_edge, Ship.edge_type, null: true
|
176
|
+
field :faction, Faction, null: true
|
177
|
+
field :aliased_faction, Faction, hash_key: :aliased_faction, null: true
|
215
178
|
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
}
|
179
|
+
def resolve(ship_name: nil, faction_id:)
|
180
|
+
IntroduceShipFunction.new.call(object, {ship_name: ship_name, faction_id: faction_id}, context)
|
181
|
+
end
|
220
182
|
end
|
221
183
|
|
222
184
|
class IntroduceShipFunction < GraphQL::Function
|
@@ -232,21 +194,24 @@ module StarWars
|
|
232
194
|
end)
|
233
195
|
|
234
196
|
def call(obj, args, ctx)
|
235
|
-
|
236
|
-
|
197
|
+
# support old and new args
|
198
|
+
ship_name = args["shipName"] || args[:ship_name]
|
199
|
+
faction_id = args["factionId"] || args[:faction_id]
|
200
|
+
if ship_name == 'Millennium Falcon'
|
237
201
|
GraphQL::ExecutionError.new("Sorry, Millennium Falcon ship is reserved")
|
238
|
-
elsif
|
202
|
+
elsif ship_name == 'Leviathan'
|
239
203
|
raise GraphQL::ExecutionError.new("🔥")
|
240
|
-
elsif
|
204
|
+
elsif ship_name == "Ebon Hawk"
|
241
205
|
LazyWrapper.new { raise GraphQL::ExecutionError.new("💥")}
|
242
206
|
else
|
243
|
-
ship = DATA.create_ship(
|
207
|
+
ship = DATA.create_ship(ship_name, faction_id)
|
244
208
|
faction = DATA["Faction"][faction_id]
|
245
209
|
connection_class = GraphQL::Relay::BaseConnection.connection_for_nodes(faction.ships)
|
246
210
|
ships_connection = connection_class.new(faction.ships, args)
|
247
211
|
ship_edge = GraphQL::Relay::Edge.new(ship, ships_connection)
|
248
212
|
result = {
|
249
213
|
shipEdge: ship_edge,
|
214
|
+
ship_edge: ship_edge, # support new-style, too
|
250
215
|
faction: faction,
|
251
216
|
aliased_faction: faction,
|
252
217
|
}
|
@@ -323,60 +288,51 @@ module StarWars
|
|
323
288
|
|
324
289
|
GraphQL::Relay::BaseConnection.register_connection_implementation(LazyNodesWrapper, LazyNodesRelationConnection)
|
325
290
|
|
326
|
-
QueryType
|
327
|
-
|
328
|
-
field :rebels, Faction do
|
329
|
-
resolve ->(obj, args, ctx) { StarWars::DATA["Faction"]["1"]}
|
330
|
-
end
|
291
|
+
class QueryType < GraphQL::Schema::Object
|
292
|
+
graphql_name "Query"
|
331
293
|
|
332
|
-
field :
|
333
|
-
resolve ->(obj, args, ctx) { StarWars::DATA["Faction"]["2"]}
|
334
|
-
end
|
294
|
+
field :rebels, Faction, null: true, resolve: ->(obj, args, ctx) { StarWars::DATA["Faction"]["1"]}
|
335
295
|
|
336
|
-
field :
|
337
|
-
resolve ->(obj, args, ctx) { Base.find(3) }
|
338
|
-
end
|
296
|
+
field :empire, Faction, null: true, resolve: ->(obj, args, ctx) { StarWars::DATA["Faction"]["2"]}
|
339
297
|
|
340
|
-
|
341
|
-
resolve ->(obj, args, ctx) {
|
342
|
-
Base
|
343
|
-
.having('id in (select max(id) from bases group by faction_id)')
|
344
|
-
.group(:id)
|
345
|
-
.order('faction_id desc')
|
346
|
-
}
|
347
|
-
end
|
298
|
+
field :largestBase, BaseType, null: true, resolve: ->(obj, args, ctx) { Base.find(3) }
|
348
299
|
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
300
|
+
field :newestBasesGroupedByFaction, BaseType.connection_type, null: true, resolve: ->(obj, args, ctx) {
|
301
|
+
Base
|
302
|
+
.having('id in (select max(id) from bases group by faction_id)')
|
303
|
+
.group(:id)
|
304
|
+
.order('faction_id desc')
|
305
|
+
}
|
306
|
+
|
307
|
+
field :basesWithNullName, BaseType.connection_type, null: false, resolve: ->(obj, args, ctx) {
|
308
|
+
[OpenStruct.new(id: nil)]
|
309
|
+
}
|
354
310
|
|
355
|
-
field :node, GraphQL::Relay::Node.field
|
311
|
+
field :node, field: GraphQL::Relay::Node.field
|
356
312
|
|
357
313
|
custom_node_field = GraphQL::Relay::Node.field do
|
358
314
|
resolve ->(_, _, _) { StarWars::DATA["Faction"]["1"] }
|
359
315
|
end
|
360
|
-
field :nodeWithCustomResolver, custom_node_field
|
316
|
+
field :nodeWithCustomResolver, field: custom_node_field
|
361
317
|
|
362
|
-
field :nodes, GraphQL::Relay::Node.plural_field
|
363
|
-
field :nodesWithCustomResolver, GraphQL::Relay::Node.plural_field(
|
318
|
+
field :nodes, field: GraphQL::Relay::Node.plural_field
|
319
|
+
field :nodesWithCustomResolver, field: GraphQL::Relay::Node.plural_field(
|
364
320
|
resolve: ->(_, _, _) { [StarWars::DATA["Faction"]["1"], StarWars::DATA["Faction"]["2"]] }
|
365
321
|
)
|
366
322
|
|
367
|
-
field :batchedBase, BaseType do
|
368
|
-
argument :id,
|
369
|
-
|
370
|
-
|
371
|
-
|
323
|
+
field :batchedBase, BaseType, null: true do
|
324
|
+
argument :id, ID, required: true
|
325
|
+
end
|
326
|
+
|
327
|
+
def batched_base(id:)
|
328
|
+
LazyLoader.defer(@context, Base, id)
|
372
329
|
end
|
373
330
|
end
|
374
331
|
|
375
|
-
MutationType
|
376
|
-
|
377
|
-
|
378
|
-
field :
|
379
|
-
field :introduceShipFunction, IntroduceShipFunctionMutation.field
|
332
|
+
class MutationType < GraphQL::Schema::Object
|
333
|
+
graphql_name "Mutation"
|
334
|
+
field :introduceShip, mutation: IntroduceShipMutation
|
335
|
+
field :introduceShipFunction, field: IntroduceShipFunctionMutation.field
|
380
336
|
end
|
381
337
|
|
382
338
|
class ClassNameRecorder
|
@@ -399,12 +355,12 @@ module StarWars
|
|
399
355
|
end
|
400
356
|
end
|
401
357
|
|
402
|
-
Schema
|
358
|
+
class Schema < GraphQL::Schema
|
403
359
|
query(QueryType)
|
404
360
|
mutation(MutationType)
|
405
361
|
default_max_page_size 3
|
406
362
|
|
407
|
-
resolve_type
|
363
|
+
def self.resolve_type(type, object, ctx)
|
408
364
|
if object == :test_error
|
409
365
|
:not_a_type
|
410
366
|
elsif object.is_a?(Base)
|
@@ -416,14 +372,14 @@ module StarWars
|
|
416
372
|
else
|
417
373
|
nil
|
418
374
|
end
|
419
|
-
|
375
|
+
end
|
420
376
|
|
421
|
-
object_from_id
|
377
|
+
def self.object_from_id(node_id, ctx)
|
422
378
|
type_name, id = GraphQL::Schema::UniqueWithinType.decode(node_id)
|
423
379
|
StarWars::DATA[type_name][id]
|
424
380
|
end
|
425
381
|
|
426
|
-
id_from_object
|
382
|
+
def self.id_from_object(object, type, ctx)
|
427
383
|
GraphQL::Schema::UniqueWithinType.encode(type.name, object.id)
|
428
384
|
end
|
429
385
|
|