-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
main.py
49 lines (31 loc) · 1.29 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from fastapi import Depends, FastAPI, Request
from graphene import Field, Mutation, ObjectType, Schema, String
from starlette.datastructures import URL
from starlette.graphql import GraphQLApp
from auth import auth_bearer
# locale imports:
from resolvers import login, user
class Query(ObjectType):
me = Field(user.UserProfileQuery, lan=String(default_value="en"))
def resolve_me(self, info, lan):
return user.UserProfileQuery(language=lan)
class Mutation(ObjectType):
login = login.UserLogin.Field()
app = FastAPI(
title="JeffQL",
description="FastAPI authentication & Login API using GraphQL and JWT.",
version="1.0.0",
)
app.add_route("/", GraphQLApp(schema=Schema(query=Query, mutation=Mutation)))
graphql_app = GraphQLApp(schema=Schema(query=Query))
@app.get("/")
async def graphiql(request: Request):
request._url = URL("/data")
return await graphql_app.handle_graphiql(request=request)
@app.post("/data")
async def graphql(request: Request, authorize: str = Depends(auth_bearer.JWTBearer())):
request.state.authorize = authorize
return await graphql_app.handle_graphql(request=request)
@app.post("/user", dependencies=[Depends(auth_bearer.JWTBearer())])
async def graphql(request: Request):
return await graphql_app.handle_graphql(request=request)