class Voyage(ObjectType): class Meta: interfaces = (Node, ) id = ID(required=True) created = DateTime() modified = DateTime() name = String() media = Field('Media') owner = Field('User') members = List('User') comment_counts = GenericScalar() def resolve_comment_counts(root, info): # Initialize a dictionary with 0 comment count per chapter base_dict = dict.fromkeys(root.chapters, 0) counts = (db.session.query(Comment.chapter, func.count( Comment.id)).filter(Comment.voyage == root).group_by( Comment.chapter)).all() base_dict.update(dict(counts)) return base_dict
class Input: worker = IntID(required=True) begin = DateTime(required=True) end = DateTime(required=True) time = Time() reason = IntID(required=True) comment = String()
def __init__(self): super(PositiveControlsField, self).__init__( PositiveControl, ids=graphene.List(graphene.ID), entered_after=DateTime(), entered_before=DateTime(), )
class User(ObjectType): login = String() id = Int() avatar_url = String() gravatar_id = String() url = String() html_url = String() followers_url = String() following_url = String() gists_url = String() starred_url = String() subscriptions_url = String() organizations_url = String() repos_url = String() events_url = String() received_events_url = String() type = String() site_admin = Boolean() name = String() company = String() blog = String() location = String() email = String() hireable = Boolean() bio = String() repos = Int() gists = Int() followers = Int() following = Int() created_at = DateTime() updated_at = DateTime()
class User(ObjectType): id = ID() created = DateTime() modified = DateTime() name = String() email = String() profile_picture = String()
class UpdateContestInput(graphene.InputObjectType): name = graphene.String() short_description = graphene.String() description = graphene.String() start_time = DateTime() freezed = graphene.Boolean() finish_time = DateTime() permitted_languages = graphene.List(graphene.String)
class Input: id = IntID(required=True, description='ID отсутствия для изменения') worker = IntID(required=True) begin = DateTime(required=True) end = DateTime(required=True) time = Time() reason = IntID(required=True) comment = String()
def __init__(self): super(ProficiencySamplesField, self).__init__( ProficiencySample, ids=graphene.List(graphene.ID), source=graphene.String(), vnum_prefix=graphene.String(), received_after=DateTime(), received_before=DateTime(), )
class ContestInput(graphene.InputObjectType): name = graphene.String(required=True) short_id = graphene.String(required=True) short_description = graphene.String(required=True) description = graphene.String( default_value='Just another competitive programming competition') start_time = DateTime() freezed = graphene.Boolean(default_value=False) finish_time = DateTime()
def __init__(self): super(PatientsField, self).__init__( Patient, ptnums=graphene.List(graphene.ID), name_prefix=graphene.String(), name_fuzzymatch=graphene.String(), mrid=graphene.String(), birthday_start=DateTime(), birthday_end=DateTime(), )
class Review(ObjectType): """ Review GraphQL ObjectType """ id = ID() text = String() reviewer = Field(lambda: User) created_at = DateTime() updated_at = DateTime() def resolve_reviewer(self, info): """ return the Reviewer object """ return _json_object_hook(self.reviewer)
class Comment(ObjectType): class Meta: interfaces = (Node, ) id = ID(required=True) created = DateTime() modified = DateTime() user = Field('User') voyage = Field('Voyage') text = String() chapter = String()
class Input: id = IntID(required=True) login = String(required=True) last_name = String(required=True) first_name = String(required=True) patronym = String() work_phone = String() personal_phone = String() email = String() gender = GenderChoicesPropertyEnum(required=True) healthy = Boolean(required=True) birth_date = DateTime() hire_date = DateTime(required=True) fire_date = DateTime() head = IntID()
class Media(ObjectType): class Meta: interfaces = (Node, ) id = ID(required=True) created = DateTime() modified = DateTime() series = String() order = Int() name = String() type = String() chapters = List(String) external_url = String()
class Beer(ObjectType): """ Beer GraphQL ObjectType """ id = ID() brewery = String() name = String() price = String() style = String() reviews = List(lambda: Review) created_at = DateTime() updated_at = DateTime() def resolve_reviews(self, info, **args): """ return the child Reviews as list of objects """ status, reviews = get_beer_reviews(self.id, {}, args) if reviews.get("data", None): return [_json_object_hook(val) for val in reviews.get("data")] return []
class SimilarSequence(graphene.ObjectType): type = SampleType(required=True) patient_sample = graphene.Field(PatientSample) positive_control = graphene.Field(PositiveControl) proficiency_sample = graphene.Field(ProficiencySample) entered_at = DateTime() pident = graphene.Float() length = graphene.Int() mismatch = graphene.Int()
class Input: title = graphene.String(required=True) body = graphene.String(required=True) received_benefit = graphene.String() provided_benefit = graphene.String() our_participants = graphene.String() other_participants = graphene.String() date = DateTime(required=True) is_draft = graphene.Boolean(default_value=False)
class OPCUAVariable(ObjectType): """ Represents an OPC UA node DataVariable with relevant attributes """ value = OPCUADataVariable(description=d.value) data_type = String(description=d.data_type) source_timestamp = DateTime(description=d.source_timestamp) status_code = String(description=d.status_code) read_time = Int(description=d.read_time)
class Contents(G.Interface): # https://github.com/graphql-python/graphene/pull/775 type_, resolve_type_ = ContentType(), GET("type") path, resolve_path = G.String(), GET("path") name, resolve_name = G.String(), GET("name") mimetype, resolve_mimetype = G.String(), GET("mimetype") writable, resolve_writable = G.Boolean(), GET("writable") created, resolve_created = DateTime(), GET("created") last_modified, resolve_last_modified = DateTime(), GET("last_modified") format, resolve_format = G.String(), GET("format") @classmethod def resolve_type(cls, instance, info): return { "file": FileContents, "notebook": NotebookContents, "directory": DirectoryContents, }[instance["type"]]
class Devotional(ObjectType): """Devotional graphql type definition.""" id = ID() title = String() passage = String() body = String() creation_date = DateTime() publish_date = Date() author = Field(lambda: User) comments = List(lambda: Comment) def __init__(self, model, *args, **kwargs): super().__init__(*args, **kwargs) self.model = model @classmethod def get_devotional(cls, id): """Class method to get a Devotional instance given an id""" model = DevotionalModel.query.filter_by(id=id).first() return cls.create_devotional_from_model(model) @classmethod def create_devotional_from_model(cls, model): """ Class method to create a Devotional instance given an SQLAlchemy model """ return cls( id=model.id, title=model.title, passage=model.passage, body=model.body, creation_date=model.creation_date, publish_date=model.publish_date, model=model ) def resolve_author(self, info): """Author resolver""" return User.create_user_from_model(self.model.author) def resolve_comments(self, info): """Comments resolver""" print(len(self.model.comments)) print(self.model.comments[0]) result = [Comment.create_comment_from_model(c) for c in self.model.comments] print(result) return result
class Query(graphene.ObjectType): user = graphene.Field(UserType, id=graphene.String()) me = graphene.Field(UserType) contest = graphene.Field(ContestType, id=graphene.String()) contest_by_short_id = graphene.Field(ContestType, short_id=graphene.String()) language = graphene.Field(LanguageType, id=graphene.String(required=True)) languages = graphene.List(LanguageType) clock = DateTime() @staticmethod def resolve_clock(_root, _info): return datetime.datetime.now() def resolve_user(self, _, **kwargs): try: return User.objects.get(pk=kwargs.get('id')) except User.DoesNotExist: raise ValueError("No Such User") @staticmethod @with_me def resolve_me(_, info): return info.context.user def resolve_contest(self, _, **kwargs): try: return Contest.objects.get(pk=kwargs.get('id')) except Contest.DoesNotExist: raise ValueError("No Such Contest") def resolve_contest_by_short_id(self, _, **kwargs): try: return Contest.objects.get(short_id=kwargs.get('short_id')) except Contest.DoesNotExist: raise ValueError("No Such Contest") def resolve_language(self, _, **kwargs): try: return Language.objects.get(pk=kwargs.get('id')) except Language.DoesNotExist: raise ValueError("No Such Language") def resolve_languages(self, info): return Language.objects.all()
def generate_type_dict(model): type_dict = {} for column in model.__table__.columns: if hasattr(model, 'private_fields') and column.name in model.private_fields: continue if column.type.python_type == int: type_dict[column.name] = Int() elif column.type.python_type == str: type_dict[column.name] = String() elif column.type.python_type == datetime.datetime: type_dict[column.name] = DateTime() elif column.type.python_type == datetime.date: type_dict[column.name] = Date() elif column.type.python_type == datetime.time: type_dict[column.name] = Time() elif column.type.python_type == bool: type_dict[column.name] = Boolean() elif column.type.python_type == decimal.Decimal: type_dict[column.name] = Float() else: raise Exception(f'Unknown column type {column.type.python_type}') return type_dict
def __init__(self): super(PatientVisitsField, self).__init__(PatientVisit, ids=graphene.List(graphene.ID), sample_ids=graphene.List(graphene.ID), ptnums=graphene.List(graphene.ID), name_prefix=graphene.String(), clinic_prefix=graphene.String(), physician_name_prefix=graphene.String(), mrid=graphene.String(), vnum=graphene.String(), collected_at_start=DateTime(), collected_at_end=DateTime(), received_at_start=DateTime(), received_at_end=DateTime(), entered_at_start=DateTime(), entered_at_end=DateTime(), order_by=graphene.List(PatientVisitsOrderByEnum))
def convert_date_to_string(field, registry=None): return DateTime(description=field.help_text)
def convert_column_to_datetime(type, column, registry=None): from graphene.types.datetime import DateTime return DateTime(description=get_column_doc(column), required=not (is_column_nullable(column)))
class Game(graphene.ObjectType): id = graphene.ID() start_time = DateTime()
class UserAction(Interface): timestamp = DateTime() user = String() device = String() name = String()
def convert_field_to_datetime(field, registry=None): """ Converts Mongoengine fields to Graphene DateTime type """ return DateTime(**get_data_from_field(field))
def convert_date_to_string(field, registry=None, input_flag=None, nested_fields=False): return DateTime(description=field.help_text or field.verbose_name, required=is_required(field) and input_flag == 'create')
def convert_form_field_to_datetime(field): return DateTime(description=field.help_text, required=field.required)