flavors / django-graphiql-debug-toolbar

Django Debug Toolbar for GraphiQL IDE and Graphene
https://pypi.python.org/pypi/django-graphiql-debug-toolbar
MIT License
72 stars 22 forks source link

"mutate" method of Mutation executes twice. #9

Closed ar7n closed 3 years ago

ar7n commented 4 years ago

dependencies

Django==2.2.6
graphene-django==2.5.0
django-debug-toolbar==2.0
django-graphiql-debug-toolbar==0.1.4

code


class CreateFavourite(graphene.Mutation):
    class Arguments:
        id = graphene.ID(required=True)

    ok = graphene.Boolean()

    @staticmethod
    def mutate(_, info, id):
        print("test")
        return CreateFavourite(ok=True)

log

System check identified no issues (0 silenced).
October 11, 2019 - 15:59:58
Django version 2.2.6, using settings 'app.settings'
Starting development server at http://0.0.0.0:8000/
Quit the server with CONTROL-C.
test
test
[11/Oct/2019 15:59:59] "POST /api/graphql/ HTTP/1.0" 200 155
OmegaDroid commented 4 years ago

I've ran into the same issue although it appears to be all calls not just mutations.

As far as I can tell the request is being processed in these 2 locations: https://github.com/flavors/django-graphiql-debug-toolbar/blob/master/graphiql_debug_toolbar/middleware.py#L61 https://github.com/flavors/django-graphiql-debug-toolbar/blob/master/graphiql_debug_toolbar/middleware.py#L80

dvf commented 4 years ago

Yup, can confirm.

androane commented 4 years ago

Same here

jakubste commented 4 years ago

same here

dvf commented 4 years ago

@ar7n are you accepting PRs?

ar7n commented 4 years ago

@dvf i am not maintainer 🤷‍♂️

ulgens commented 4 years ago

Hey @dvf , if you have a solution, can you please share it with us? Thanks a lot.

dvf commented 4 years ago

Sorry @ar7n, my mistake.

@ulgens, I haven't had time to dig in. But on these lines it looks like we're initially processing the request in order to:

  1. Add the JS script to the response if the request was to a GraphQL view;
  2. Immediately return the response if it's not a POST request from a GraphQL view.

So the response is called twice, first to get the JS to display on the page, and second to return the metrics to display. Perhaps @mongkok could shed some light on how to fix this.

dvf commented 4 years ago

Just want to bump this @mongkok

ulgens commented 4 years ago

@dvf https://gist.github.com/ulgens/e166ad31ec71e6b1f0777a8d81ce48ae I created this for one of our projects. The code doesn't look good to me and i'm surprised it works but what i try achieve is, basically there are two cases to render panel context: Get request to html file (page load) and json post request (graphl queries). There were two request processor in the original code and i tried to isolate these two cases and put related queries under them. It works for both page load and json post requests, doesn't duplicate queries or mutations and returns correct data.

adrengifo commented 4 years ago

is there a fix to this?

edthrn commented 4 years ago

@adrengifo the patch proposed by @ulgens in his Gist works good.

It is definitely not a production-grade workflow, but since the debug toolbar is only meant to be used during development, that's enough for me as long as the underlying issue is not fixed. Thanks @ulgens!

bellini666 commented 4 years ago

I just opened a PR that should solve this: https://github.com/flavors/django-graphiql-debug-toolbar/pull/12

I thought about copying the whole toolbar's __call__ code and return a tuple of (response, toolbar) to avoid needing to instantiate and process the response again. To avoid that (which would overwrite any change in the toolbar's code itself), I mocked the toolbar's instantiation in kinda malignus way but functional =P

What do you guys think?

p02diada commented 4 years ago

any news about this issue?

YasielCabrera commented 3 years ago

is this project not longer maintained? I'm facing the same issue here and I see there is already a PR since a couple month ago but is not merged yet

kasaiee commented 3 years ago

I have the issue too. To quick fix I suggested to role back to the main debug toolbar.

itzomen commented 3 years ago

Damn, had this issue for straight 1 month of Development. I just moved back to the default debug toolbar

itzomen commented 3 years ago

I just opened a PR that should solve this: #12

I thought about copying the whole toolbar's __call__ code and return a tuple of (response, toolbar) to avoid needing to instantiate and process the response again. To avoid that (which would overwrite any change in the toolbar's code itself), I mocked the toolbar's instantiation in kinda malignus way but functional =P

What do you guys think?

Great job Man, I don't know why your PR haven't been reviewed. @mongkok Please can you take a look?