Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# https://github.com/graphql-python/graphene/issues/956 is fixed
deprecation_reason = getattr(enum_cls, "__deprecation_reason__", None)
if deprecation_reason:
options.setdefault("deprecation_reason", deprecation_reason)
type_name = type_name or (enum_cls.__name__ + "Enum")
enum_data = [(str_to_enum(code.upper()), code) for code, name in enum_cls.CHOICES]
return graphene.Enum(type_name, enum_data, **options)
TaxRateType = graphene.Enum(
"TaxRateType", [(str_to_enum(rate[0]), rate[0]) for rate in CoreTaxRateType.CHOICES]
)
PermissionEnum = graphene.Enum(
"PermissionEnum",
[
(str_to_enum(codename.split(".")[1]), codename)
for codename in MODELS_PERMISSIONS
],
)
WeightUnitsEnum = graphene.Enum(
"WeightUnitsEnum", [(str_to_enum(unit[0]), unit[0]) for unit in WeightUnits.CHOICES]
)
)
def resolve_repository(self, info):
return Repository.from_db(
repos_models.Repository.objects.get(id=self.repository)
)
class DependencyUsageConnection(relay.Connection):
total_count = graphene.Int()
class Meta:
node = DependencyUsage
CheckResultStatusEnum = graphene.Enum.from_enum(CheckResultStatus)
class CheckResult(graphene.ObjectType):
kind_key = graphene.String()
is_found = graphene.Boolean()
status = graphene.Field(CheckResultStatusEnum)
severity = graphene.Field(IssueSeverityEnum)
effort = graphene.Field(IssueEffortEnum)
details = JSONString()
title = graphene.String()
description = graphene.String()
@property
def kind(self):
return check_discovery.KINDS[self.kind_key]
def convert_choice_to_enum(type, column, registry=None):
name = "{}_{}".format(column.table.name, column.name).upper()
if isinstance(type.choices, EnumMeta):
# type.choices may be Enum/IntEnum, in ChoiceType both presented as EnumMeta
# do not use from_enum here because we can have more than one enum column in table
return Enum(name, list((v.name, v.value) for v in type.choices))
else:
return Enum(name, type.choices)
def nullable_enum_from_field(_model, _field):
field = _model._meta.get_field(_field)
choices = getattr(field, "choices", None)
if choices:
meta = field.model._meta
name = to_camel_case("my{}_{}".format(meta.object_name, field.name))
choices = list(get_choices(choices))
named_choices = [(c[0], c[1]) for c in choices]
named_choices_descriptions = {c[0]: c[2] for c in choices}
class EnumWithDescriptionsType(object):
@property
def description(self):
return named_choices_descriptions[self.name]
enum = graphene.Enum(name, list(named_choices), type=EnumWithDescriptionsType)
converted = enum(
description=field.help_text, required=not (field.null or field.blank)
)
else:
raise NotImplementedError("Field does NOT have choices")
return converted
:param items:
:param is_filterable_func:
:param get_type_func:
:return:
"""
params = {}
for field, value in items:
if is_filterable_func(field):
# Getting other backend specific fields (schema dependant)
if self.field_belongs_to(field):
params.update({field: field})
return {
self.prefix: graphene.Argument(
graphene.List(
graphene.Enum.from_enum(
enum.Enum(
"{}{}{}BackendEnum".format(
DYNAMIC_CLASS_NAME_PREFIX,
to_pascal_case(self.prefix),
self.connection_field.type.__name__
),
params
)
return datetime.datetime.strptime(value, "%Y-%m-%dT%H:%M:%S.%f")
# Profile enums
class Alg(graphene.Enum):
"""
Supported signature algorithms
"""
HS256 = "HS256"
RS256 = "RS256"
RSA = "RSA"
ED25519 = "ED25519"
class Typ(graphene.Enum):
"""
Supported signature types
"""
JWT = "JWT"
PGP = "PGP"
class Classification(graphene.Enum):
"""
Mozilla data classification
"""
MOZILLA_CONFIDENTIAL = "MOZILLA CONFIDENTIAL"
PUBLIC = "PUBLIC"
WORKGROUP_CONFIDENTIAL = "WORKGROUP CONFIDENTIAL"
# from graphene_django import DjangoObjectType
from sentry.api.graphql_query import QueryMaster
# from sentry.api.event_search import get_snuba_query_args
# from sentry.api.bases.organization import OrganizationPermission
# from sentry.api.bases.group import GroupPermission
# from sentry.api.bases.project import ProjectPermission, ProjectEventPermission
# from sentry.api.bases.project import ProjectEventPermission
from sentry.api.graphql_type import SentryGraphQLType
from sentry.models import Group, Organization, Project
# from sentry.models.event import SnubaEvent
# from sentry.utils.snuba import raw_query
import graphene
class OrgStatus(graphene.Enum):
ACTIVE = 0
PENDING_DELETION = 1
DELETION_IN_PROGRESS = 2
# class OrganizationType(SentryGraphQLType):
# class Meta:
# model = Organization
# only_fields = ('slug', 'name', 'status',
# 'date_added', 'default_role', 'flags', 'project_set')
#
# status = graphene.Field(OrgStatus)
#
# project_set = graphene.Field(
# graphene.List('sentry.api.graphql.ProjectType'),
# slug=graphene.String()
return [ExecutionStepInput(inp) for inp in self.execution_step.step_inputs]
def resolve_outputs(self, _info):
return [ExecutionStepOutput(out) for out in self.execution_step.step_outputs]
def resolve_name(self, _info):
return self.execution_step.key
def resolve_solid(self, _info):
return Solid(self.execution_step.solid)
def resolve_tag(self, _info):
return self.execution_step.tag
class EvaluationErrorReason(graphene.Enum):
RUNTIME_TYPE_MISMATCH = 'RUNTIME_TYPE_MISMATCH'
MISSING_REQUIRED_FIELD = 'MISSING_REQUIRED_FIELD'
FIELD_NOT_DEFINED = 'FIELD_NOT_DEFINED'
SELECTOR_FIELD_ERROR = 'SELECTOR_FIELD_ERROR'
class EvaluationStackListItemEntry(graphene.ObjectType):
def __init__(self, list_index):
super(EvaluationStackListItemEntry, self).__init__()
self._list_index = list_index
list_index = graphene.NonNull(graphene.Int)
def resolve_list_index(self, _info):
return self._list_index
def convert_choices_to_named_enum_with_descriptions(name, choices):
choices = list(get_choices(choices))
named_choices = [(c[0], c[1]) for c in choices]
named_choices_descriptions = {c[0]: c[2] for c in choices}
class EnumWithDescriptionsType(object):
@property
def description(self):
return named_choices_descriptions[self.name]
return Enum(name, list(named_choices), type=EnumWithDescriptionsType)
"""
class TaskID(String):
"""The name of an active task."""
class JobID(String):
"""A job submission from an active task."""
class TimePoint(String):
"""A date-time in the ISO8601 format."""
LogLevels = Enum(
'LogLevels',
list(logging._nameToLevel.items()),
description=lambda x: f'Python logging level: {x.name} = {x.value}.'
if x else ''
)
class SuiteStopMode(Enum):
"""The mode used to stop a running workflow."""
# Note: contains only the REQUEST_* values from StopMode
Clean = StopMode.REQUEST_CLEAN
Now = StopMode.REQUEST_NOW
NowNow = StopMode.REQUEST_NOW_NOW
@property