Closed paymog closed 5 years ago
Oh, looks like
from flask import request
def resolve_latest_snapshot(self, info: ResolveInfo, org_id: Optional[int] = None) -> models.Snapshot:
print(request.headers)
# more stuff
works. I wonder if there's a better, more graphene-y solution...
Looks like context
is request
(if you haven't overrided it): https://github.com/graphql-python/flask-graphql/blob/master/flask_graphql/graphqlview.py#L41
So probably info.context
is request
, and headers are in info.context.headers
, but I haven't verified it.
Oh yup, you're right. I was overriding it but now I've added it back in. Thanks!
‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐ On Friday, April 26, 2019 2:10 AM, Petr Messner notifications@github.com wrote:
Looks like context is request (if you haven't overrided it): https://github.com/graphql-python/flask-graphql/blob/master/flask_graphql/graphqlview.py#L41
So probably info.context is request, but I haven't verified it.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.
When trying to access info.context
in mutation I get
"graphql.error.located_error.GraphQLLocatedError: Working outside of request context"
Pretty simple setup:
class SomeMutation(graphene.Mutation):
"""
"""
def mutate(self, info):
"""
"""
print(info.context)
... snip...
return
class Mutation(graphene.ObjectType):
"""
"""
some_mutation = SomeMutation.Field()
schema = graphene.Schema(query=Query, mutation=Mutation, subscription=Subscription)
app.add_url_rule('/graphql',
view_func=GraphQLView.as_view('graphql',
schema=schema,
batch=True,
graphiql=False,
executor=GeventExecutor(),
)
)
What's the right way to get request header when resolving a query/mutation? A related issue, #17, lead me to believe that
info.context.headers
will work but I'm finding that doesn't exist when I try to print it:with a resolver of:
I have flask-graphql version 2.0.0.
EDIT: other related packages I have: