markhuot / craftql

A drop-in GraphQL server for Craft CMS
Other
320 stars 53 forks source link

Support batched queries #113

Open jariz opened 6 years ago

jariz commented 6 years ago

CraftQL currently does not support query batching, a feature in apollo-client to prevent sending multiple requests at the same time.

Query batching works as follows: rather than a single operation object (like a 'normal request' at the moment), a request can contain an array with multiple operation objects.
The server in turn should return with a array of operation results.

markhuot commented 6 years ago

This is supported by the graphqlphp dep CraftQL depends on, as well. I'll look at adding this, but it'll be a few days, at least, before I'm able to focus on it.

markhuot commented 6 years ago

@jariz, I'm looking in to this more and as best I can tell apollo-client should support query batching without any modification to the server. Have you been able to test this out and are you seeing an error? If you can provide any more detail about what you've tried/what's not working I'd love to get batching on the stable list for CraftQL!

jariz commented 6 years ago

I asked with the Apollo guys and they mentioned it does not that way anymore.
https://twitter.com/dhaivatsays/status/1012412303659053056 Server transport is the default and only way to do batching as of 2018 it seems.

I currently do not have an computer but I remember it would give a GQL syntax error on 1:1 once you tried sending an array as body, regardless of contents.

markhuot commented 6 years ago

Thanks @jariz, that's helpful. Let me do some more testing. This should be possible to support, I just need to figure out what keys need to be parsed.

markhuot commented 6 years ago

FYI, this is implemented on the dev-batch-queries branch and will merge to master some time in the next week or so!

kristian-wcd commented 6 years ago

@markhuot What's the status on this? We would really need that feature.

markhuot commented 6 years ago

This is supported on the dev-batch-queries branch. If you're able to test it there it would help move things along and get this in to a stable release.

kristian-wcd commented 6 years ago

Ok, I will get on it.

kristian-wcd commented 6 years ago

@markhuot So I gave the batching a try and it works pretty well for my use-case so far. Thank you for that! However, as I already mentioned in this issue: Creating a new category while upserting does not link to the newly created category. This is also true for the batched requests (obviously). Here are the things I tried with the batched request. Hopefully we can move this feature to master soon.

Queries:

Mutations:

jonnyasmar commented 6 years ago

@markhuot Curious: what's preventing this from getting merged into master? I just installed the batch-queries-defer branch and everything -- on the surface -- seems to be working as expected.

I'm performing no mutations, but I have some complex queries including nested entryConnections.

markhuot commented 6 years ago

This is a part of a caching/speed improvement I'm working on. I probably won't merge this branch directly but copy bits and pieces of it in to a new branch that is going to move the enter schema generation in to it's own "process" so that it can be cached independently from the resolvers. Basically, right now, on each request I'm generating the entire schema and it's proving to be too slow (more than half the request time).

Long story short, thanks for testing! Maybe I can get batching merged outside of the caching stuff I'm working on separately.

jonnyasmar commented 6 years ago

Oh, that sounds like a very welcome enhancement!!

If it delays you at all from getting that released, please continue to defer. I'm more than happy to wait for speed improvements :)

mikeebee commented 5 years ago

Hey @markhuot! :) Are you still planning to copy some of these bits over to master at some point?

I've been building using 1.3.1 and then tried to switch to the batch-queries-defer repo to see if I can solve some Deadlock found when trying to get lock; try restarting transaction errors when trying to create many entries via a mutation, but I got a few Cannot query field X on type X errors on my initial query. This could be something to do with my setup but I know that branch is a fair few commits behind so not quite sure.