graphql-python / graphene-django

Build powerful, efficient, and flexible GraphQL APIs with seamless Django integration.
http://docs.graphene-python.org/projects/django/en/latest/
MIT License
4.29k stars 767 forks source link

Status code with Query #1466

Closed elyas-hedayat closed 12 months ago

elyas-hedayat commented 12 months ago

Is your feature request related to a problem? Please describe. Hi; I use from DjangoFilterConnectionField for writting my Query , In some case i need to return status_code with my Query how it is possible to do this .

Describe the solution you'd like

this is my code i want to return status code with that i don't know what really can i do

me = DjangoFilterConnectionField(MeType)

@staticmethod
def resolve_site_me(root, info,  *args, **kwargs):
    return Me.objects.all() 
sjdemartini commented 12 months ago

@elyas-hedayat What do you mean by status code? Where is the status_code produced? These sorts of "how can I do X" questions are usually better suited for Stack Overflow than GitHub issues, which are oriented toward bug reports and feature-requests.

elyas-hedayat commented 12 months ago

Also, #956 is related to my issue topic In resolver of Query I want to return status code like DjangoRest manually I search a lot, but I could not find response that suited to my question

sjdemartini commented 12 months ago

Hm, I'm still not sure I understand what status code you're referring to. Do you mean the HTTP status code? That should always be 200 unless there's a server error (in which case there will not be a GraphQl structure returned), and it's part of the HTTP Response status line, not part of a GraphQL object structure within the response body. You could presumably add a field in you GraphQL response ObjectType like def resolve_status_code(): return 200 if you want to "simulate" having the field in your response. I'd recommend reading more about GraphQL patterns, since this seems fairly unusual. And in the future, please post questions of this sort on Stack Overflow instead of opening questions as issues in this project. Thank you.

See also https://stackoverflow.com/a/42942539/4543977