Module: GraphQL::Schema::Member::HasFields::InterfaceMethods

Defined in:
lib/graphql/schema/member/has_fields.rb

Overview

-- @requires_ancestor: Module

Instance Method Summary collapse

Instance Method Details

#fields(context = GraphQL::Query::NullContext.instance) ⇒ Object

Returns

  • Hash<String => GraphQL::Schema::Field> — Fields on this object, keyed by name, including inherited fields

:call-seq:

fields(context:) -> Hash[String, GraphQL::Schema::Field]


270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
# File 'lib/graphql/schema/member/has_fields.rb', line 270

def fields(context = GraphQL::Query::NullContext.instance)
  warden = Warden.from_context(context)
  # Local overrides take precedence over inherited fields
  visible_fields = {}
  all_ancestors = ancestors #: Array[untyped]
  for ancestor in all_ancestors
    if ancestor.respond_to?(:own_fields)
      ancestor.own_fields.each do |field_name, fields_entry|
        # Choose the most local definition that passes `.visible?` --
        # stop checking for fields by name once one has been found.
        if !visible_fields.key?(field_name) && (f = Warden.visible_entry?(:visible_field?, fields_entry, context, warden))
          visible_fields[field_name] = f.ensure_loaded
        end
      end
    end
  end
  visible_fields
end

#get_field(field_name, context = GraphQL::Query::NullContext.instance) ⇒ Object



250
251
252
253
254
255
256
257
258
259
260
261
262
# File 'lib/graphql/schema/member/has_fields.rb', line 250

def get_field(field_name, context = GraphQL::Query::NullContext.instance)
  warden = Warden.from_context(context)
  skip_visible = context.respond_to?(:types) && context.types.is_a?(GraphQL::Schema::Visibility::Profile)
  all_ancestors = ancestors #: Array[untyped]
  for ancestor in all_ancestors
    if ancestor.respond_to?(:own_fields) &&
        (f_entry = ancestor.own_fields[field_name]) &&
        (skip_visible || (f_entry = Warden.visible_entry?(:visible_field?, f_entry, context, warden)))
      return f_entry
    end
  end
  nil
end