-
Notifications
You must be signed in to change notification settings - Fork 25
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
Automate subscriptions with links #42
Comments
This is a bit of a critical issue for me, so any help will be greatly appreciated. Thanks! |
OK, I think it is explained here: https://github.com/cult-of-coders/apollo-live-server
|
OK, I solved it by enhancing the resolver for the subscription: Subscription: {
groups: {
resolve: (payload, args, {db}) => {
if (payload.event === Event.ADDED) {
// do a direct grapher query to get the linked data
let linkedDoc = db.groups.createQuery({
$filters: {
_id: payload.doc._id
},
_id: 1,
name: 1,
description: 1,
members: {
_id: 1,
name: 1,
company: 1
},
admins: {
_id: 1,
name: 1,
company: 1
}
}).fetch();
if (linkedDoc && linkedDoc.length) {
// there should be only one record since we filtered on the added doc
return ({
doc: linkedDoc[0],
event: payload.event
});
}
// something went wrong, send back original payload
return (payload);
}
return (payload);
},
subscribe(_, args, context) {
console.log("Calling groups subscription; user = " + context.userId);
// sanity checks
if (!context.userId) {
throw new Meteor.Error("authorization-error", "Action not authorized");
}
const observer = context.db.groups.find({
memberIds: context.userId
});
return asyncIterator(observer);
}
}
},
... It would be nice to figure out what the associated query was in the initial ReactiveQuery subscription, so that we know exactly what date to send back. But this works for now... |
@ujwal-setlur indeed, this is currently a limitation, and even if we do this, grapher could export a functionality that does this essentially, however it's very problematic with This would be a good feature request. |
I have 2 collections: users and groups. I have 2 main link sfrom groups to users based on memberIds and adminIds fields. Essentially who are the members and who are the admins.
Here is my GraphQL schema with schema directives:
Group:
Here is my User schema:
Here is how I do my subscription:
Here are my query and subscription resolvers:
On initial load, all is well and good. I get a good list with all the data. However, when I create a new group, say with GraphQL playground, then I run into a problem. I do get the group created event, but I do not get all the information about the group, particularly the ones attached to links.
Here is the mutation that added the query:
Here is the update record I got:
Notice that I get only _id, name, and description. I don't get members and admins fields. Both those fields have links on them pointing to User.
What am I doing wrong?
The text was updated successfully, but these errors were encountered: