Open techknowfile opened 4 years ago
Hey @techknowfile! I was having the same issue with a project of mine and I traced it to the middleware in my project.
It turns out that graphene-django middleware gets triggered for every field! I did not know this, and it's not super clear from the docs: https://docs.graphene-python.org/en/latest/execution/middleware/
This thread has a couple of solutions: https://github.com/graphql-python/graphene-django/issues/810
In my case, my middleware really should have been django middleware, so I migrated it over to that and my query times dropped exponentially (in one case, from 3.5 min to 2.5 seconds!)
response = schema.execute(query)
, it takes less than a second to receive a response with all the data in response.data; however, if I query the data through the local Django server (via GraphQL Playground or my frontend application), it takes 10+ seconds for the server to send the response.I initially assumed this was being caused by the serialization of the data from the database. I knew the queries were taking only 1/100th of a second based on the django_silk query/profiler results. However, the fast response from schema.execute rules out the serialization process being the issue.
Running cProfiler on Django doesn't appear to trace through the GraphQLView (any explanation of why this might be would be greatly appreciated). However, I was able to create a dynamic profiler with django_silk to confirm that it's something within
GraphQLView.get_response()
that's causing the slowdownWhat is the expected behavior? I'd expect the response to not take 1000x as long to send as the time taken to query and serialize the data.
Please tell us about your environment:
Other information (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. stackoverflow) StackOverflow question initially opened regarding this matter