graphql 1.7.14 → 1.8.0.pre1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/generators/graphql/function_generator.rb +1 -1
- data/lib/generators/graphql/loader_generator.rb +1 -1
- data/lib/generators/graphql/mutation_generator.rb +1 -6
- data/lib/generators/graphql/templates/function.erb +2 -2
- data/lib/generators/graphql/templates/loader.erb +2 -2
- data/lib/graphql.rb +2 -0
- data/lib/graphql/argument.rb +0 -1
- data/lib/graphql/backwards_compatibility.rb +2 -3
- data/lib/graphql/base_type.rb +18 -16
- data/lib/graphql/compatibility/query_parser_specification.rb +0 -117
- data/lib/graphql/compatibility/query_parser_specification/parse_error_specification.rb +0 -14
- data/lib/graphql/define/assign_object_field.rb +5 -12
- data/lib/graphql/deprecated_dsl.rb +28 -0
- data/lib/graphql/directive.rb +0 -1
- data/lib/graphql/enum_type.rb +1 -3
- data/lib/graphql/execution.rb +0 -1
- data/lib/graphql/execution/multiplex.rb +29 -12
- data/lib/graphql/field.rb +5 -20
- data/lib/graphql/function.rb +12 -0
- data/lib/graphql/input_object_type.rb +1 -3
- data/lib/graphql/internal_representation/node.rb +14 -26
- data/lib/graphql/internal_representation/visit.rb +6 -3
- data/lib/graphql/introspection/arguments_field.rb +0 -1
- data/lib/graphql/introspection/enum_values_field.rb +0 -1
- data/lib/graphql/introspection/fields_field.rb +0 -1
- data/lib/graphql/introspection/input_fields_field.rb +0 -1
- data/lib/graphql/introspection/interfaces_field.rb +0 -1
- data/lib/graphql/introspection/of_type_field.rb +0 -1
- data/lib/graphql/introspection/possible_types_field.rb +0 -1
- data/lib/graphql/introspection/schema_field.rb +0 -1
- data/lib/graphql/introspection/type_by_name_field.rb +0 -1
- data/lib/graphql/introspection/typename_field.rb +0 -1
- data/lib/graphql/language.rb +0 -3
- data/lib/graphql/language/generation.rb +182 -3
- data/lib/graphql/language/lexer.rb +69 -144
- data/lib/graphql/language/lexer.rl +4 -15
- data/lib/graphql/language/nodes.rb +76 -136
- data/lib/graphql/language/parser.rb +621 -668
- data/lib/graphql/language/parser.y +11 -17
- data/lib/graphql/language/token.rb +3 -10
- data/lib/graphql/object_type.rb +6 -1
- data/lib/graphql/query.rb +13 -8
- data/lib/graphql/query/arguments.rb +33 -48
- data/lib/graphql/query/context.rb +1 -0
- data/lib/graphql/query/literal_input.rb +1 -4
- data/lib/graphql/relay/connection_resolve.rb +3 -0
- data/lib/graphql/relay/global_id_resolve.rb +5 -1
- data/lib/graphql/relay/relation_connection.rb +19 -14
- data/lib/graphql/schema.rb +219 -12
- data/lib/graphql/schema/argument.rb +33 -0
- data/lib/graphql/schema/build_from_definition.rb +18 -64
- data/lib/graphql/schema/enum.rb +76 -0
- data/lib/graphql/schema/field.rb +127 -0
- data/lib/graphql/schema/field/dynamic_resolve.rb +63 -0
- data/lib/graphql/schema/field/unwrapped_resolve.rb +20 -0
- data/lib/graphql/schema/input_object.rb +61 -0
- data/lib/graphql/schema/interface.rb +32 -0
- data/lib/graphql/schema/loader.rb +2 -2
- data/lib/graphql/schema/member.rb +97 -0
- data/lib/graphql/schema/member/build_type.rb +106 -0
- data/lib/graphql/schema/member/has_fields.rb +56 -0
- data/lib/graphql/schema/member/instrumentation.rb +113 -0
- data/lib/graphql/schema/member/list_type_proxy.rb +21 -0
- data/lib/graphql/schema/member/non_null_type_proxy.rb +21 -0
- data/lib/graphql/schema/object.rb +65 -0
- data/lib/graphql/schema/printer.rb +266 -33
- data/lib/graphql/schema/scalar.rb +25 -0
- data/lib/graphql/schema/traversal.rb +26 -17
- data/lib/graphql/schema/union.rb +48 -0
- data/lib/graphql/static_validation/rules/fields_have_appropriate_selections.rb +1 -5
- data/lib/graphql/static_validation/rules/fields_will_merge.rb +8 -15
- data/lib/graphql/static_validation/rules/variables_are_used_and_defined.rb +1 -11
- data/lib/graphql/subscriptions/action_cable_subscriptions.rb +5 -7
- data/lib/graphql/tracing.rb +0 -1
- data/lib/graphql/tracing/platform_tracing.rb +7 -20
- data/lib/graphql/tracing/scout_tracing.rb +2 -2
- data/lib/graphql/unresolved_type_error.rb +2 -3
- data/lib/graphql/version.rb +1 -1
- data/readme.md +1 -1
- data/spec/dummy/app/channels/graphql_channel.rb +1 -22
- data/spec/dummy/log/development.log +0 -239
- data/spec/dummy/log/test.log +0 -204
- data/spec/dummy/test/system/action_cable_subscription_test.rb +0 -4
- data/spec/dummy/tmp/screenshots/failures_test_it_handles_subscriptions.png +0 -0
- data/spec/generators/graphql/function_generator_spec.rb +0 -26
- data/spec/generators/graphql/loader_generator_spec.rb +0 -24
- 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/backtrace_spec.rb +0 -10
- data/spec/graphql/base_type_spec.rb +5 -19
- data/spec/graphql/boolean_type_spec.rb +3 -3
- data/spec/graphql/directive_spec.rb +1 -3
- data/spec/graphql/enum_type_spec.rb +5 -18
- data/spec/graphql/execution/execute_spec.rb +1 -1
- data/spec/graphql/execution/multiplex_spec.rb +2 -2
- 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 +2 -15
- data/spec/graphql/int_type_spec.rb +2 -2
- data/spec/graphql/internal_representation/rewrite_spec.rb +2 -2
- data/spec/graphql/introspection/schema_type_spec.rb +0 -1
- data/spec/graphql/language/generation_spec.rb +186 -21
- data/spec/graphql/language/lexer_spec.rb +1 -21
- data/spec/graphql/language/nodes_spec.rb +12 -21
- data/spec/graphql/language/parser_spec.rb +1 -1
- data/spec/graphql/query/arguments_spec.rb +15 -37
- data/spec/graphql/query/serial_execution/value_resolution_spec.rb +2 -2
- data/spec/graphql/query/variables_spec.rb +1 -1
- data/spec/graphql/query_spec.rb +5 -31
- data/spec/graphql/rake_task_spec.rb +1 -3
- 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/mutation_spec.rb +3 -3
- data/spec/graphql/relay/relation_connection_spec.rb +1 -65
- data/spec/graphql/schema/build_from_definition_spec.rb +4 -86
- data/spec/graphql/schema/enum_spec.rb +60 -0
- data/spec/graphql/schema/field_spec.rb +14 -0
- data/spec/graphql/schema/input_object_spec.rb +43 -0
- data/spec/graphql/schema/interface_spec.rb +98 -0
- data/spec/graphql/schema/object_spec.rb +119 -0
- data/spec/graphql/schema/printer_spec.rb +15 -92
- data/spec/graphql/schema/scalar_spec.rb +40 -0
- data/spec/graphql/schema/union_spec.rb +35 -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 +25 -23
- data/spec/graphql/static_validation/rules/fields_have_appropriate_selections_spec.rb +2 -10
- 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 +1 -1
- data/spec/graphql/tracing/platform_tracing_spec.rb +1 -60
- data/spec/support/dummy/schema.rb +25 -39
- data/spec/support/jazz.rb +334 -0
- data/spec/support/lazy_helpers.rb +21 -23
- data/spec/support/star_wars/data.rb +7 -6
- data/spec/support/star_wars/schema.rb +109 -142
- metadata +39 -33
- data/lib/graphql/execution/instrumentation.rb +0 -82
- data/lib/graphql/language/block_string.rb +0 -47
- data/lib/graphql/language/document_from_schema_definition.rb +0 -277
- data/lib/graphql/language/printer.rb +0 -351
- data/lib/graphql/tracing/data_dog_tracing.rb +0 -49
- data/spec/graphql/execution/instrumentation_spec.rb +0 -165
- data/spec/graphql/language/block_string_spec.rb +0 -70
- data/spec/graphql/language/document_from_schema_definition_spec.rb +0 -770
- data/spec/graphql/language/printer_spec.rb +0 -203
data/lib/graphql/schema.rb
CHANGED
@@ -16,6 +16,17 @@ require "graphql/schema/validation"
|
|
16
16
|
require "graphql/schema/warden"
|
17
17
|
require "graphql/schema/build_from_definition"
|
18
18
|
|
19
|
+
|
20
|
+
require "graphql/schema/member"
|
21
|
+
require "graphql/schema/argument"
|
22
|
+
require "graphql/schema/enum"
|
23
|
+
require "graphql/schema/field"
|
24
|
+
require "graphql/schema/input_object"
|
25
|
+
require "graphql/schema/interface"
|
26
|
+
require "graphql/schema/object"
|
27
|
+
require "graphql/schema/scalar"
|
28
|
+
require "graphql/schema/union"
|
29
|
+
|
19
30
|
module GraphQL
|
20
31
|
# A GraphQL schema which may be queried with {GraphQL::Query}.
|
21
32
|
#
|
@@ -80,7 +91,6 @@ module GraphQL
|
|
80
91
|
:orphan_types, :directives,
|
81
92
|
:query_analyzers, :multiplex_analyzers, :instrumenters, :lazy_methods,
|
82
93
|
:cursor_encoder,
|
83
|
-
:ast_node,
|
84
94
|
:raise_definition_error
|
85
95
|
|
86
96
|
# Single, long-lived instance of the provided subscriptions class, if there is one.
|
@@ -387,6 +397,18 @@ module GraphQL
|
|
387
397
|
# @param ctx [GraphQL::Query::Context] The context for the current query
|
388
398
|
# @return [GraphQL::ObjectType] The type for exposing `object` in GraphQL
|
389
399
|
def resolve_type(type, object, ctx = :__undefined__)
|
400
|
+
check_resolved_type(type, object, ctx) do |ok_type, ok_object, ok_ctx|
|
401
|
+
if @resolve_type_proc.nil?
|
402
|
+
raise(NotImplementedError, "Can't determine GraphQL type for: #{ok_object.inspect}, define `resolve_type (type, obj, ctx) -> { ... }` inside `Schema.define`.")
|
403
|
+
end
|
404
|
+
@resolve_type_proc.call(ok_type, ok_object, ok_ctx)
|
405
|
+
end
|
406
|
+
end
|
407
|
+
|
408
|
+
# This is a compatibility hack so that instance-level and class-level
|
409
|
+
# methods can get correctness checks without calling one another
|
410
|
+
# @api private
|
411
|
+
def check_resolved_type(type, object, ctx = :__undefined__)
|
390
412
|
if ctx == :__undefined__
|
391
413
|
# Old method signature
|
392
414
|
ctx = object
|
@@ -394,15 +416,20 @@ module GraphQL
|
|
394
416
|
type = nil
|
395
417
|
end
|
396
418
|
|
419
|
+
if object.is_a?(GraphQL::Schema::Object)
|
420
|
+
object = object.object
|
421
|
+
end
|
422
|
+
|
397
423
|
# Prefer a type-local function; fall back to the schema-level function
|
398
424
|
type_proc = type && type.resolve_type_proc
|
399
425
|
type_result = if type_proc
|
400
426
|
type_proc.call(object, ctx)
|
401
427
|
else
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
428
|
+
yield(type, object, ctx)
|
429
|
+
end
|
430
|
+
|
431
|
+
if type_result.respond_to?(:graphql_definition)
|
432
|
+
type_result = type_result.graphql_definition
|
406
433
|
end
|
407
434
|
|
408
435
|
if type_result.nil?
|
@@ -543,19 +570,13 @@ module GraphQL
|
|
543
570
|
GraphQL::Schema::Printer.print_schema(self, only: only, except: except, context: context)
|
544
571
|
end
|
545
572
|
|
546
|
-
# Return the GraphQL::Language::Document IDL AST for the schema
|
547
|
-
# @return [GraphQL::Language::Document]
|
548
|
-
def to_document
|
549
|
-
GraphQL::Language::DocumentFromSchemaDefinition.new(self).document
|
550
|
-
end
|
551
|
-
|
552
573
|
# Return the Hash response of {Introspection::INTROSPECTION_QUERY}.
|
553
574
|
# @param context [Hash]
|
554
575
|
# @param only [<#call(member, ctx)>]
|
555
576
|
# @param except [<#call(member, ctx)>]
|
556
577
|
# @return [Hash] GraphQL result
|
557
578
|
def as_json(only: nil, except: nil, context: {})
|
558
|
-
execute(Introspection::INTROSPECTION_QUERY, only: only, except: except, context: context)
|
579
|
+
execute(Introspection::INTROSPECTION_QUERY, only: only, except: except, context: context)
|
559
580
|
end
|
560
581
|
|
561
582
|
# Returns the JSON response of {Introspection::INTROSPECTION_QUERY}.
|
@@ -565,6 +586,191 @@ module GraphQL
|
|
565
586
|
JSON.pretty_generate(as_json(*args))
|
566
587
|
end
|
567
588
|
|
589
|
+
class << self
|
590
|
+
extend GraphQL::Delegate
|
591
|
+
def_delegators :graphql_definition, :as_json, :to_json
|
592
|
+
|
593
|
+
def method_missing(method_name, *args, &block)
|
594
|
+
if graphql_definition.respond_to?(method_name)
|
595
|
+
graphql_definition.public_send(method_name, *args, &block)
|
596
|
+
else
|
597
|
+
super
|
598
|
+
end
|
599
|
+
end
|
600
|
+
|
601
|
+
def respond_to_missing?(method_name, incl_private = false)
|
602
|
+
graphql_definition.respond_to?(method_name, incl_private) || super
|
603
|
+
end
|
604
|
+
|
605
|
+
def graphql_definition
|
606
|
+
@graphql_definition ||= to_graphql
|
607
|
+
end
|
608
|
+
|
609
|
+
def use(plugin, options = {})
|
610
|
+
plugins << [plugin, options]
|
611
|
+
end
|
612
|
+
|
613
|
+
def plugins
|
614
|
+
@plugins ||= []
|
615
|
+
end
|
616
|
+
|
617
|
+
def to_graphql
|
618
|
+
schema_defn = self.new
|
619
|
+
schema_defn.query = query
|
620
|
+
schema_defn.mutation = mutation
|
621
|
+
schema_defn.subscription = subscription
|
622
|
+
schema_defn.max_depth = max_depth
|
623
|
+
schema_defn.default_max_page_size = default_max_page_size
|
624
|
+
schema_defn.orphan_types = orphan_types
|
625
|
+
if !directives
|
626
|
+
directives(DIRECTIVES)
|
627
|
+
end
|
628
|
+
schema_defn.directives = directives
|
629
|
+
schema_defn.resolve_type = method(:resolve_type)
|
630
|
+
schema_defn.object_from_id = method(:object_from_id)
|
631
|
+
schema_defn.id_from_object = method(:id_from_object)
|
632
|
+
instrumenters.each do |step, insts|
|
633
|
+
insts.each do |inst|
|
634
|
+
schema_defn.instrumenters[step] << inst
|
635
|
+
end
|
636
|
+
end
|
637
|
+
schema_defn.instrumenters[:query] << GraphQL::Schema::Member::Instrumentation
|
638
|
+
lazy_classes.each do |lazy_class, value_method|
|
639
|
+
schema_defn.lazy_methods.set(lazy_class, value_method)
|
640
|
+
end
|
641
|
+
if plugins.any?
|
642
|
+
schema_plugins = plugins
|
643
|
+
# TODO don't depend on .define
|
644
|
+
schema_defn = schema_defn.redefine do
|
645
|
+
schema_plugins.each do |plugin, options|
|
646
|
+
if options.any?
|
647
|
+
use(plugin, **options)
|
648
|
+
else
|
649
|
+
use(plugin)
|
650
|
+
end
|
651
|
+
end
|
652
|
+
end
|
653
|
+
end
|
654
|
+
schema_defn.send(:rebuild_artifacts)
|
655
|
+
|
656
|
+
schema_defn
|
657
|
+
end
|
658
|
+
|
659
|
+
def query(new_query_object = nil)
|
660
|
+
if new_query_object
|
661
|
+
@query_object = new_query_object
|
662
|
+
else
|
663
|
+
@query_object.respond_to?(:graphql_definition) ? @query_object.graphql_definition : @query_object
|
664
|
+
end
|
665
|
+
end
|
666
|
+
|
667
|
+
def mutation(new_mutation_object = nil)
|
668
|
+
if new_mutation_object
|
669
|
+
@mutation_object = new_mutation_object
|
670
|
+
else
|
671
|
+
@mutation_object.respond_to?(:graphql_definition) ? @mutation_object.graphql_definition : @mutation_object
|
672
|
+
end
|
673
|
+
end
|
674
|
+
|
675
|
+
def subscription(new_subscription_object = nil)
|
676
|
+
if new_subscription_object
|
677
|
+
@subscription_object = new_subscription_object
|
678
|
+
else
|
679
|
+
@subscription_object.respond_to?(:graphql_definition) ? @subscription_object.graphql_definition : @subscription_object
|
680
|
+
end
|
681
|
+
end
|
682
|
+
|
683
|
+
def default_max_page_size(new_default_max_page_size = nil)
|
684
|
+
if new_default_max_page_size
|
685
|
+
@default_max_page_size = new_default_max_page_size
|
686
|
+
else
|
687
|
+
@default_max_page_size
|
688
|
+
end
|
689
|
+
end
|
690
|
+
|
691
|
+
def max_depth(new_max_depth = nil)
|
692
|
+
if new_max_depth
|
693
|
+
@max_depth = new_max_depth
|
694
|
+
else
|
695
|
+
@max_depth
|
696
|
+
end
|
697
|
+
end
|
698
|
+
|
699
|
+
def orphan_types(new_orphan_types = nil)
|
700
|
+
if new_orphan_types
|
701
|
+
@orphan_types = new_orphan_types
|
702
|
+
else
|
703
|
+
@orphan_types || []
|
704
|
+
end
|
705
|
+
end
|
706
|
+
|
707
|
+
def default_execution_strategy
|
708
|
+
if superclass <= GraphQL::Schema
|
709
|
+
superclass.default_execution_strategy
|
710
|
+
else
|
711
|
+
@default_execution_strategy
|
712
|
+
end
|
713
|
+
end
|
714
|
+
|
715
|
+
def resolve_type(type, obj, ctx)
|
716
|
+
raise NotImplementedError, "#{self.name}.resolve_type(type, obj, ctx) must be implemented to use Union types or Interface types (tried to resolve: #{type.name})"
|
717
|
+
end
|
718
|
+
|
719
|
+
def object_from_id(node_id, ctx)
|
720
|
+
raise NotImplementedError, "#{self.name}.object_from_id(node_id, ctx) must be implemented to use the `node` field (tried to load from id `#{node_id}`)"
|
721
|
+
end
|
722
|
+
|
723
|
+
def id_from_object(object, type, ctx)
|
724
|
+
raise NotImplementedError, "#{self.name}.id_from_object(object, type, ctx) must be implemented to create global ids (tried to create an id for `#{object.inspect}`)"
|
725
|
+
end
|
726
|
+
|
727
|
+
def lazy_resolve(lazy_class, value_method)
|
728
|
+
lazy_classes[lazy_class] = value_method
|
729
|
+
end
|
730
|
+
|
731
|
+
def instrument(instrument_step, instrumenter, options = {})
|
732
|
+
step = if instrument_step == :field && options[:after_built_ins]
|
733
|
+
:field_after_built_ins
|
734
|
+
else
|
735
|
+
instrument_step
|
736
|
+
end
|
737
|
+
instrumenters[step] << instrumenter
|
738
|
+
end
|
739
|
+
|
740
|
+
def directives(new_directives = nil)
|
741
|
+
if new_directives
|
742
|
+
@directives = new_directives.reduce({}) { |m, d| m[d.name] = d; m }
|
743
|
+
end
|
744
|
+
@directives
|
745
|
+
end
|
746
|
+
|
747
|
+
private
|
748
|
+
|
749
|
+
def lazy_classes
|
750
|
+
@lazy_classes ||= {}
|
751
|
+
end
|
752
|
+
|
753
|
+
def instrumenters
|
754
|
+
@instrumenters ||= Hash.new { |h,k| h[k] = [] }
|
755
|
+
end
|
756
|
+
end
|
757
|
+
|
758
|
+
|
759
|
+
def self.inherited(child_class)
|
760
|
+
child_class.singleton_class.class_eval do
|
761
|
+
prepend(MethodWrappers)
|
762
|
+
end
|
763
|
+
end
|
764
|
+
|
765
|
+
module MethodWrappers
|
766
|
+
# Wrap the user-provided resolve-type in a correctness check
|
767
|
+
def resolve_type(type, obj, ctx = :__undefined__)
|
768
|
+
graphql_definition.check_resolved_type(type, obj, ctx) do |ok_type, ok_obj, ok_ctx|
|
769
|
+
super(ok_type, ok_obj, ok_ctx)
|
770
|
+
end
|
771
|
+
end
|
772
|
+
end
|
773
|
+
|
568
774
|
protected
|
569
775
|
|
570
776
|
def rescues?
|
@@ -585,6 +791,7 @@ module GraphQL
|
|
585
791
|
GraphQL::Relay::ConnectionInstrumentation,
|
586
792
|
GraphQL::Relay::EdgesInstrumentation,
|
587
793
|
GraphQL::Relay::Mutation::Instrumentation,
|
794
|
+
GraphQL::Schema::Member::Instrumentation,
|
588
795
|
]
|
589
796
|
|
590
797
|
def rebuild_artifacts
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module GraphQL
|
3
|
+
class Schema
|
4
|
+
class Argument
|
5
|
+
include GraphQL::Schema::Member::CachedGraphQLDefinition
|
6
|
+
|
7
|
+
NO_DEFAULT = :__no_default__
|
8
|
+
|
9
|
+
attr_reader :name
|
10
|
+
|
11
|
+
def initialize(arg_name, type_expr, desc = nil, required:, default_value: NO_DEFAULT)
|
12
|
+
@name = arg_name.to_s
|
13
|
+
@type_expr = type_expr
|
14
|
+
@description = desc
|
15
|
+
@null = !required
|
16
|
+
@default_value = default_value
|
17
|
+
end
|
18
|
+
|
19
|
+
def to_graphql
|
20
|
+
argument = GraphQL::Argument.new
|
21
|
+
argument.name = @name
|
22
|
+
argument.type = -> {
|
23
|
+
Member::BuildType.parse_type(@type_expr, null: @null)
|
24
|
+
}
|
25
|
+
argument.description = @description
|
26
|
+
if NO_DEFAULT != @default_value
|
27
|
+
argument.default_value = @default_value
|
28
|
+
end
|
29
|
+
argument
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -107,8 +107,6 @@ module GraphQL
|
|
107
107
|
directives directives.values
|
108
108
|
end
|
109
109
|
|
110
|
-
schema.ast_node = schema_definition if schema_definition
|
111
|
-
|
112
110
|
schema
|
113
111
|
end
|
114
112
|
|
@@ -119,26 +117,18 @@ module GraphQL
|
|
119
117
|
NullScalarCoerce = ->(val, _ctx) { val }
|
120
118
|
|
121
119
|
def build_enum_type(enum_type_definition, type_resolver)
|
122
|
-
|
120
|
+
GraphQL::EnumType.define(
|
123
121
|
name: enum_type_definition.name,
|
124
122
|
description: enum_type_definition.description,
|
125
123
|
values: enum_type_definition.values.map do |enum_value_definition|
|
126
|
-
|
124
|
+
EnumType::EnumValue.define(
|
127
125
|
name: enum_value_definition.name,
|
128
126
|
value: enum_value_definition.name,
|
129
127
|
deprecation_reason: build_deprecation_reason(enum_value_definition.directives),
|
130
128
|
description: enum_value_definition.description,
|
131
129
|
)
|
132
|
-
|
133
|
-
value.ast_node = enum_value_definition
|
134
|
-
|
135
|
-
value
|
136
130
|
end
|
137
131
|
)
|
138
|
-
|
139
|
-
enum.ast_node = enum_type_definition
|
140
|
-
|
141
|
-
enum
|
142
132
|
end
|
143
133
|
|
144
134
|
def build_deprecation_reason(directives)
|
@@ -158,8 +148,6 @@ module GraphQL
|
|
158
148
|
coerce: NullScalarCoerce,
|
159
149
|
)
|
160
150
|
|
161
|
-
scalar_type.ast_node = scalar_type_definition
|
162
|
-
|
163
151
|
if default_resolve.respond_to?(:coerce_input)
|
164
152
|
scalar_type = scalar_type.redefine(
|
165
153
|
coerce_input: ->(val, ctx) { default_resolve.coerce_input(scalar_type, val, ctx) },
|
@@ -171,15 +159,11 @@ module GraphQL
|
|
171
159
|
end
|
172
160
|
|
173
161
|
def build_union_type(union_type_definition, type_resolver)
|
174
|
-
|
162
|
+
GraphQL::UnionType.define(
|
175
163
|
name: union_type_definition.name,
|
176
164
|
description: union_type_definition.description,
|
177
165
|
possible_types: union_type_definition.types.map{ |type_name| type_resolver.call(type_name) },
|
178
166
|
)
|
179
|
-
|
180
|
-
union.ast_node = union_type_definition
|
181
|
-
|
182
|
-
union
|
183
167
|
end
|
184
168
|
|
185
169
|
def build_object_type(object_type_definition, type_resolver, default_resolve:)
|
@@ -191,20 +175,14 @@ module GraphQL
|
|
191
175
|
fields: Hash[build_fields(object_type_definition.fields, type_resolver, default_resolve: typed_resolve_fn)],
|
192
176
|
interfaces: object_type_definition.interfaces.map{ |interface_name| type_resolver.call(interface_name) },
|
193
177
|
)
|
194
|
-
type_def.ast_node = object_type_definition
|
195
|
-
type_def
|
196
178
|
end
|
197
179
|
|
198
180
|
def build_input_object_type(input_object_type_definition, type_resolver)
|
199
|
-
|
181
|
+
GraphQL::InputObjectType.define(
|
200
182
|
name: input_object_type_definition.name,
|
201
183
|
description: input_object_type_definition.description,
|
202
184
|
arguments: Hash[build_input_arguments(input_object_type_definition, type_resolver)],
|
203
185
|
)
|
204
|
-
|
205
|
-
input.ast_node = input_object_type_definition
|
206
|
-
|
207
|
-
input
|
208
186
|
end
|
209
187
|
|
210
188
|
def build_default_value(default_value)
|
@@ -213,10 +191,6 @@ module GraphQL
|
|
213
191
|
default_value.name
|
214
192
|
when GraphQL::Language::Nodes::NullValue
|
215
193
|
nil
|
216
|
-
when GraphQL::Language::Nodes::InputObject
|
217
|
-
default_value.to_h
|
218
|
-
when Array
|
219
|
-
default_value.map { |v| build_default_value(v) }
|
220
194
|
else
|
221
195
|
default_value
|
222
196
|
end
|
@@ -230,33 +204,25 @@ module GraphQL
|
|
230
204
|
kwargs[:default_value] = build_default_value(input_argument.default_value)
|
231
205
|
end
|
232
206
|
|
233
|
-
argument = GraphQL::Argument.define(
|
234
|
-
name: input_argument.name,
|
235
|
-
type: type_resolver.call(input_argument.type),
|
236
|
-
description: input_argument.description,
|
237
|
-
**kwargs,
|
238
|
-
)
|
239
|
-
|
240
|
-
argument.ast_node = input_object_type_definition
|
241
|
-
|
242
207
|
[
|
243
208
|
input_argument.name,
|
244
|
-
|
209
|
+
GraphQL::Argument.define(
|
210
|
+
name: input_argument.name,
|
211
|
+
type: type_resolver.call(input_argument.type),
|
212
|
+
description: input_argument.description,
|
213
|
+
**kwargs,
|
214
|
+
)
|
245
215
|
]
|
246
216
|
end
|
247
217
|
end
|
248
218
|
|
249
219
|
def build_directive(directive_definition, type_resolver)
|
250
|
-
|
220
|
+
GraphQL::Directive.define(
|
251
221
|
name: directive_definition.name,
|
252
222
|
description: directive_definition.description,
|
253
223
|
arguments: Hash[build_directive_arguments(directive_definition, type_resolver)],
|
254
224
|
locations: directive_definition.locations.map(&:to_sym),
|
255
225
|
)
|
256
|
-
|
257
|
-
directive.ast_node = directive_definition
|
258
|
-
|
259
|
-
directive
|
260
226
|
end
|
261
227
|
|
262
228
|
def build_directive_arguments(directive_definition, type_resolver)
|
@@ -267,32 +233,24 @@ module GraphQL
|
|
267
233
|
kwargs[:default_value] = build_default_value(directive_argument.default_value)
|
268
234
|
end
|
269
235
|
|
270
|
-
argument = GraphQL::Argument.define(
|
271
|
-
name: directive_argument.name,
|
272
|
-
type: type_resolver.call(directive_argument.type),
|
273
|
-
description: directive_argument.description,
|
274
|
-
**kwargs,
|
275
|
-
)
|
276
|
-
|
277
|
-
argument.ast_node = directive_argument
|
278
|
-
|
279
236
|
[
|
280
237
|
directive_argument.name,
|
281
|
-
|
238
|
+
GraphQL::Argument.define(
|
239
|
+
name: directive_argument.name,
|
240
|
+
type: type_resolver.call(directive_argument.type),
|
241
|
+
description: directive_argument.description,
|
242
|
+
**kwargs,
|
243
|
+
)
|
282
244
|
]
|
283
245
|
end
|
284
246
|
end
|
285
247
|
|
286
248
|
def build_interface_type(interface_type_definition, type_resolver)
|
287
|
-
|
249
|
+
GraphQL::InterfaceType.define(
|
288
250
|
name: interface_type_definition.name,
|
289
251
|
description: interface_type_definition.description,
|
290
252
|
fields: Hash[build_fields(interface_type_definition.fields, type_resolver, default_resolve: nil)],
|
291
253
|
)
|
292
|
-
|
293
|
-
interface.ast_node = interface_type_definition
|
294
|
-
|
295
|
-
interface
|
296
254
|
end
|
297
255
|
|
298
256
|
def build_fields(field_definitions, type_resolver, default_resolve:)
|
@@ -311,8 +269,6 @@ module GraphQL
|
|
311
269
|
**kwargs,
|
312
270
|
)
|
313
271
|
|
314
|
-
arg.ast_node = argument
|
315
|
-
|
316
272
|
[argument.name, arg]
|
317
273
|
end]
|
318
274
|
|
@@ -325,8 +281,6 @@ module GraphQL
|
|
325
281
|
deprecation_reason: build_deprecation_reason(field_definition.directives),
|
326
282
|
)
|
327
283
|
|
328
|
-
field.ast_node = field_definition
|
329
|
-
|
330
284
|
type_name = resolve_type_name(field_definition.type)
|
331
285
|
field.connection = type_name.end_with?("Connection")
|
332
286
|
[field_definition.name, field]
|