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
Make addFilterArg asynchronous #31
Comments
I hacked in an await in And everything seems to work properly. |
I do not think about async in And what about such query definition (add async to arrow function): query: async (query, value, resolveParams) => {
var site = await Site.get();
query.category = await Category.findOne({site, node: value}).exec();
}, Does it work or not? |
Thanks for the reply, I was missing In the file resolver.js line 362, we can see I fixed it 'incorrectly' by changing addFilterArg in resolver.js if (isFunction(opts.query)) {
resolver.setResolve((resolveParams: ResolveParams) => {
const value = objectPath.get(resolveParams, ['args', 'filter', opts.name]);
if (value) {
if (!resolveParams.rawQuery) {
resolveParams.rawQuery = {}; // eslint-disable-line
}
opts.query(resolveParams.rawQuery, value, resolveParams).then(function(){
return resolveNext(resolveParams);
})
} else {
return resolveNext(resolveParams);
}
}); Or if es7 is supported, the following could probably work if (isFunction(opts.query)) {
resolver.setResolve(async(resolveParams: ResolveParams) => {
const value = objectPath.get(resolveParams, ['args', 'filter', opts.name]);
if (value) {
if (!resolveParams.rawQuery) {
resolveParams.rawQuery = {}; // eslint-disable-line
}
await opts.query(resolveParams.rawQuery, value, resolveParams);
}
return resolveNext(resolveParams);
}); Thanks! |
Has anyone create this issue PR yet ? |
I did not create a PR. |
It will be cool if you would ! 😎😀 I 'm stuck in this issue too Anyway this is how I solve it for now. // Instead of modify query in filterArg
// Wrap resolver with async function and modify your filter
// before going to resolve()
TC.setResolver('findOne', TC.getResolver('findOne')
.wrapResolve(next => async (rp) => {
const result = await rp.context.Plant.findOne({ $or: [{ key: rp.args.key }] });
if (result) {
rp.args.filter = Object.assign({ plantId: result._id.toString() }, rp.args.filter) // eslint-disable-line
}
return next(rp);
})) |
Same here! I'm workarounding it like indicated above. |
Done! Will be available on npm in minutes. someResolver.addFilterArg({
name: 'isActive',
type: 'Boolean!',
description: 'Active status filter',
query: async (query, value, resolveParams) => {
const checkPermissions = await Promise.resolve('accessGranted');
if (checkPermissions) {
query.isActive = value;
}
},
}); |
🎉 This issue has been resolved in version 4.8.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
@toverux thank you for reminding me of this old problem. I completely forgot about it. |
Oh @nodkz, did I already said that you're the best maintainer on earth? |
I am using relay and graphql-compose, and I want to make a query for Item which are child of categories.
My schema looks like:
And my filter looks like:
My problem is that I cannot make asynchronous database queries in addFilterArg.
From the client, I want to query and sort Items which are under a certain category where I know the node string, but not the _id.
The text was updated successfully, but these errors were encountered: