lesstrict
This commit is contained in:
parent
72c9bf9bb7
commit
d20cd1e521
|
@ -25,7 +25,7 @@ class ShoutAuthor(Base):
|
||||||
id = None
|
id = None
|
||||||
shout = Column(ForeignKey('shout.slug'), primary_key = True)
|
shout = Column(ForeignKey('shout.slug'), primary_key = True)
|
||||||
user = Column(ForeignKey('user.slug'), primary_key = True)
|
user = Column(ForeignKey('user.slug'), primary_key = True)
|
||||||
caption: str = Column(String, nullable=False, default = "")
|
caption: str = Column(String, nullable = True, default = "")
|
||||||
|
|
||||||
class ShoutAllowed(Base):
|
class ShoutAllowed(Base):
|
||||||
__tablename__ = "shout_allowed"
|
__tablename__ = "shout_allowed"
|
||||||
|
|
|
@ -10,7 +10,7 @@ from resolvers.community import community_follow, community_unfollow
|
||||||
from resolvers.reactions import reactions_follow, reactions_unfollow
|
from resolvers.reactions import reactions_follow, reactions_unfollow
|
||||||
from auth.authenticate import login_required
|
from auth.authenticate import login_required
|
||||||
from sqlalchemy import select, desc, and_
|
from sqlalchemy import select, desc, and_
|
||||||
from sqlalchemy.orm import selectinload
|
from sqlalchemy.orm import selectinload, joinedload
|
||||||
|
|
||||||
|
|
||||||
@query.field("topViewed")
|
@query.field("topViewed")
|
||||||
|
@ -50,14 +50,16 @@ async def view_shout(_, info, slug):
|
||||||
|
|
||||||
@query.field("getShoutBySlug")
|
@query.field("getShoutBySlug")
|
||||||
async def get_shout_by_slug(_, info, slug):
|
async def get_shout_by_slug(_, info, slug):
|
||||||
all_fields = [node.name.value for node in info.field_nodes[0].selection_set.selections]
|
shout = None
|
||||||
selected_fields = set(["authors", "topics", "reactions", "captions"]).intersection(all_fields)
|
|
||||||
select_options = [selectinload(getattr(Shout, field)) for field in selected_fields]
|
|
||||||
# select_options.append(selectinload(ShoutTopic.caption).label("captions"))
|
|
||||||
# TODO: append captions anyhow
|
# TODO: append captions anyhow
|
||||||
with local_session() as session:
|
with local_session() as session:
|
||||||
shout = session.query(Shout).\
|
shout = session.query(Shout).\
|
||||||
options(select_options).\
|
options([
|
||||||
|
selectinload(Shout.topics),
|
||||||
|
selectinload(Shout.reactions),
|
||||||
|
selectinload(Shout.authors)
|
||||||
|
]).\
|
||||||
|
join([ShoutAuthor.user, ShoutAuthor.caption], ShoutAuthor.shout == slug ).\
|
||||||
filter(Shout.slug == slug).first()
|
filter(Shout.slug == slug).first()
|
||||||
|
|
||||||
if not shout:
|
if not shout:
|
||||||
|
|
|
@ -322,7 +322,7 @@ type Reaction {
|
||||||
|
|
||||||
type Author {
|
type Author {
|
||||||
slug: String!
|
slug: String!
|
||||||
name: String!
|
name: String
|
||||||
userpic: String
|
userpic: String
|
||||||
caption: String # only for full shout
|
caption: String # only for full shout
|
||||||
}
|
}
|
||||||
|
@ -333,7 +333,7 @@ type Shout {
|
||||||
slug: String!
|
slug: String!
|
||||||
body: String!
|
body: String!
|
||||||
createdAt: DateTime!
|
createdAt: DateTime!
|
||||||
authors: [Author!]!
|
authors: [Author]
|
||||||
# ratings: [Rating]
|
# ratings: [Rating]
|
||||||
community: String
|
community: String
|
||||||
cover: String
|
cover: String
|
||||||
|
|
Loading…
Reference in New Issue
Block a user