Class: GraphQL::Schema::BuildFromDefinition::Builder::TypeResolver
- Inherits:
-
Object
- Object
- GraphQL::Schema::BuildFromDefinition::Builder::TypeResolver
- Defined in:
- lib/graphql/schema/build_from_definition.rb
Instance Attribute Summary collapse
-
#build_interface ⇒ Object
writeonly
Sets the attribute build_interface.
-
#links ⇒ Object
Returns the value of attribute links.
-
#queued_directives ⇒ Object
readonly
Directive applications waiting for #apply_queued_directives.
Instance Method Summary collapse
- #build_interface_now(interface_name) ⇒ Object
- #call(ast_node) ⇒ Object
-
#directive_class(name) ⇒ Object
The already-defined directive class named
name, ornilif there isn't one yet. - #directive_without_arguments?(name) ⇒ Boolean
- #field_resolve_methods ⇒ Object
-
#get_argument(owner, argument_name) ⇒ Object
Like
owner.get_argument(argument_name), but cached. -
#initialize(lookup_hash, directives, queued_directives, type_classes, &missing_type_handler) ⇒ TypeResolver
constructor
A new instance of TypeResolver.
- #interface_module(type_name, base_type) ⇒ Object
-
#register(type) ⇒ Object
Add
typeto the lookup hash. -
#type_class(type_name, base_type) ⇒ Object
The class made ahead of time for
type_name(returned once, to be built), or a new subclass ofbase_type.
Constructor Details
#initialize(lookup_hash, directives, queued_directives, type_classes, &missing_type_handler) ⇒ TypeResolver
Returns a new instance of TypeResolver.
823 824 825 826 827 828 829 |
# File 'lib/graphql/schema/build_from_definition.rb', line 823 def initialize(lookup_hash, directives, queued_directives, type_classes, &missing_type_handler) @lookup_hash = lookup_hash @directives = directives @queued_directives = queued_directives @type_classes = type_classes @missing_type_handler = missing_type_handler end |
Instance Attribute Details
#build_interface=(value) ⇒ Object (writeonly)
Sets the attribute build_interface
843 844 845 |
# File 'lib/graphql/schema/build_from_definition.rb', line 843 def build_interface=(value) @build_interface = value end |
#links ⇒ Object
Returns the value of attribute links.
845 846 847 |
# File 'lib/graphql/schema/build_from_definition.rb', line 845 def links @links end |
#queued_directives ⇒ Object (readonly)
Directive applications waiting for GraphQL::Schema::BuildFromDefinition::Builder#apply_queued_directives
852 853 854 |
# File 'lib/graphql/schema/build_from_definition.rb', line 852 def queued_directives @queued_directives end |
Instance Method Details
#build_interface_now(interface_name) ⇒ Object
847 848 849 |
# File 'lib/graphql/schema/build_from_definition.rb', line 847 def build_interface_now(interface_name) @build_interface&.call(interface_name, self) end |
#call(ast_node) ⇒ Object
891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 |
# File 'lib/graphql/schema/build_from_definition.rb', line 891 def call(ast_node) case ast_node when GraphQL::Language::Nodes::TypeName type_name = ast_node.name if @lookup_hash.key?(type_name) @lookup_hash[type_name] else @missing_type_handler.call(type_name) end when GraphQL::Language::Nodes::NonNullType call(ast_node.of_type).to_non_null_type when GraphQL::Language::Nodes::ListType call(ast_node.of_type).to_list_type when String @directives[ast_node] ||= @missing_type_handler.call(ast_node) else raise "Unexpected ast_node: #{ast_node.inspect}" end end |
#directive_class(name) ⇒ Object
The already-defined directive class named name, or nil if there isn't one yet
876 877 878 |
# File 'lib/graphql/schema/build_from_definition.rb', line 876 def directive_class(name) @directives[name] end |
#directive_without_arguments?(name) ⇒ Boolean
880 881 882 883 884 885 886 887 888 889 |
# File 'lib/graphql/schema/build_from_definition.rb', line 880 def directive_without_arguments?(name) @directives_without_arguments ||= {} if @directives_without_arguments.key?(name) @directives_without_arguments[name] else dir_class = @directives[name] # Don't cache unknown directives, they might be defined later dir_class ? (@directives_without_arguments[name] = dir_class.all_argument_definitions.empty?) : false end end |
#field_resolve_methods ⇒ Object
866 867 868 |
# File 'lib/graphql/schema/build_from_definition.rb', line 866 def field_resolve_methods @field_resolve_methods ||= FieldResolveMethods.new end |
#get_argument(owner, argument_name) ⇒ Object
Like owner.get_argument(argument_name), but cached. Directives are applied after types are built,
so their arguments don't change while this cache is used.
856 857 858 859 860 861 862 863 864 |
# File 'lib/graphql/schema/build_from_definition.rb', line 856 def get_argument(owner, argument_name) @arguments_by_owner ||= {}.compare_by_identity owner_arguments = @arguments_by_owner[owner] ||= {} if owner_arguments.key?(argument_name) owner_arguments[argument_name] else owner_arguments[argument_name] = owner.get_argument(argument_name) end end |
#interface_module(type_name, base_type) ⇒ Object
839 840 841 |
# File 'lib/graphql/schema/build_from_definition.rb', line 839 def interface_module(type_name, base_type) @type_classes.delete(type_name) || Builder.new_interface_module(type_name, base_type) end |
#register(type) ⇒ Object
Add type to the lookup hash. Types call this before building their members, so that references back to them (including cycles) find this type.
871 872 873 |
# File 'lib/graphql/schema/build_from_definition.rb', line 871 def register(type) @lookup_hash[type.graphql_name] = type end |
#type_class(type_name, base_type) ⇒ Object
The class made ahead of time for type_name (returned once, to be built), or a new subclass of base_type
832 833 834 835 836 837 |
# File 'lib/graphql/schema/build_from_definition.rb', line 832 def type_class(type_name, base_type) @type_classes.delete(type_name) || Class.new(base_type) { #: self as singleton(GraphQL::Schema::Member) graphql_name(type_name) } end |