Module: GraphQL::Schema::Member::HasFields::ObjectMethods Private
- Defined in:
- lib/graphql/schema/member/has_fields.rb
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
-
#fields(context = GraphQL::Query::NullContext.instance) ⇒ Hash<String => GraphQL::Schema::Field>
private
Fields on this object, keyed by name, including inherited fields.
- #get_field(field_name, context = GraphQL::Query::NullContext.instance) ⇒ Object private
Instance Method Details
#fields(context = GraphQL::Query::NullContext.instance) ⇒ Hash<String => GraphQL::Schema::Field>
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.
Returns Fields on this object, keyed by name, including inherited fields.
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/graphql/schema/member/has_fields.rb', line 165 def fields(context = GraphQL::Query::NullContext.instance) # Objects need to check that the interface implementation is visible, too warden = Warden.from_context(context) # Local overrides take precedence over inherited fields visible_fields = {} had_any_fields_at_all = false for ancestor in ancestors if ancestor.respond_to?(:own_fields) && visible_interface_implementation?(ancestor, context, warden) ancestor.own_fields.each do |field_name, fields_entry| had_any_fields_at_all = true # 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 if !had_any_fields_at_all && !has_no_fields? warn(GraphQL::Schema::Object::FieldsAreRequiredError.new(self). + "\n\nThis will raise an error in a future GraphQL-Ruby version.") end visible_fields end |
#get_field(field_name, context = GraphQL::Query::NullContext.instance) ⇒ 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.
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/graphql/schema/member/has_fields.rb', line 146 def get_field(field_name, context = GraphQL::Query::NullContext.instance) # Objects need to check that the interface implementation is visible, too warden = Warden.from_context(context) ancs = ancestors skip_visible = context.respond_to?(:types) && context.types.is_a?(GraphQL::Schema::Visibility::Profile) i = 0 while (ancestor = ancs[i]) if ancestor.respond_to?(:own_fields) && visible_interface_implementation?(ancestor, context, warden) && (f_entry = ancestor.own_fields[field_name]) && (skip_visible || (f_entry = Warden.visible_entry?(:visible_field?, f_entry, context, warden))) return (skip_visible ? f_entry : f_entry.ensure_loaded) end i += 1 end nil end |