question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

In resolver, Can I access request context?

See original GitHub issue
class TaskSchema(Schema):
    id: int
    title: str
    is_completed: bool
    owner: Optional[str]
    lower_title: str

    def resolve_lower_title(self, obj):
        return self.title.lower()

I want to pass some value to hide some field. like this.

    def resolve_lower_title(self, obj):
        if context.is_code_valid:
           return obj.title.lower()
        else:
           if obj.is_preview:
               return obj.title.lower()
           else:
                return ''

Is it possible with resolver or another way? I can do this in drf serializer because they support getting context from view…

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
vitalikcommented, Jul 3, 2022

@quroom

well for this type of integration I would do it like this:


class TaskSchema(Schema):
    id: int
    title: str
    is_completed: bool
    owner: Optional[str]
    lower_title: str

    @api.get("places/{place_id}/audioguides", response=List[AudioGuideOut])
    def list_audioguides(request, place_id: int):
        qs = Place.objects.get(id=place_id).audioguides.all()
        items = list(qs) # forcing sql execution
        for i in items:
              if context.is_code_valid:
                   i.lower_title = i.title.lower()
              else:
                  i.lower_title = ''
        return items

if you really want to collect data on schema level - then I would pass context to each item in the queryset:

        items = list(qs) # forcing sql execution
        for i in items:
              i.context = some_context
         return items
0reactions
quroomcommented, Jul 3, 2022

thanks a lot!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Resolver mapping template context reference - AWS AppSync
Accessing the $context. The $context variable is a map that holds all of the contextual information for your resolver invocation. It has the...
Read more >
Resolvers - Apollo GraphQL Docs
A resolver is a function that's responsible for populating the data for a single field in your schema. It can populate that data...
Read more >
How do I access context and args in resolver at the same time?
You can access request headers by using this method. first add context in graphqlModule import in app.module.ts imports: [ GraphQLModule.
Read more >
How To Access the request object inside a GraphQL resolver ...
Here, we are using es6 arrow functions and passing request object in that function.so that it will be available to pass in context...
Read more >
RequestContext (Spring Framework 6.0.3 API)
Set the UrlPathHelper to use for context path and request URI decoding. Can be used to pass a shared UrlPathHelper instance in. A...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found