Skip to content

Add support for batching several requests into one #38

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 3, 2016

Conversation

michalochman
Copy link
Contributor

Batch format compatible with nodkz/react-relay-network-layer.

Tested only POST requests with Content-Type: application/json since I do not think it would be used differently.

@coveralls
Copy link

coveralls commented Oct 31, 2016

Coverage Status

Coverage increased (+0.2%) to 92.317% when pulling 6bd89f2 on TangoAgency:batch into d348ec8 on graphql-python:master.

@michalochman
Copy link
Contributor Author

Not sure why the UnboundLocalError suddenly occurred in my build on Travis. master tests probably never checked the else branch of if execution_result condition. Anyway, the issue is now fixed.

@syrusakbary
Copy link
Member

Looks great!!

Thanks for such a great PR!

@syrusakbary syrusakbary merged commit a7caad0 into graphql-python:master Nov 3, 2016
@jole78
Copy link

jole78 commented Jan 17, 2017

First of all, thanks a lot for adding this.
A question/request though.
As I understand, this is made for a specific client implementation of batched queries...??

I'm using apollo-client which also supports query batching but it expects the results to come back the same way as "normal" queries, in a data prop.
From what I can see the response format for a batched query looks like this:

                response = {
                     'id': id,
                     'payload': response,
                     'status': status_code,
                 }

where response['data'] is overwritten with this 'new' response instead.

I did make this work by sub classing the GraphQLView and basically removed those lines but it seems a bit cumbersome since I have to copy/paste this entire function:
def get_response(self, request, data, show_graphiql=False):

and make the changes in there.

Would it be an option to make the response format more pluggable in some way...perhaps like a function that we can overwrite instead that takes the execution result and returns the response, and that would default to response['data']. Then one could sub class the GraphQLView and just overwrite that function to return a different response format if so desired.

@michalochman
Copy link
Contributor Author

@jole78 try setting response transform function as batch property of GraphQLView and then transforming the actual response using that function in the code you linked.

I would also suggest making the current implementation default to not break existing code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants