class SnapshotType(ObjectType): name = String(required=True) start_date = Date() end_date = Date() articles = List(NonNull(ArticleType)) def __init__(self, *args, **kwargs): pass @staticmethod def resolve_name(parent, info, **kwargs): snapshot = kwargs['snapshot'] return snapshot['name'] @staticmethod def resolve_start_date(parent, info, **kwargs): snapshot = kwargs['snapshot'] return snapshot['start_date'] @staticmethod def resolve_end_date(parent, info, **kwargs): snapshot = kwargs['snapshot'] return snapshot['end_date'] @staticmethod def resolve_articles(parent, info, **kwargs): snapshot = kwargs['snapshot'] return snapshot.article
class ProductType(ObjectType): id = ID() slug = String(required=True) name = String(required=True) name2 = String(required=False) full_name = String(required=False) one_c_id = String(required=False) sku = String(required=False) active = Boolean(required=False) unit = String(required=False) cat_number = String(required=False) oem_number = String(required=False) partNumber = String(required=False) brand = Field(BrandType, required=False) related = List(RelatedProductType) category = List(CategoryType) model = List(NewCarModelType, required=False) engine = List(EngineType) excerpt = String(required=False) description = String(required=False) created_date = Date(required=False) updated_date = Date(required=False) has_photo = Boolean(required=True) images = List(IProductImagesType, required=False) attributes = List(AttributesType) stocks = List(ProductStocksType, required=False) bages = List(String, required=False) rating = Float() ratingCount = Int() video = List(String) condition = String(required=False) breads = List(List(BreadCrumbsType))
class Query(ObjectType): stocks = Field(List( NonNull(StockType)), first=Int(), offset=Int(), symbol=String(required=True), start_date=Date(), end_date=Date() ) user = Field(String, email=String(required=True)) @staticmethod def resolve_user(parent, info, **kwargs): # Todo: Add email to JWT if session['email'] != kwargs['email']: raise Exception('Invalid user email.') return UserType(email=kwargs['email']) @staticmethod def resolve_stocks(parent, info, **kwargs): if kwargs.get('symbol', None): return [StockType(**kwargs)] # Todo: Use memcached for most recent searched stocks, here is just hardcoding return [StockType(symbol=symbol) for symbol in ['AAPL', 'FB', 'MSFT', 'GOOGL', 'AMZN']]
class Query(ObjectType): # this defines a Field `hello` in our Schema with a single Argument `name` hello = String(name=String(default_value="stranger")) test = String() goodbye = String() one_week_from = Date(required=True, date_input=Date(required=True)) one_hour_from = DateTime(required=True, datetime_input=DateTime(required=True)) one_minute_from = Time(required=True, time_input=Time(required=True)) # our Resolver method takes the GraphQL context (root, info) as well as # Argument (name) for the Field and returns data for the query Response def resolve_hello(root, info, name): return f'Hello {name}!' def resolve_test(root, info): return 'Testing...' def resolve_goodbye(root, info): return 'See ya!' def resolve_one_week_from(root, info, date_input): """ { oneWeekFrom(dateInput:"2020-10-10") } :param info: :param date_input: :return: """ assert type(date_input) == datetime.date return date_input + datetime.timedelta(weeks=1) def resolve_one_hour_from(root, info, datetime_input): """ { oneHourFrom(datetimeInput:"2006-01-02T15:04:05") } :param info: :param datetime_input: :return: """ assert type(datetime_input) == datetime.datetime return datetime_input + datetime.timedelta(hours=1) def resolve_one_minute_from(root, info, time_input): """ { oneHourFrom(timeInput: "15:04:05") } :param info: :param time_input: :return: """ assert type(time_input) == datetime.time tmp_time_input = datetime.datetime.combine(datetime.date(1, 1, 1), time_input) return (tmp_time_input + datetime.timedelta(minutes=1)).time() me = Field(Person) def resolve_me(parent, info): # returns an object that represents a Person return get_human(name="Luke Skywalker")
class Arguments: description = String(required=True) photo_url = String(required=True) procedure_code = String(required=False) date_for_receipt = Date(required=False) cut_off_date = Date(required=False) exam_type_id = Int(required=True) location_id = Int(required=True) provider_id = Int(required=True) health_plan_id = Int(required=True)
class SportsAttribute: """Sport Attribute for Coach and Referees""" description = String() active = Boolean() level = String() level_date = Date() level_years = Int()
class Arguments: gender = String(required=True) email_or_phone = String(required=True) username = String(required=True) date_of_birth = Date(required=True) password1 = String(required=True) password2 = String(required=True)
class Event(ObjectType): id = ID() title = String() description = String() resourceURI = String() urls = List(MarvelUrl) start = Date() end = Date() thumbnail = Field(Image) comics = Field(AllList) stories = Field(AllList) series = Field(AllList) characters = Field(AllList) creators = Field(AllList) next = Field(Summary) previous = Field(Summary)
class Teams(ObjectType): """ Teams Graphql Attributes""" id = ID() description = String() active = Boolean() join_date = Date() join_years = Int()
class EditGroupInput(InputObjectType): """Input for editing group""" group_id = ID(requiered=True) title = String() about = String() access_level = Argument(GroupQl._meta.fields['access_level'].type) date = Date()
def convert_date_to_string(field, registry=None, required=None, field_many_to_many_extras=None, field_foreign_key_extras=None): # We only render DateFields with auto_now[_add] if they are explicitly required or not if required is None and ( getattr(field, "auto_now", None) or getattr(field, "auto_now_add", None) ): return return Date(description=field.help_text, required=is_required(field, required))
class Sports(ObjectType): """ Sports Graphql Attributes for Referees and Coaches""" id = ID() description = String() active = Boolean() level = String() level_date = Date() level_years = Int()
class UserEditInput(InputObjectType): """Input for edit user""" phone_number = String() user_name = String() surname = String() about = String() birthday = Date() nickname = String() email = String()
def convert_date_to_string(field, registry=None, input_flag=None): if input_flag == "order_by": return OrderEnum(description=field.help_text or field.verbose_name, ) if input_flag == "where": return DateFilter(description=field.help_text or field.verbose_name, ) return Date( description=field.help_text or field.verbose_name, required=is_required(field) and input_flag == "create", )
class Arguments: phone_number = String(required=True) password = String(required=True) name = String() nickname = String(required=True) email = String() birth = Date() dni = String() role = String()
class TableType(DjangoObjectType): class Meta: model = TableModel exclude = ('orders', ) reserved = Field(Boolean, date=Date()) def resolve_reserved(self, info, date): return OrderModel.objects.filter(table_id=self.id, date=date).exists()
class CreateOrderMutation(DjangoModelFormMutation): name = String() email = String() date = Date() table = ID() order = Field(OrderType) class Meta: form_class = OrderForm
class UserType(ObjectType): id = String(required=True) phone_number = String(required=True) password = String(required=True) name = String() nickname = String(required=True) email = String() birth = Date() dni = String() role = String()
class AddGroupInput(InputObjectType): """Input for add group""" title = String(required=True) about = String() access_level = Argument(GroupQl._meta.fields['access_level'].type) date = Date(required=True) admin_role = Argument( GroupUserQl._meta.fields['role_in_group'].type, description= 'The group model will depend on the role of the administrator')
class Match(ObjectType): match_id = ID() createdAt = Date() duration = Int() gameMode = String() shardId = String() patchVersion = String() endGameReason = String() queue = String() rosters = List(Roster) telemetry_data = Field(TelemetryData) telemetry = List(TelemetryEvent)
class GoogleDate(ObjectType): date = Date() datetime = DateTime() timezone = String() def resolve_date(parent, info): return is_date_or_none(parent.get('date')) def resolve_datetime(parent, info): return iso_datetime_or_none(parent.get('dateTime')) def resolve_timezone(parent, info): return parent.get('timeZone')
class Story(ObjectType): id = ID() title = String() description = String() resourceURI = String() type = String() modified = Date() thumbnail = Field(Image) comics = Field(AllList) series = Field(AllList) events = Field(AllList) characters = Field(AllList) creators = Field(AllList) originalissue = Field(Summary)
class PostType(ObjectType): id = ID() slug = String() image = String() title = String() excerpt = String() text = String() partsCategory = List(CategoryType) category = List(CategoryType) date = Date() author = String() car = List(NewCarModelType) totalCount = Int() count = Int() tags = List(String)
class Episode(ObjectType): duration = Int() file_type = String() id = ID() is_deleted: Boolean() is_video: Boolean() played_up_to = Int() playing_status = Int() published_at = Date() size = String() starred = Boolean() title = String() url = String() uuid = ID() podcast = Field(Podcast)
class Character(ObjectType): id = ID() name = String() description = String() resourceURI = String() thumbnail = String() comics = Field(AllList) events = Field(AllList) series = Field(AllList) stories = Field(AllList) urls = List(MarvelUrl) has_profile_pic = Boolean() id = ID() picture_url = String() smart_name = String() thumbnail_url = String() modified = Date()
class UserType(ObjectType): """ Graphql type for User model """ id = Int(required=False) first_name = GString(required=False) last_name = GString(required=False) username = GString(required=False) gender = GString(required=False) date_of_birth = Date(required=False) email = GString(required=False) phone_number = GString(required=False) picture = GString(required=False) active = GBoolean(required=False) created_at = GDateTime(required=False) updated_at = GDateTime(required=False) number_of_followers = Int(required=False)
class EIP(ObjectType): eip_id = ID() eip_type = Field(type=Enum.from_enum(EIPType)) title = String() author = String() status = EIPStatusField created = Date() updated = String() discussions_to = String() review_period_end = String() category = EIPCategoryField requires = List(Int) replaces = List(Int) superseded_by = List(Int) resolution = String() full_text = String() tags = List(String)
class ArticleType(ObjectType): url = String(required=True, url=String()) thumbnail = String(required=True) title = String(required=True) snippet = String(required=True) date_published = Date(required=True) def __init__(self, *args, **kwargs): pass @staticmethod def resolve_url(parent, info, **kwargs): article = kwargs['article'] return article.url @staticmethod def resolve_thumbnail(parent, info, **kwargs): article = kwargs['article'] return article.thumbnail @staticmethod def resolve_title(parent, info, **kwargs): article = kwargs['article'] return article.title @staticmethod def resolve_snippet(parent, info, **kwargs): article = kwargs['article'] return article.snippet @staticmethod def resolve_date_published(parent, info, **kwargs): article = kwargs['article'] return article.date_published
class CreateUser(Mutation): class Arguments: phone_number = String(required=True) password = String(required=True) name = String() nickname = String(required=True) email = String() birth = Date() dni = String() role = String() id = String() phone_number = String() password = String() name = String() nickname = String() email = String() birth = Date() dni = String() role = String() def mutate(root, info, phone_number, password, nickname, name=None, email=None, birth=None, dni=None, role=None): return CreateUser(phone_number=phone_number, password=password, name=name, nickname=nickname, email=email, birth=birth, dni=dni, role=role)
class CourseType(ObjectType): id = Int(required=True) title = String(required=True) mentor = String() active = Boolean() create_date = Date()