support passing metadata at request time
See original GitHub issueUse case:
I am implementing persisted queries for my own custom backend. To do this, in production I generate a build artifact that goes along with the query. Then I want to write a middleware to modify the request on the way out to simply replace the serialized query with the build artifact. On the server, the artifact gets transformed back into the query.
The problem: there is no (real) way for me to send this artifact through the request for my middleware to consume. The only way I could get this to work is to “smuggle” it through variables
as a magic field that gets extracted out by my NetworkInterface
.
This would be much nicer if I could just pass that build artifact through the request to have the middleware swap it out.
Could this be a plugin?
Maybe. Middleware comes very close to doing everything I need, I just don’t have a good API to send it the extra bit of data it needs.
Is there a workaround?
Yes, see above about smuggling it through variables
. However this is super hacky, I would prefer to do it correctly.
Note: the interface for Request indicates that one can pass in additional key/value pairs, but this data unfortunately does not survive to the NetworkInterface
/middleware layer.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:3
- Comments:10 (5 by maintainers)
Top GitHub Comments
@roippi @helfer are we talking about adding
metadata
field to GraphQLRequest interface? If so, I don’t see any breaking changes here, we are adding new stuff, not removing it, I might not see the whole picture though@roippi Could you please give an example of a situation when this becomes a problem?
@roippi I believe
metadata
is the ideal place for “custom” information to be stored. I would like to utilize it for marking certain queries as the ones that require the “global” loading spinner. So that I could use that info in a middleware to dispatch the action that will show the spinner.Do you see any harm in passing
metadata
all the way to the networkInterface?