Module: GraphQL::Schema::Interface::DefinitionMethods Private

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Instance Method Summary collapse

Methods included from Member::HasFields

add_default_resolve_module, #add_field, extended, #field, #field_class, #fields, #global_id_field, #inherited, #own_fields

Methods included from Member::TypeSystemHelpers

#list?, #non_null?, #to_list_type, #to_non_null_type, #to_type_signature

Methods included from Member::BaseDSLMethods

#authorized?, #description, #graphql_name, #introspection, #mutation, #name, #overridden_graphql_name

Methods included from Relay::TypeExtensions

#connection_type, #define_connection, #define_edge, #edge_type

Methods included from Member::CachedGraphQLDefinition

#graphql_definition, #initialize_copy

Instance Method Details

#accessible?(context) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The interface is accessible if any of its possible types are accessible

Returns:



31
32
33
34
35
36
37
38
# File 'lib/graphql/schema/interface.rb', line 31

def accessible?(context)
  context.schema.possible_types(self).each do |type|
    if context.schema.accessible?(type, context)
      return true
    end
  end
  false
end

#definition_methods(&block) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Methods defined in this block will be: - Added as class methods to this interface - Added as class methods to all child interfaces



16
17
18
# File 'lib/graphql/schema/interface.rb', line 16

def definition_methods(&block)
  self::DefinitionMethods.module_eval(&block)
end

#included(child_class) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Here’s the tricky part. Make sure behavior keeps making its way down the inheritance chain.



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
# File 'lib/graphql/schema/interface.rb', line 41

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

    # 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

    # We need this before we can call `own_interfaces`
    child_class.extend(Schema::Interface::DefinitionMethods)

    child_class.own_interfaces << self
    child_class.interfaces.each do |interface_defn|
      child_class.extend(interface_defn::DefinitionMethods)
    end
  elsif child_class < GraphQL::Schema::Object
    # Add all definition methods of this interface and the interfaces it
    # includes onto the child class.
    (interfaces + [self] - [GraphQL::Schema::Interface]).each do |interface_defn|
      child_class.extend(interface_defn::DefinitionMethods)
    end

    # This is being included into an object type, make sure it's using `implements(...)`
    backtrace_line = caller(0, 10).find { |line| line.include?("schema/object.rb") && line.include?("in `implements'")}
    if !backtrace_line
      raise "Attach interfaces using `implements(#{self})`, not `include(#{self})`"
    end
  end

  super
end

#kindObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



106
107
108
# File 'lib/graphql/schema/interface.rb', line 106

def kind
  GraphQL::TypeKinds::INTERFACE
end

#orphan_types(*types) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



80
81
82
83
84
85
86
87
88
# File 'lib/graphql/schema/interface.rb', line 80

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

#to_graphqlObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/graphql/schema/interface.rb', line 90

def to_graphql
  type_defn = GraphQL::InterfaceType.new
  type_defn.name = graphql_name
  type_defn.description = description
  type_defn.orphan_types = orphan_types
  fields.each do |field_name, field_inst|
    field_defn = field_inst.graphql_definition
    type_defn.fields[field_defn.name] = field_defn
  end
  type_defn.[:type_class] = self
  if respond_to?(:resolve_type)
    type_defn.resolve_type = method(:resolve_type)
  end
  type_defn
end

#visible?(context) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The interface is visible if any of its possible types are visible

Returns:



21
22
23
24
25
26
27
28
# File 'lib/graphql/schema/interface.rb', line 21

def visible?(context)
  context.schema.possible_types(self).each do |type|
    if context.schema.visible?(type, context)
      return true
    end
  end
  false
end