alexsteinerde / graphql-kit

Easy setup of a GraphQL server with Vapor. It uses the GraphQL implementation of Graphiti.
MIT License
99 stars 18 forks source link

allow customization of POST stream strategy #9

Closed jaredh159 closed 3 years ago

jaredh159 commented 3 years ago

hey Alex! 👋 me again.

I have a mutation for a bulk insert of many records at once, and I found I was running into Vapor's default streaming body collection size. I was able to fix it by overriding the collect stream size limit globally, but I'd really rather only do that for POST requests to the /graphql route, for obvious reasons.

This PR adds an optional configuration setting for your register() function, allowing a custom strategy to be passed in for the POST handler.

I struggled with the naming of the param a bit -- as I mentioned, I didn't want to apply it to GET requests, so I called it postBody. But if you can think of a better name, or if there's some other way to selectively customize this value without changing the library (maybe a middleware?), let me know. Thanks!

jaredh159 commented 3 years ago

You know, I thought a bit more, and realized, I could just copy the inner code from your register function into my configure.swift file and make the change of collect stream size there. So, there is a workaround. If this seems to fringe of a customization, maybe just close this, and I'll go that route.

alexsteinerde commented 3 years ago

Thanks for the PR. I think you are right. Offering this option will enable more use cases. I tested the change with the .stream strategy and it seems to work so far.

What do you think about my proposal of the parameter naming?

jaredh159 commented 3 years ago

Yup, I like your parameter name better. I was trying to follow how normal routes are named in vanilla Vapor, but I think postBody was a little awkward. Updated the PR with new parameter name. 👍

jaredh159 commented 3 years ago

Thanks for merging! When you have a minute, can you cut a new release for this change?

alexsteinerde commented 3 years ago

Thanks for the reminder. Please see release 2.3.1 (created just now).