This commit is contained in:
Ivan Vazhenin
2023-12-20 20:33:51 +03:00
parent a6b674939b
commit 13af01e356

13
main.py
View File

@@ -193,6 +193,12 @@ class Query:
stmt = select(User)
return UsersGQL(users=[json.dumps(user.to_dict()) for user in session.scalars(stmt)])
@strawberry.field()
def user(self, id: int) -> UsersGQL:
sync_engine = connect()
with Session(sync_engine) as session:
return UsersGQL(users=json.dumps(session.query(User).filter(User.id == id).one_or_none().to_dict()))
@strawberry.field()
def queue(self) -> UsersGQL:
sync_engine = connect()
@@ -204,14 +210,17 @@ class Query:
@strawberry.type
class Mutation:
@strawberry.mutation
def update_user(self, id_: int, bndname: str, newbnd: bool, active: bool, upstream: bool) -> bool:
def update_user(self, id_: int, bndname: str, newbnd: bool, active: bool, upstream: bool, passwd: str,
username: str) -> bool:
sync_engine = connect()
with Session(sync_engine) as session:
user = session.query(User).get(id_)
user.username = username
user.bndname = bndname
user.newbnd = newbnd
user.active = active
user.upstream = upstream
user.passwd = passwd
session.commit()
return True
@@ -342,7 +351,7 @@ graphql_app = GraphQLRouter(schema, graphiql=True)
app = FastAPI(root_path="/graphql")
app.add_middleware(CORSMiddleware,
allow_origins=['http://127.0.0.1:3000'],
allow_origins=['http://127.0.0.1:3000', 'http://localhost:3000'],
allow_credentials=True,
allow_methods=['*'],
allow_headers=['*']