I'm using FastAPI and now want to add GraphQL using graphene.
I'm using:
fastapi-userstarlette.graphql.GraphQLAppHere's the routing for GraphQL and how I used fastapi-user package.
import fastapi_users
from starlette.graphql import GraphQLApp
from mypackage.schema import my_schema
...
app.include_router(fastapi_users.router, prefix="/users", tags=["users"])
app.include_router(google_oauth_router, prefix="/google-oauth", tags=["users"])
app.add_route("/", GraphQLApp(schema=my_schema))
...
In the schema, I need to get user information and control the role based auth.
How to, or how can I use get_current_active_user() method with GraphQL schema?
I'm assuming that my_schema inherits graphene.ObjectType and that the first argument is info as shown in the example at:
https://fastapi.tiangolo.com/advanced/graphql/
from graphene import ObjectType, String
class Query(ObjectType):
hello = String(name=String(default_value="stranger"))
def resolve_hello(self, info, name):
return "Hello " + name
info contains the session object with your user information.
info.context['request'].session['user']
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With