[Proposal] Pass additional argument to adapters #1325
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Right now there doesn't exist a way to pass additional metadata for a query down to the adapter. This could be helpful when building custom adapters that need handle things like passing connections around or adding information for multi-tenancy.
This PR adds that ability in a temporary format. For now you can tack on an additional argument to your queries after the callback or use the
.meta()
key in the deferred object builder to pass any arbitrary data down to an adapter function.Yes this breaks the common node contract of the callback as the last argument and it's weird. I know this isn't a great longterm solution. If you don't use the extra argument everything will work as expected though. The big plus is it gives us this functionality now without breaking every single one of the community adapters.
In the major version bump to
1.0.0
we will retool the function signatures to take an(options, cb)
signature so that we can add non-breaking changes in the future.Some examples of usage:
To access the meta value in the adapter you would build a function like so:
For some more background on this see #1307