Module: GraphQL::Schema::Interface::DefinitionMethods
- Includes:
- Member::BaseDSLMethods, Member::HasAstNode, Member::HasDirectives, Member::HasFields, Member::HasInterfaces, Member::HasPath, Member::HasUnresolvedTypeError, Member::RelayShortcuts, Member::Scoped, Member::TypeSystemHelpers
- Included in:
- GraphQL::Schema::Interface
- Defined in:
- lib/graphql/schema/interface.rb
Constant Summary
Constants included from Member::HasDirectives
Member::HasDirectives::NO_DIRECTIVES
Constants included from Member::HasFields
Member::HasFields::CONFLICT_FIELD_NAMES, Member::HasFields::GRAPHQL_RUBY_KEYWORDS, Member::HasFields::RUBY_KEYWORDS
Instance Attribute Summary
Attributes included from Member::HasAstNode
Attributes included from Member::RelayShortcuts
#connection_type, #connection_type_class, #edge_type, #edge_type_class
Attributes included from Member::BaseDSLMethods
#default_graphql_name, #graphql_name
Instance Method Summary collapse
-
#definition_methods(&block) ⇒ Object
Methods defined in this block will be: - Added as class methods to this interface - Added as class methods to all child interfaces.
-
#included(child_class) ⇒ Object
Here’s the tricky part.
-
#kind ⇒ Object
-
#orphan_types(*types) ⇒ Object
-
#type_membership_class(membership_class = nil) ⇒ Object
-
#visible?(context) ⇒ Boolean
Methods included from Member::HasInterfaces
#implements, #interface_type_memberships, #interfaces, #own_interface_type_memberships
Methods included from Member::HasDirectives
add_directive, #directive, #directives, get_directives, #inherited, #remove_directive, remove_directive
Methods included from Member::HasAstNode
Methods included from Member::Scoped
Methods included from Member::HasPath
Methods included from Member::HasFields
#add_field, #all_field_definitions, #field, #field_class, #fields, #get_field, #global_id_field, #own_fields
Methods included from Member::TypeSystemHelpers
#initialize, #list?, #non_null?, #to_list_type, #to_non_null_type, #to_type_signature
Methods included from Member::BaseDSLMethods
#authorized?, #default_relay, #description, #introspection, #introspection?, #mutation, #name
Instance Method Details
#definition_methods(&block) ⇒ Object
Methods defined in this block will be: - Added as class methods to this interface - Added as class methods to all child interfaces
22 23 24 |
# File 'lib/graphql/schema/interface.rb', line 22 def definition_methods(&block) self::DefinitionMethods.module_eval(&block) end |
#included(child_class) ⇒ Object
Here’s the tricky part. Make sure behavior keeps making its way down the inheritance chain.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/graphql/schema/interface.rb', line 40 def included(child_class) if !child_class.is_a?(Class) # In this case, it's been included into another interface. # This is how interface inheritance is implemented # We need this before we can call `own_interfaces` child_class.extend(Schema::Interface::DefinitionMethods) child_class.type_membership_class(self.type_membership_class) child_class.ancestors.reverse_each do |ancestor| if ancestor.const_defined?(:DefinitionMethods) child_class.extend(ancestor::DefinitionMethods) end end # Use an instance variable to tell whether it's been included previously or not; # You can't use constant detection because constants are brought into scope # by `include`, which has already happened at this point. if !child_class.instance_variable_defined?(:@_definition_methods) defn_methods_module = Module.new child_class.instance_variable_set(:@_definition_methods, defn_methods_module) child_class.const_set(:DefinitionMethods, defn_methods_module) child_class.extend(child_class::DefinitionMethods) end child_class.introspection(introspection) child_class.description(description) # If interfaces are mixed into each other, only define this class once if !child_class.const_defined?(:UnresolvedTypeError, false) add_unresolved_type_error(child_class) end elsif child_class < GraphQL::Schema::Object # This is being included into an object type, make sure it's using `implements(...)` backtrace_line = caller(0, 10).find { |line| line.include?("schema/member/has_interfaces.rb") && line.include?("in `implements'")} if !backtrace_line raise "Attach interfaces using `implements(#{self})`, not `include(#{self})`" end end super end |
#kind ⇒ Object
91 92 93 |
# File 'lib/graphql/schema/interface.rb', line 91 def kind GraphQL::TypeKinds::INTERFACE end |
#orphan_types(*types) ⇒ Object
81 82 83 84 85 86 87 88 89 |
# File 'lib/graphql/schema/interface.rb', line 81 def orphan_types(*types) if types.any? @orphan_types = types else all_orphan_types = @orphan_types || [] all_orphan_types += super if defined?(super) all_orphan_types.uniq end end |
#type_membership_class(membership_class = nil) ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/graphql/schema/interface.rb', line 31 def type_membership_class(membership_class = nil) if membership_class @type_membership_class = membership_class else @type_membership_class || find_inherited_value(:type_membership_class, GraphQL::Schema::TypeMembership) end end |
#visible?(context) ⇒ Boolean
27 28 29 |
# File 'lib/graphql/schema/interface.rb', line 27 def visible?(context) true end |