예제 #1
0
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
예제 #2
0
class VoyageQuery(object):
    voyage = Field(
        'Voyage',
        voyage_id=ID(name='id', required=True),
    )
    voyages = ConnectionField('VoyageConnection')
    comments_for_voyage = ConnectionField(
        'CommentConnection',
        voyage_id=ID(name='id', required=True),
        chapter=String(),
    )

    def resolve_voyage(root, info, voyage_id):
        return Voyage.query.get(voyage_id)

    def resolve_voyages(root, info):
        return Voyage.query

    def resolve_comments_for_voyage(root, info, voyage_id, chapter=None):
        voyage = Voyage.query.get(voyage_id)
        if voyage is None:
            raise QueryException('Voyage not found')

        membership = (Membership.query.filter(
            Membership.voyage == voyage,
            Membership.user == current_user,
        )).first()
        if membership is None:
            raise QueryException('Voyage not found')

        current_chapter_index = voyage.chapters.index(
            membership.current_chapter)
        allowed_chapters = voyage.chapters[:current_chapter_index +
                                           1]  # Include the current chapter with + 1

        comments = (Comment.query.filter(
            Comment.voyage == voyage,
            Comment.chapter.in_(allowed_chapters),
        ))

        if chapter:
            if chapter not in voyage.chapters:
                QueryException(
                    'Invalid chapter ({}) for the voyage'.format(chapter))
            comments = comments.filter(Comment.chapter == chapter)

        return comments
예제 #3
0
class User(ObjectType):
    id = ID()
    created = DateTime()
    modified = DateTime()

    name = String()
    email = String()
    profile_picture = String()
예제 #4
0
class VoyageSubscription(object):
    voyage_created = Field('Voyage')
    voyage_updated = Field(
        'Voyage',
        voyage_id=ID(name='id', required=True),
    )

    def resolve_voyage_created(root, info):
        return events.voyage.subscribe_created()

    def resolve_voyage_updated(root, info, voyage_id):
        return events.voyage.subscribe_updated(voyage_id=voyage_id)
예제 #5
0
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()
예제 #6
0
class MediaQuery(object):
    media = Field(
        'Media',
        media_id=ID(name='id', required=True),
    )
    # I know the plural is media, sue me
    medias = ConnectionField('MediaConnection')

    def resolve_media(root, info, media_id):
        return Media.query.get(media_id)

    def resolve_medias(root, info):
        return Media.query
예제 #7
0
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()
예제 #8
0
class MyNode(ObjectType):
    # class Meta:
    #     interfaces = (Node, )
    id = ID()
    name = String()
예제 #9
0
 class Arguments:
     voyage_id = ID(name='id', required=True, description='ID of the voyage to invite to')
     email = String(required=True, description='Email of the user to invite')
예제 #10
0
 class Arguments:
     media_id = ID(required=True, description='ID of the media that this voyage is for')
     name = String(required=True, description='Name of the voyage')
예제 #11
0
 class Arguments:
     voyage_id = ID(name='id', required=True, description='ID of the voyage to comment in')
     chapter = String(required=True, description='The chapter to comment on')
     text = String(required=True, description='The comment')