Class: Types::BaseObject

Inherits:
GraphQL::Schema::Object
  • Object
show all
Includes:
Gitlab::Graphql::ExposePermissions, Gitlab::Graphql::MarkdownField, Gitlab::Graphql::Present
Defined in:
app/graphql/types/base_object.rb

Direct Known Subclasses

AccessLevelType, Admin::Analytics::UsageTrends::MeasurementType, Admin::SidekiqQueues::DeleteJobsResponseType, AlertManagement::AlertStatusCountsType, AlertManagement::AlertType, AlertManagement::HttpIntegrationType, AlertManagement::PrometheusIntegrationType, AwardEmojis::AwardEmojiType, BlobViewerType, BoardListType, BoardType, BranchType, Ci::AnalyticsType, Ci::ApplicationSettingType, Ci::BuildNeedType, Ci::CiCdSettingType, Ci::Config::ConfigType, Ci::Config::GroupType, Ci::Config::IncludeType, Ci::Config::JobRestrictionType, Ci::Config::JobType, Ci::Config::NeedType, Ci::Config::StageType, Ci::DetailedStatusType, Ci::GroupType, Ci::JobArtifactType, Ci::JobTokenScopeType, Ci::JobType, Ci::PipelineCountsType, Ci::PipelineMessageType, Ci::PipelineType, Ci::RecentFailuresType, Ci::RunnerArchitectureType, Ci::RunnerPlatformType, Ci::RunnerSetupType, Ci::RunnerType, Ci::StageType, Ci::StatusActionType, Ci::TemplateType, Ci::TestCaseType, Ci::TestReportSummaryType, Ci::TestReportTotalType, Ci::TestSuiteSummaryType, Ci::TestSuiteType, CiConfiguration::Sast::AnalyzersEntityType, CiConfiguration::Sast::EntityType, CiConfiguration::Sast::OptionsEntityType, CiConfiguration::Sast::Type, Clusters::AgentActivityEventType, Clusters::AgentTokenType, Clusters::AgentType, CommitType, ContainerExpirationPolicyType, ContainerRepositoryTagType, ContainerRepositoryType, CustomEmojiType, CustomerRelations::ContactType, CustomerRelations::OrganizationType, DesignManagement::DesignAtVersionType, DesignManagement::DesignCollectionType, DesignManagement::DesignType, DesignManagement::VersionType, DesignManagementType, DiffRefsType, DiffStatsSummaryType, DiffStatsType, EnvironmentType, ErrorTracking::SentryDetailedErrorType, ErrorTracking::SentryErrorCollectionType, ErrorTracking::SentryErrorFrequencyType, ErrorTracking::SentryErrorStackTraceContextType, ErrorTracking::SentryErrorStackTraceEntryType, ErrorTracking::SentryErrorStackTraceType, ErrorTracking::SentryErrorTagsType, ErrorTracking::SentryErrorType, EventType, EvidenceType, GrafanaIntegrationType, GroupInvitationType, GroupMemberType, IssueStatusCountsType, IssueType, JiraImportType, JiraUserType, Kas::AgentConfigurationType, Kas::AgentConnectionType, Kas::AgentMetadataType, LabelType, MergeRequestType, Metadata::KasType, MetadataType, Metrics::DashboardType, Metrics::Dashboards::AnnotationType, MilestoneStatsType, MilestoneType, MutationType, NamespaceType, Notes::DiffPositionType, Notes::DiscussionType, Notes::NoteType, Packages::Composer::JsonType, Packages::Composer::MetadatumType, Packages::Conan::FileMetadatumType, Packages::Conan::MetadatumType, Packages::Helm::DependencyType, Packages::Helm::FileMetadatumType, Packages::Helm::MaintainerType, Packages::Helm::MetadataType, Packages::Maven::MetadatumType, Packages::Nuget::DependencyLinkMetadatumType, Packages::Nuget::MetadatumType, Packages::PackageDependencyLinkType, Packages::PackageDependencyType, Packages::PackageFileType, Packages::PackageTagType, Packages::PackageType, Packages::Pypi::MetadatumType, PermissionTypes::BasePermissionType, ProjectInvitationType, ProjectMemberType, ProjectStatisticsType, ProjectType, Projects::Services::BaseServiceType, Projects::Services::JiraProjectType, Projects::Services::JiraServiceType, Projects::TopicType, PrometheusAlertType, QueryComplexityType, QueryType, ReleaseAssetLinkType, ReleaseAssetsType, ReleaseLinksType, ReleaseSourceType, ReleaseType, Repository::BlobType, RepositoryType, RootStorageStatisticsType, SavedReplyType, SnippetType, Snippets::BlobType, SubscriptionType, TaskCompletionStatus, Terraform::StateType, Terraform::StateVersionType, TimelogType, TodoType, Tree::BlobType, Tree::SubmoduleType, Tree::TreeEntryType, Tree::TreeType, UserCalloutType, UserMergeRequestInteractionType, UserPreferencesType, UserStatusType, UserType, WorkItemType, WorkItems::TypeType

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Gitlab::Graphql::Present

#present, #unpresented

Class Method Details

.accepts(*types) ⇒ Object


19
20
21
22
23
# File 'app/graphql/types/base_object.rb', line 19

def self.accepts(*types)
  @accepts ||= []
  @accepts += types
  @accepts
end

.assignable?(object) ⇒ Boolean

Returns:

  • (Boolean)

42
43
44
45
46
47
48
# File 'app/graphql/types/base_object.rb', line 42

def self.assignable?(object)
  assignable = accepts

  return true if assignable.blank?

  assignable.any? { |cls| object.is_a?(cls) }
end

.authorizationObject


30
31
32
# File 'app/graphql/types/base_object.rb', line 30

def self.authorization
  @authorization ||= ::Gitlab::Graphql::Authorize::ObjectAuthorization.new(authorize)
end

.authorize(*args) ⇒ Object


12
13
14
15
16
17
# File 'app/graphql/types/base_object.rb', line 12

def self.authorize(*args)
  raise 'Cannot redefine authorize' if @authorize_args && args.any?

  @authorize_args = args.freeze if args.any?
  @authorize_args || (superclass.respond_to?(:authorize) ? superclass.authorize : nil)
end

.authorized?(object, context) ⇒ Boolean

Returns:

  • (Boolean)

34
35
36
# File 'app/graphql/types/base_object.rb', line 34

def self.authorized?(object, context)
  authorization.ok?(object, context[:current_user])
end

Instance Method Details

#current_userObject


38
39
40
# File 'app/graphql/types/base_object.rb', line 38

def current_user
  context[:current_user]
end

#idObject

All graphql fields exposing an id, should expose a global id.


26
27
28
# File 'app/graphql/types/base_object.rb', line 26

def id
  GitlabSchema.id_from_object(object)
end